luau-lsp

repository·main·Indexed 19 days ago

https://github.com/johnnymorganz/luau-lsp

A Language Server implementation for the Luau programming language providing diagnostics, autocompletion, and intellisense. It features deep integration with Roblox development workflows, including Rojo sourcemaps and a Roblox Studio Companion Plugin for real-time DataModel resolution. Supports various editors via LSP, including VS Code, Neovim (luau-lsp.nvim), JetBrains IDEs (intellij-luau), and Zed (zed-luau).

Tokens
15.3K
Snippets
55
Records
87
Agent score
67%

What's inside luau-lsp

  1. Configure Luau language settings via .luaurc

    main

    The language server supports two types of configuration:

    1. General Luau Configuration: Use .luaurc files to configure language strictness, lints, and require aliases. This follows the standard Luau RFC specification.
    2. Language Server Configuration: Specific settings provided via your editor's settings (e.g., VSCode settings).
  2. How plugins and transformations work

    main
    1. The plugin receives the original source code.
    2. The plugin returns a list of TextEdit objects.
    3. The language server applies these edits to produce transformed source code.
    4. Luau type-checks the transformed source.
    5. LSP features (diagnostics, hover, etc.) automatically map positions back to your original source.

    Multiple Plugins: All configured plugins receive the original source (they are not chained). Edits from all plugins are combined. If edits overlap, an error is logged and no transformation is applied.

  3. How the Studio Plugin and Language Server work together

    main

    The Studio Plugin acts as a bridge between the Roblox DataModel and your external editor.

    1. Change Detection: The InstanceTracker module detects changes within the Roblox DataModel.
    2. Serialization: Changes are serialized into tree updates.
    3. Communication: The plugin sends these updates to the Luau Language Server via HTTP requests handled by ServerEndpoints.
    4. Result: This allows external editors to provide intelligent autocompletion and accurate type analysis for Roblox-specific instances and types.
  4. Generate Roblox API types using dumpRobloxTypes.py

    main

    The globalTypes.d.luau file is an autogenerated type definition file used for Roblox development. You can regenerate this file by running the dumpRobloxTypes.py script, which extracts information from the Roblox API Dump, BrickColor data, and DataTypes.json.

    $ python dumpRobloxTypes.py > globalTypes.d.luau
  5. Configure Definitions and Documentation

    main

    You can provide built-in definitions and documentation to the server to improve intellisense.

    Built-in Definitions

    Use the --definitions:@name=PATH argument to add definition files. The name must be a unique reference. You can provide multiple definitions.

    Documentation

    Use the --docs=PATH argument to provide documentation files for built-in definitions.

    Recommended URLs for Roblox Users:

    • https://luau-lsp.pages.dev/type-definitions/globalTypes.None.d.luau
    • https://luau-lsp.pages.dev/type-definitions/globalTypes.PluginSecurity.d.luau
    • https://luau-lsp.pages.dev/type-definitions/globalTypes.LocalUserSecurity.d.luau
    • https://luau-lsp.pages.dev/type-definitions/globalTypes.RobloxScriptSecurity.d.luau
    • https://luau-lsp.pages.dev/api-docs/en-us.json
    $ luau-lsp lsp --definitions:@roblox=/path/to/globalTypes.d.luau
  6. Install the Luau Language Server Studio Plugin

    main

    To enable real-time DataModel information in your external editor (like VS Code), you must install the companion plugin in Roblox Studio and enable it in your editor settings.

    1. Install the Roblox Studio Plugin: Download it from the Creator Store.
    2. Install the Editor Extension: Ensure the luau-lsp extension is installed in your editor (e.g., VS Code).
    3. Enable the Feature: In VS Code, set the following setting to true:
      • luau-lsp.studioPlugin.enabled
    {
      "luau-lsp.studioPlugin.enabled": true
    }
  7. Configure Rojo sourcemaps for Roblox development

    main

    If you use Rojo (v7.3.0+), the language server uses Rojo-style sourcemaps to resolve DataModel instance trees for intellisense. The server listens for changes to a sourcemap.json file at the workspace root.

    To generate the sourcemap, run: rojo sourcemap --watch default.project.json --output sourcemap.json

    It is recommended to add sourcemap.json to your .gitignore.

    rojo sourcemap --watch default.project.json --output sourcemap.json
  8. Install the Luau Language Server

    main

    You can install the Luau Language Server via the VSCode Marketplace or OpenVSX Registry. For other editors, you can set up your own client following the Language Server Clients guide.

    If you need the latest features, you can download a Nightly Release and manually install the .vsix file. Nightly builds include debug symbols and profiling instrumentation.

    VSCode Marketplace: https://marketplace.visualstudio.com/items?itemName=JohnnyMorganz.luau-lsp
    OpenVSX Registry: https://open-vsx.org/extension/JohnnyMorganz/luau-lsp