Jump to content

User:Ash/SRB2 Lua on VSCode

From SRB2 Wiki

Introduction

REPORT BUGS AND MISSING DEFINITIONS HERE: https://git.do.srb2.org/LJSonic/vscode-lua-srb2

This is a simple guide to get SRB2 Lua working on VSCode.

Thanks to LJ for making these tools available to us!

Getting it working

This guide requires VSCode to be already installed on your computer.

Follow the guide step by step for best results.

WARNING: THIS MAY REQUIRE OTHER LUA LANGUAGE EXTENSIONS TO BE DISABLED.

Download the files

First, download one of the following file depending on your OS, and decompress it:

Put the SRB2-2.2/ folder (you can rename it if you want) in a place you won't have to move very often (for best results!).

Install the VSIX file

In VSCode, open your command palette (on PC: F1 or CTRL+Shift+P. on Mac: Command+Shift+P).

Type "Install from VSIX":

A picture of VSCode with the command palette open, highlighting "Install from VSIX".

Follow the prompt to install the SRB2 Lua VSIX file that matches your OS ("vscode-srb2lua-X.X.X-win32-x64.vsix" on Windows).

Configure the library path

When it's installed, go to your extensions and locate the SRB2 Lua extension.

Then, click the gear icon to open its settings.

This picture shows the SRB2 Lua extension with some arrows pointing to the extensions icon on the left, and the gear icon on the right.

Once in settings, scroll down until you see "Lua > Workspace: Library".

From there, hit the "Add Item" button and point it to the srb2.d.lua file.

Any other Lua files you'd like the extension to reference are OPTIONAL.

Pictured is my setup, with the srb2.d.lua file and 2 files I wanted the extension to load for me (the name is wrong in this picture):

This picture shows the Library section of the SRB2 Lua extension's settings. The only file required for this to work is the srb2.d.lua file.

Configure the preload limits

Since SRB2's Lua API is very expansive, you may want to scroll to find "Lua > Workspace: Max Preload" and "Lua > Workspace: Preload File Size".

From there, increase their values so the library file doesn't get rejected by the extension.

My settings are provided as a reference, but you can use any number that works (but the default is too small, I think):

A picture of the SRB2 Lua VSCode extension's settings for max file sizes: Max Preload at 10000, and Preload File Size at 5000.

Optional configuration for SRB2

Configure the plugin path

You can make the extension automatically infer the types of the arguments in `addHook()` by pointing "Lua > Runtime > Plugin" to the plugin.lua file.

Enable SRB2-specific syntax

You can optionally add SRB2 Lua specific symbols like continue and slash comments // under "Lua > Runtime: Nonstandard Symbol". The pseudo-variable syntax ($, $1, $2, etc.) is already supported by default:

A picture of the SRB2 Lua VSCode extension's nonstandard symbols settings, with "continue" and slash comments added.

And that's it! You should be able to see it working in your Lua files:

A picture of the SRB2 Lua VSCode extension with the text "add" typed into the editor, with multiple SRB2-specific options that match the string "add" popping up with Intellisense.

Troubleshooting

If it does not work, try the following steps:

  • Some web browsers seem to download srb2.d.lua with the wrong extension under some circumstances. Ensure it is not called srb2.d.lua.txt or some other extension instead.
  • Disable any other VS Code Lua extensions you may have installed before, as they can sometimes interfere.