Language Server Implementation for Luau

Luau Language Server

An implementation of a language server for the Luau programming language.

Getting Started

Install the extension from the marketplace: https://marketplace.visualstudio.com/items?itemName=JohnnyMorganz.luau-lsp

The extension will automatically populate the latest API types and documentation.

To resolve your instance tree and provide module resolution, the language server uses Rojo sourcemaps. The language server will automatically create a sourcemap.json in your workspace root on startup and whenever files are added/created/renamed.

It does this by running the rojo sourcemap command, hence Rojo 7.1.0+ must be available to execute in your workspace root. It is recommend to .gitignore the sourcemap.json file. In future, the language server will generate the file internally.

By default we generate a sourcemap for a default.project.json project file. The name can be changed in extension settings, as well as whether non-script instances are included in the sourcemap (included by default). Autogeneration of sourcemaps can also be toggled completely on/off in settings - the server will instead just listen to manual changes to sourcemap.json files.

Design Goals

The initial goal is to develop a language server supporting all common LSP functions. Module resolution and typing will initially revolve around Rojo.

The idea is to ensure module resolution is customisable, allowing the server to later be easily extended to support other environments where Luau may be used. We could also potentially take it a step forward, allowing the server to be used on an Lua 5.1 codebase through a translation layer (such as type comments through EmmyLua), allowing the language server to support general purpose Lua development powered by the Luau type inference engine.

If you use Luau in a different environment and are interested in using the language server, please get in touch!

Supported Features

  • Rojo Files Resolution
  • API Type Definitions
  • Diagnostics (incl. type errors)
  • Autocompletion
  • Hover
  • Signature Help
  • Go To Definition
  • Go To Type Definition
  • Find References
  • Document Highlight
  • Document Link
  • Document Symbol
  • Color Provider
  • Rename
  • Folding Range
  • Selection Range
  • Call Hierarchy
  • Type Hierarchy
  • Semantic Tokens
  • Inlay Hints
  • Workspace Symbols

The following are extra features defined in the LSP specification, but most likely do not apply to Luau or are not necessary. They can be investigated at a later time:

  • Go To Declaration (do not apply)
  • Go To Implementation (do not apply)
  • Code Actions (not necessary - could potentially add "fixers" for lints)
  • Code Lens (not necessary)
  • Inline Value (applies for debuggers only)
  • Moniker
  • Formatting (see stylua)

Build From Source

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --target luau-lsp --config Release
Owner
A CS Student interested in tooling, game development, and cyber security
null
Comments
  • Integration with SublimeLSP stopped working

    Integration with SublimeLSP stopped working

    This used to work just fine, but after updating to a more recent version of luau-lsp (apologies, I haven't noted the last version that worked) I'm getting this:

    Traceback (most recent call last):
      File "/home/zeux/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 149, in invoke
      File "/home/zeux/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/sessions.py", line 1964, in on_payload
      File "/home/zeux/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/sessions.py", line 1952, in deduce_payload
    TypeError: int() argument must be a string or a number, not 'NoneType'
    

    The Python code that errors is

            elif "id" in payload:
                response_id = int(payload["id"])
    

    I'm assuming that "id" is set to null in the JSON response... I'm going to try to bisect this but I wanted to file this first in case it's something obvious.

  • Support Studio plugin to infer instance hierarchy

    Support Studio plugin to infer instance hierarchy

    Luau-lsp does not recognize required modules defined in rbxms. However, the instance of the ModuleScript is still recognized by luau-lsp. I expect requires of ModuleScripts defined in .rbxms to work with luau-lsp, but I get type errors instead, shown below.

    I have two reasons for keeping certain modules inside the .rbxl. The first reason is that I do not want to see several hundred modules from Roblox in my VSCode project. The second reason is to easily allow non-coders in my team create projects to edit particular module scripts without Rojo overwriting their work.

    Here is an example project already setup with rbxm files: lsp_bug.zip The included .rbxl shows that the code is valid and works with Rojo.

    image

  • Enum can't be indexed as a table

    Enum can't be indexed as a table

    Problem I can't index Enum like this:

    Enum["UserInputType"]["Keyboard"]
    

    Error TypeError: Expected type table, got 't1 where t1 = {| AccessoryType: Enum.AccessoryType, ActionType: Enum.ActionType, ActuatorRelativeTo: Enum.ActuatorRelativeTo, ActuatorType: Enum.ActuatorType, AdPortalStatus: Enum.AdPortalStatus, AdPortalType: Enum.AdPortalType, AdShape: Enum.AdShape, AdornCullingMode: Enum.AdornCullingMode, AlignType: Enum.AlignType, AlphaMode: Enum.AlphaMode, AnalyticsEconomyAction: Enum.AnalyticsEconomyAction, AnalyticsLogLevel: Enum.AnalyticsLogLevel, AnalyticsProgressionStatus: Enum.AnalyticsProgressionStatus, AnimationPriority... TRUNCATED' instead

  • Types a and Player cannot be compared because they do not have the same metatable

    Types a and Player cannot be compared because they do not have the same metatable

    No warnings occur in Studio.

    --!strict
    local event = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent")
    assert(event:IsA("RemoteEvent"), "") -- LSP does now recognize `event` as a `RemoteEvent`.
    
    -- Won't warn if `player` is typed explicitly, but `Player` type is inferred anyway.
    event.OnServerEvent:Connect(function(player, target: Player)
    	print(player == target) -- Warning.
    end)
    
    local working_event: RemoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent")
    working_event.OnServerEvent:Connect(function(player, target: Player)
    	print(player == target) -- No warning.
    end)
    
    TypeError: Types a and Player cannot be compared with == because they do not have the same metatable
    
  • `Instance:FindFirstChild()` and `Instance:FindFirstAncestor()` can't always be compared with `nil`

    `Instance:FindFirstChild()` and `Instance:FindFirstAncestor()` can't always be compared with `nil`

    --!strict
    local model = Instance.new("Model")
    assert(model:FindFirstChild("does_not_exist") ~= nil) -- This warns.
    assert(workspace:FindFirstChild("does_not_exist") ~= nil) -- This is fine.
    
    TypeError: Types Instance and nil cannot be compared with ~= because they do not have the same metatable
    
  • Instance.GetChildren returns

    Instance.GetChildren returns "Objects"

    Instead of returning an array of Instances, luau-lsp says workspace:GetChildren() returns Objects. This happens for any other instance as well. image

    This is what Roblox Studio shows for workspace:GetChildren() image

  • Adding the extension to Open VSX Registry

    Adding the extension to Open VSX Registry

    Right now, the extension is only available on the Microsoft's VSCode extension marketplace, this makes the extension inaccessible to users using a different version of VSCode such as code-server or VSCodium. Right now the only workaround I could find was to download the extension package and then installing them manually.

    Perhaps add the extension to the Open VSX Registry?

  • Some types are `any` in definitions depending on ordering

    Some types are `any` in definitions depending on ordering

    WorldRoot.Raycast should return RaycastResult? as documented here: https://create.roblox.com/docs/reference/engine/classes/WorldRoot#Raycast But luau-lsp shows the return type as just RaycastResult image

    RaycastParams.FilterDescendantsInstances should be typed as {Instance} instead of {any}. image

    OverlapParams does not have property IgnoreWater as documented here: https://create.roblox.com/docs/reference/engine/classes/WorldRoot#Raycast But luau-lsp suggests and accepts OverlapParams.IgnoreWater image

    The types for CFrame.Position and CFrame.p are also wrong. They should be Vector3. image image

  • UTF-8 error within globalTypes.d.lua causes invalid typechecking

    UTF-8 error within globalTypes.d.lua causes invalid typechecking

    Freshly installed this extension with no conflicting extensions (eg. RobloxLSP), getting a strange error that causes substantial typechecking inaccuracy and general bugs

    Failed to read definitions file c:/Users/Snowdust/AppData/Roaming/Code/User/globalStorage/johnnymorganz.luau-lsp/globalTypes.d.lua. Extended types will not be provided

    image

    SyntaxError: Expected identifier when parsing expression, got invalid UTF-8 sequence

    image

  • Path for luau-lsp.types.definitionFiles doesn't work on Windows

    Path for luau-lsp.types.definitionFiles doesn't work on Windows

    I'm successfully using luau-lsp.types.definitionFiles on macOS to define my own types with an absolute path to a definition file. Unfortunately I can't get the same definitions to work on Windows though. On reload, luau-lsp simply says the definitions file does not exist.

    I'm pretty sure I've tried all combinations and permutations of forward slashes, backward slashes, double slashes, double quotes, etc. I've also tried both using the VSCode Settings UI and editing the json manually.

    I'm also sure the file exists at the path I'm providing! Not sure what else it could be.

  • Diagnostics do not cleared for ignored files

    Diagnostics do not cleared for ignored files

    I would like Luau-LSP to copy Roblox Studio's "Type Inference Modes" behavior documented here: https://luau-lang.org/typecheck#type-inference-modes

    This makes it easier to use other people's code that also uses these annotations without finding and changing ignore globs in vscode. I think this feature should be an optional setting in vscode to respect type inference modes annotation.

  • Doc comment support in type definitions

    Doc comment support in type definitions

    export type Roact = {
    	--[=[
    		Creates a roact element.
    
    		...
    	]=]
    	createElement: () -> (),
    }
    

    This could be a potential solution to older libraries not having moonwave-style doc comments. A user could then make a wrapper package that exports proper types and documentation comments pulled from the original package.

    This is also a potential solution to classes that are difficult to add types to using the idiomatic export class Class = typeof(Class.new()) and that need a full type definitions to work well.

    Possibly related to #236 considering the above remarks

  • Typechecker reports false positives when defining a user-defined type in the project

    Typechecker reports false positives when defining a user-defined type in the project

    Defining function return type will raise type-related errors.

    For example, adding a user-defined return type (such as Roact.Element) will raise an error of unknown type. Screenshot 2022-12-21 at 14 13 43

  • Ignored error returning error code 1.

    Ignored error returning error code 1.

    I may have found a bug on Luau LSP analyze... if you try to use --ignore on a file that throws an error, it will return the error code 1. here is a mini repo with the problem, if you try to run luau-lsp analyze --ignore=example.lua it won't print nothing because it ignored the error - but an error code was returned. image

    luauerror.zip

  • Doc comments do not attach to certain kinds of function declarations

    Doc comments do not attach to certain kinds of function declarations

    Functions declared like this do not get doc comments attached:

    --[=[
    	Doc comment
    ]=]
    local func = function()
    
    end
    

    EDIT: I realized now that this may count as a doc comment on a variable and not on a function declaration, let me know if this is just that feature missing and not actually a bug.

  • Autocomplete anonymous functions when passing as argument

    Autocomplete anonymous functions when passing as argument

    If we need to pass an argument as a function (e.g. a callback), it would be nice if it there is a snippet option to autocomplete the parameters and go directly into the function body

  • Don't enable all FFlags (related to recent crashing)

    Don't enable all FFlags (related to recent crashing)

    Currently the Language Server is heavily crashing due to a problem upstream in Luau (https://github.com/Roblox/luau/issues/780)

    The bug is gated behind the LuauUninhabitedSubAnything, but currently we enable all FFlags by default.

    To temporarily alleviate this bug, you can set the above FFlag to False, or disable the "Enable all FFlags" setting.

    We should in general make "Enable all FFlags" no longer on by default, as it is not necessary anymore with the FFlag syncing with Studio. There may be cases where this is disadvantageous though, so we will need to look into this further.

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting

ccls ccls, which originates from cquery, is a C/C++/Objective-C language server. code completion (with both signature help and snippets) definition/re

Jan 6, 2023
A concatenative functional language to be used as a sidekick for the mlatu language

gerku _, | | __ _, ___ ,_ __ | | __ _, _, /\___ / _` | / _ \| '__)| |

Jan 14, 2022
exp2swift translator which translates STEP schema files described in ISO 10303-11 STEP EXPRESS language to the Swift programing language.

STEPswiftcode/ exp2swift exp2swift translator which translates STEP schema files described in ISO 10303-11 STEP EXPRESS language to the Swift programi

Jan 3, 2022
StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that of JavaScript's and TypeScript's

StarkScript StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that

May 10, 2022
The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.

Wren is a small, fast, class-based concurrent scripting language Think Smalltalk in a Lua-sized package with a dash of Erlang and wrapped up in a fami

Dec 30, 2022
C implementation of the Monkey programming language.
C implementation of the Monkey programming language.

Development of this interpreter continues here: dannyvankooten/pepper-lang C implementation of the Monkey programming language. Bytecode compiler and

Dec 30, 2022
Simple String_View implementation for C programming language.

Simple String_View implementation for C programming language.

Dec 21, 2022
A C++ implementation of the Forth programming language

onward A C++ implementation of the Forth programming language Build # Clone repository git clone https://github.com/tetsuo-cpp/onward.git cd onward/

Mar 6, 2022
In DFS-BFS Implementation In One Program Using Switch Case I am Using an Simple And Efficient Code of DFS-BFS Implementation.
In DFS-BFS Implementation In One Program Using Switch Case I am Using an Simple And Efficient Code of DFS-BFS Implementation.

DFS-BFS Implementation-In-One-Program-Using-Switch-Case-in-C Keywords : Depth First Search(DFS), Breadth First Search(BFS) In Depth First Search(DFS),

Nov 17, 2021
Web Server based on the Raspberry Pico using an ESP8266 with AT firmware for WiFi
Web Server based on the Raspberry Pico using an ESP8266 with AT firmware for WiFi

PicoWebServer This program runs on a Raspberry Pico RP2040 to provide a web server when connected to an Espressif ESP8266. This allows the Pico to be

Jan 7, 2023
OpenTibiaBR - Canary Project is a free and open-source MMORPG server emulator written in C++.
OpenTibiaBR - Canary Project is a free and open-source MMORPG server emulator written in C++.

OpenTibiaBR - Canary Project is a free and open-source MMORPG server emulator written in C++. It is a fork of the OTServBR-Global project. To connect to the server and to take a stable experience, you can use our own client or tibia client and if you want to edit something, check our customized tools.

Dec 28, 2022
Crashser - open source dump/crash server for different programming languages

Crashser - open source dump/crash server for different programming languages (used for crash analysis in various applications). This library is crossplatfrom (now only Windows, Linux, OSX) implementation C++ client for Crasher dump/crash server.

Oct 15, 2022
The Cycle: Frontier server emulation

Prospect Also known as "The Cycle: Frontier". This repository is just something I work on when bored, do not expect much at this stage. Features Conne

Nov 29, 2022
Remastered MW3 Server Freezer for the 1.4:382 version of the game (client)

MW3ServerFreezer Remastered MW3 Server Freezer for the 1.4:382 version of the game (client). Disclaimer This software has been created purely for the

Oct 31, 2022
OneFlow Backend For Triton Inference Server

Triton Inference Server OneFlow Backend

Jan 6, 2022
Passive scriptable LED server for Raspberry Pi

Passive LED server Scriptable LED server that you can just keep running all the time on a Raspberry Pi. Requirements Raspberry Pi 4 or newer (older mi

Dec 1, 2021
Plex media server local privilige escalation poc - CVE-2021-42835

Local Privilege PlEXcalasion - CVE-2021-42835 Plex Media Server for Windows prior to version 1.25.0.5282, vulnerable to Time Of Check Time Of Use (TOC

May 24, 2022
The main repository for the Darkflame Universe Server Emulator project.
The main repository for the Darkflame Universe Server Emulator project.

Darkflame Universe Introduction Darkflame Universe (DLU) is a server emulator for LEGO® Universe. Development started in 2013 and has gone through mul

Jan 7, 2023