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

  • Inlay Hints
  • 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 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, returns the type of the arguments you give them, for example:

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

returns BasePart.

When giving a function as an argument to the method Connect of a RBXScriptSignal, the parameters of the callback will have their corresponding types!

And you also have a snippet that autocompletes the function and the parameters.

When doing math operations with certain types, you will get 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 gives you string as key and any as value.
Array gives you integer as key and any as value.
Objects gives you integer as key and Instance as value.

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

Full Luau Syntax

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

However, there is not type checking, but i’m planning to implement it in a future update.

Using Selene (Optional)

Selene is a linter created by @Kampfkarren. In order to use it, disable Roblox LSP diagnostics.

Rojo Support

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

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

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 Roblox LSP > 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 Roblox LSP > 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 can also add an special annotation on top of variables to get intellisense of a module that Roblox LSP didn’t found.

---@module path.to.test
local test = require(test)

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.

Autocompletion for datamodel descendants

Roblox LSP can receive information from Roblox Studio using a plugin, if you install it, a list of every descendant in your game will be send to Roblox LSP every time you create, remove, move or rename an Instance.

test

To use this feature, install the plugin here, and two buttons will appear in the Toolbar called Connect to start sending data to this extension, and Settings to configure the plugin.

Roblox LSP will be ready to receive data when you initialize the extension (when you open a lua file), it creates a port in localhost (your machine), you can configure the port changing the setting robloxLsp.misc.serverPort. You can also configure the plugin to make it start automatically when you open the place, exclude instances and their descendants, or change the port, both ports must match. It is recommended to use a different port for every project.

You can check if the data is being sent to localhost in http://127.0.0.1:PORT/last.

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

Color Picker and Preview

When you call the constructors of Color3, a box will appear that you can use to preview the color and by clicking on it, change it easily.

test

(The gif recorder does not capture all colors of the gradient).

Using it with other Code Editors

If you prefer Sublime Text, Atom, Vim, 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.

Get Help

You can join the Roblox OSS Discord Server to get help if you have a problem.

Notes

  • Make sure you don’t have both Lua by sumneko and Roblox LSP installed.

  • Roblox LSP consumes a lot of RAM, but nothing worrisome (unless you have like 2 GB of ram).

  • 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.

  • When the Language Server starts, it will load all the scripts in your workspace one by one (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 updates automatically.

  • This topic may have many grammatical errors.

Thanks! Feedback is appreciated!

547 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!

11 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.

3 Likes

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

4 Likes

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.

1 Like

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

1 Like

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!

2 Likes

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.

1 Like

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

2 Likes

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

3 Likes

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

1 Like

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.

4 Likes

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

2 Likes

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

2 Likes

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

1 Like

As far as I’m aware, this is the tool that almost every developer uses: GitHub - rojo-rbx/rbxlx-to-rojo: Tool to one time convert Roblox places to Rojo projects

1 Like

This looks amazing! Gonna try it out later.

1 Like

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

Mine just ran straight out of the downloads folder, never had to worry about a dll file. are you using the exe version? (if you’re on Windows of course)

EDIT: Just realized you mentioned a .exe file, my bad :sweat_smile:

1 Like