Skip to content

Instantly share code, notes, and snippets.

@AnchyDev
Last active July 13, 2024 02:05
Show Gist options
  • Save AnchyDev/10cba8f2851cae49b29dc9b5d4eda121 to your computer and use it in GitHub Desktop.
Save AnchyDev/10cba8f2851cae49b29dc9b5d4eda121 to your computer and use it in GitHub Desktop.

Setup Eluna with VSCode

This short guide runs you through how to setup Eluna definitions with VSCode to improve your Eluna Lua development experience.

This guide was written for Windows but it can be adapted pretty easily for Linux.

Contents

Install VSCode

To write your scripts you are going to need a code editor, the most popular option and the one being used to setup the Eluna definitions in this guide is VSCode.

You can download VSCode from here: https://code.visualstudio.com/

Install Lua Language Server

To support Lua development in VSCode you need to install a Lua Language Server. The purpose of the language server is to:

  • Provide syntax checking
  • Diagnose issues and provide warnings
  • Code formatting
  • Intellisense / auto-complete There are more features but these are the most notable.

To install the language server, search for lua in the extensions tab of VSCode and install the extension by sumneko.

Install Lua

Generate Eluna Definitions

Install Python

To setup the Lua definitions you need to generate the documentation files for Eluna so you can parse the definitions from them. You can download and install Python from here: https://www.python.org/downloads/ (The version used in this guide was 3.11.3).

Setup pip

The Eluna docs generator and language server parser both require packages to be installed to run. This means we need a package manager like pip to install the packages to the machine.

You can check if pip is installed by running python -m pip --version and it should display the pip version. If it does not then you can run python -m ensurepip --default-pip to setup pip.

Like mentioned earlier we need some packages to run the parser files, run this command to install the packages:

pip install jinja2 typedecorator markdown

Generate Eluna Docs

You need to download and generate the Eluna docs from the ElunaLuaEngine/Eluna repository.

You can do this by downloading the repository manually or using git to clone it.

Option 1: Clone

git clone https://github.com/ElunaLuaEngine/Eluna.git

Option 2: Manually Download

  1. Navigate to https://github.com/ElunaLuaEngine/Eluna
  2. Click the green <> Code button at the top right of the file list.
  3. Click Download ZIP
  4. Extract the file to your preferred location.

Generate

Navigate to the Eluna folder you created which contains the Eluna source, and open the docs folder.

Open a terminal at this location and generate the docs by:

  • Holding Shift and Right-Clicking any empty space in the folder.
  • Clicking Open in Terminal / Open PowerShell window here
  • Execute the command python -m ElunaDoc

This will generate a build folder which we will give to the Lua Language Server parser.

Generate Lua Language Files

Now that you have generated the docs, you need to download the Language Server Parser so you can parse them.

You can do this by downloading the repository manually or using git to clone it.

Option 1: Clone

git clone https://github.com/Foereaper/LuaLS-Eluna-Parser.git

Option 2: Manually Download

  1. Navigate to https://github.com/Foereaper/LuaLS-Eluna-Parser
  2. Click the green <> Code button at the top right of the file list.
  3. Click Download ZIP
  4. Extract the file to your preferred location.

Configure

There is a PowerShell script that makes it easy to generate the language server files, however it needs to be configured with the correct paths so it can generate them.

  • Right click the runParser.ps1 file.
  • Click Open with.. and select a text editor.
  • Configure $parserScriptPath so it points to the parser.py provided by LuaLS-Eluna-Parser
  • Configure $htmlParentDirectory so it points to the path to the docs you generated earlier.
  • Configure $outputDirectory so it points to where you would like the language server files to be generated.

Configure VSCode

Now that you have generated the language server files, you need the Lua extension to know where they are located so you can benefit from the Eluna definitions.

  1. Open VSCode.
  2. Click the View button at the top of the screen and open the Command Palette (or press Ctrl+Shift+P)
  3. Search for Settings and select Open Settings (UI)
  4. Search for lua.workspace.library in the Search settings textbox.
  5. Click Add Item button and add the path that contains the language files and press OK.

The VSCode Lua Language Server now should know about the Eluna language files, you can test this by opening one of your Eluna scripts and hovering over one of your hook register calls and see if it gives you detailed information.

Example 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment