Roblox LSP - Full Intellisense for Roblox and Luau!

Roblox LSP

Visual Studio Code Extension

Roblox LSP is Lua Language Server for Roblox forked from sumneko’s Lua language server.

Everything you will see in this topic and more was made by me, but this would not be possible without the language server created by sumneko.

Introduction

This project was made with Roblox developers in mind.

Roblox LSP provides a lot of features, like advanced IntelliSense, Signature Help, Goto Definition, Symbols, Diagnostics, etc, and many focused on programming in Roblox and Luau.

When you are a Roblox programmer, you may not be satisfied with Roblox Studio and the Script Editor it has for various reasons, so you decide to use an external editor (like Visual Studio Code) to improve your workflow.

This comes with many advantages like:

  • Have your project in your filesystem.
  • Use Git for version control (Especially useful when working with teams)
  • Use your favorite code editor.

And this comes with more advantages like Snippets, Multiple Editors, Multiple Cursors, Code Preview, and a huge amount of Plugins that give you even more!

Now you can add to that list: A Better IntelliSense!

I am going to show you its features and explain you how to use it, so this topic can become a little long.

sumneko’s Lua Features

  • Goto Definition
  • Find All References
  • Hover
  • Diagnostics
  • Rename
  • Auto Completion
  • IntelliSense
  • Signature Help
  • Document Symbols
  • Workspace Symbols
  • Syntax Check
  • Highlight
  • Code Action
  • EmmyLua Annotation
  • Multi Workspace
  • Semantic Tokens

Features

Roblox Environment

You will feel that you are programming in Roblox Studio (but better), it has an environment exactly same as Roblox, you have the same globals, same functions, same everything!

And you can also expect certain behaviors, such as that global variables can only be used in the script in which you define them, and that _G and shared are shared across all scripts.

Classes and Datatypes

As you can expect, you will have full intellisense and auto-completion for each Class and Datatype, but not only that.

You will get documentation and details of the API of almost every member of every class.

And also className autocompletion for functions like GetService, IsA, etc, and Enums autocompletion!

Functions like GetService, Instance.new, FindFirstChildOfClass, etc, will return a type with the arguments you give them, for example:

local basePart = game.Workspace:FindFirstChildWhichIsA("BasePart")

will return BasePart.

But get ready because there is still more!

When giving a function as an argument to Connect of a RBXScriptSignal, the parameters of the function will get types!

You will also have a snippet that autocompletes the function and the parameters.

When doing math operations with certain types, you will receive the expected type!

You also have some table types, like Dictionary, Array, Map and Objects, which will give types to the parameters of a for loop.

Dictionary will give you string as key and any as value.
Array will give you integer as key and any as value.
Objects will give you integer as key and Instance as value.

But that’s not all, because some functions will give you more specific types, for example, Players.GetPlayers will give you Objects<Player>

NOTE: Vector2int16, Vector3int16 and Region3int16 are not included because they interfere in autocompletion and are not enough used.

Full Luau Syntax

It supports full Luau Syntax! and has IntelliSense for Compound Assignments, Continue Statement and types for parameters, variables and returns.

However, there is not type checking, and I have no plans to implement it.

Selene (for VSCode)

Selene is a linter created by @Kampfkarren, which gives you some cool lints that Roblox LSP doesn’t, and it has Luau syntax support.

In order to use it, Roblox LSP has an option to disable Syntax Error warnings, all Roblox LSP features works correctly with syntax errors in the code, these are simply ignored.

You just have to install Selene for VSCode, and you will also have to disable some duplicated lints.

Recommended Configuration

Add this to your selene.toml:

std = "roblox"

[rules]
undefined_variable = "allow"
unused_variable = "allow"
shadowing = "allow"
empty_if = "allow"
incorrect_standard_library_use = "warn"

Alternatively, you can disable the same diagnostics in Roblox LSP if you prefer Selene.

Make sure you have the latest version of Selene.

Rojo Support

This is extremely important and useful, with Rojo support you can do a lot of things!

If you have a project file in your workspace, it will read it and create an Instance Tree, with it, you will get IntelliSense for modules, it will know the location of the scripts in the Instance Tree, and you will get Autocompletion for children in DataModel that you created in your filesystem.

Children of StarterPack, StarterGui, StarterPlayerScripts and StarterCharacter will also be children of Backpack, PlayerGui, PlayerScripts and Character respectively.

It has support for .txt, .lua and .model.json files, and recognizes init files too.

If you have multiple projects in your workspace, you can set Lua > Workspace: Load Mode to Rojo Project, and Roblox LSP will only load the scripts that can be found in your Rojo Project, unless you open them manually.

You also have to specify the name of the .project.json file you are working with in Workspace: Rojo Project File, by default it is “default”.

But if you want to work on several projects at the same time that are in the same workspace, and you have several .project.json files, then you can set Lua > Workspace: Rojo Project File to blank, this will make Roblox LSP read all the .project.json files it finds, convert them into Instance Trees, and then combine the Instance Trees into one.

You may also have noticed that the require function has an optional parameter called path, it’s optional, and you can use it to get IntelliSense for files that Roblox LSP can’t found.

Another thing to notice is that the functions FindFirstChild and WaitForChild, will return you the child of the Instance if it finds it, otherwise, they will return you a value of type Instance.

Import Instance Tree

If the Instance Tree generated with your Rojo Project is not enough, you can generate one with a Roblox Studio Plugin: https://www.roblox.com/library/5534792758/Instance-Tree-Generator

Just click in the button called Generate and it will create a script in Lighting called datamodel.json.

Then, save it in your workspace root with the extension .datamodel.json, and name it the same as your .project.json file, for example: default.datamodel.json.

It will not look for Instances that doesn’t have a valid lua name: no spaces, no symbols except for _, and no numbers at the beginning of the name.

Unfortunately this process has to be done manually and does not update itself, this is a feature that I plan to add.

Diagnostics

sumneko’s Lua includes a lot of diagnostics, and Roblox LSP includes a few more focused in Roblox, they only work with Roblox Instances, Datatypes, and Lua libraries.

Undefined Member

You will get a warning if you try to access an undefined member of an Instance or DataType.

This comes with a problem, when indexing the children of an Instance, you will get a warning, this is fixed in many ways:

  • You can add the Name of the child in Lua › Diagnostics: Ignore, and it has a quick fix for that.
  • When writing the same name twice or more across all the scripts, it will automatically ignored.
  • When Lua › Diagnostics: Datamodel As Ignore is enable, all the names found in the Instance Tree will be ignored.

When indexing a value of type Instance specifically, it will give you a warning if the member is undefined in all Instance classes.

Deprecated Member

When indexing a deprecated member of an Instance or DataType, you will get an info warning.

There is a quick fix to fix it, or you can add the name in the ignore list.

Incorrect Arguments

When calling a function with incorrect arguments types, you will get a warning.

And when calling GetService, IsA, Instance.new, etc, you will get a warning if className is invalid.

You can disable the diagnostics you don’t want.

Extra Libraries

You can extend Roblox LSP with .lni (LNI) files, when you place them in a folder called “.vscode” in your workspace root, Roblox LSP will load them.

Or you can place them in:
C:\Users\YOUR_USER\.vscode\extensions\nightrains.robloxlsp-#.#.#\server\libs\@rbx

Here are some that I made:

Roact

It adds the following types:

  • Roact
  • RoactComponent
  • RoactBinding
  • RoactContext
  • RoactElement
  • RoactFragment
  • RoactTree

To use it, set the type Roact to your Roact module.

You can also do:

---@type Roact
local roact = require(game.ReplicatedStorage.Roact)

Download it: roact.zip (948 Bytes)

AeroGameFramework

It adds the following types:

  • AeroService
  • AeroController

It has something very special, AeroService and AeroController comes with members called Modules, Shared, Services and Controlllers, when you set the type of a variable to AeroService or AeroController, it will appear in Services or Controllers.

For Modules and Shared, your project has to be structured this way:

root:
    - scr
        - Server
            - Modules
        - Client
            - Modules
        - Shared

Download it: aero.zip (921 Bytes)

Knit

Adds the following types:

  • Knit

Like AeroGameFramework, it provides intellisense for Services and Controllers, but it doesn’t need you to have your project structured in a specific way.

Download it: knit.zip (375 Bytes)

Using it with other Code Editors

If you prefer Sublime Text, Atom, Vim, Notepad, etc, luckily, as Roblox LSP is a Language Server, it can be used in almost any code editor.

To do it, all you need is the server that you can found in the GitHub repository, and a Language Client for your Code Editor, the process is completely different for each code editor, so I can’t explain it here.

Keep in mind that depending on the code editor and the language client you use, some features of Roblox LSP will not work correctly or will not be available, the most recommended is to use Visual Studio Code, which already comes with an extension to install it easily.

Notes

  • If you have used sumneko’s lua before, you may have noticed that it had some weird bugs, many of them have been fixed in Roblox LSP.

  • Roblox LSP consumes a lot of RAM, but nothing worrisome.

  • The Language Server can only run on 64-bits computers.

  • If you have a Low-End computer, you will start to notice it slow from 700 lines of code, the performance depends only on the file you are editing, and there are other factors such as the complexity of the code. You can enable Lua › Completion: Fast Autocompletion, although it is experimental and may not work correctly sometimes.

  • When the Language Server starts, it will load all the scripts one by one in your workspace (depending on how Workspace: Load Mode is configured), this process may be slow, but the first script that will load will be the one you are editing and from there you can start coding.

  • The Roblox API does not update automatically yet, it will be updated every time I update Roblox LSP, but to do it yourself, copy the necessary files from CloneTrooper1019/Roblox-Client-Tracker, and paste them in:
    C:\Users\YOUR_USER\.vscode\extensions\nightrains.robloxlsp-#.#.#\server\rbx, they are:
    API-Dump.json, ReflectionMetadata.xml and AutocompleteMetadata.xml.

  • This topic may have many grammatical errors.

Thanks! Feedback is appreciated!

190 Likes

Haha yes!!! I remember you showing this off in #help-and-feedback:cool-creations i believe it was and ever since that video of the demo I’ve been wanting to use this ever since!

This is one crazy extension!

3 Likes

This looks amazing, I can’t wait to try it out! I’m really happy there is a new non-studio script editor that doesn’t rely on Rojo/VS. I am an Atom user myself, and really like it’s simplistic style and navigation. I’ll dedicate a few hours to learn all about LSP.

1 Like

Currently having issues running this extension within VSCode. This looks like an absolute time-saver and would greatly improve my workflow - that is, if it worked.

Here are the errors I am receiving.

image

1 Like

Can you show me the output? and make sure you don’t have sumneko’s Lua installed.

I would’ve shared the output originally if it had anything in it to begin with (genuinely quite shocking as there’s obviously an error: VSCode is just not outputting it). As for having sumneko’s Lua extension installed, never have had it installed - I checked. I have also removed any lua-related extensions that may have interfered with the processing that your extension was doing and that also yielded no results.

I don’t think I can share anything else other than that picture :grimacing:. Are there any other requirements that I might need to do?

and yes, I have reloaded VSCode numerous times.

Your computer is 32 Bits? Unfortunately, the Language Server is compiled in 64 Bits, I forgot to mention it.

I found the issue. I realised the file was not located in a “workspace” and I figured this would be the root cause of the issue - and guess what I found - it was! Should’ve mentioned that as well; although, I didn’t think it would matter since other language servers can handle that. Possibly a bug or intentional? Obviously not priority but it’d be nice for it to work for isolated files not opened within a workspace.

Also I’m running on 64bits thankfully :slight_smile:

Great extension and can’t wait to use this for future projects for sure!

1 Like

Oh yeah, it does what you says, there is no support for isolated files, it would be good, but i would have to modify many things, I think I will at some point.

This is really cool!

Been playing around with it for the last 5 minutes and already found a bunch of things you’d never be able to do inside studio! I have to say, my favorite so far is it understanding a player’s functions and parameters from inside a for loop: https://gyazo.com/5d674762afd041375cc66dff1f7870b0

1 Like

Gave it a go on an existing project and while it’s nice, it has a few issues.

It seems to occasionally just outright fail to recognize some class members (it was doing this for Plugin:CreateDockWidgetPluginGui, Plugin:CreateToolbar, Plugin:CreatePluginAction, Selection:Get, and Selection:Set) and doesn’t recognize DockWidgetPluginGuiInfo at all.

It also has issues with Rojo projects. I have UI that is saved to the file tree as an .rbxmx file. It doesn’t make sense for me to index it with FindFirstChild. And yet, that’s what it’s requiring of me. It also doesn’t seem to recognize the existence of .model.json files despite them being very simple – you can see one here that it fails to recognize.

Hover over could also use some work. Right now we’re in a weird situation where this happens:
image

But for some reason re-defining plugin changes it entirely:
image

2 Likes

I am definitely bookmarking this. Thank you for making this!

Literally I just forgot to add DockWidgetPluginGuiInfo class.

It doesn’t have support for .rbxmx files (yet), but it should recognize .model.json files.

and the Hover is different because when you do:

local var: number = 2

you are doing the same as:

---@type number
local var = 2

this is a EmmyLua annotation, when you use EmmyLua, you will notice that types set with annotations works differently as types you got in any other way.

I’m going to fix all for the next update.

2 Likes

This will help my workflow so much. You are a legend. Thank you so much my man.

Just thought about this while using this amazing new extension you’ve made. I don’t know if I’m blind and you put this in your post or not, but I think it would be really cool if you created a way to tell the script the all the StarterGui children also exist in PlayerGui. Like in Roblox-TS, there is ways using validate trees and other methods to do that kind of stuff.

I think it would be neat, seeing as I am a front end developer and I work with UI controller scripts in AGF a lot, so it would be helpful to have the autocompletes for that as well. Currently, the intelliSense doesn’t know that the gui’s exist in the playergui so there are no autocompletes.

1 Like

This is amazing! Works like a charm for me, can’t wait to start using this on large projects.

I cant figure out how to use it, sorry im dumb, i never used rojo, i downloaded the vscode extension

how would you take the scripts to vscode

As far as I’m aware, this is the tool that almost every developer uses: https://github.com/rojo-rbx/rbxlx-to-rojo

This looks amazing! Gonna try it out later.

it says vcruntime140.dll could not be found, where do i put the .exe