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.
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/
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
.
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).
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
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.
git clone https://github.com/ElunaLuaEngine/Eluna.git
- Navigate to
https://github.com/ElunaLuaEngine/Eluna
- Click the green
<> Code
button at the top right of the file list. - Click
Download ZIP
- Extract the file to your preferred location.
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
andRight-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.
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.
git clone https://github.com/Foereaper/LuaLS-Eluna-Parser.git
- Navigate to
https://github.com/Foereaper/LuaLS-Eluna-Parser
- Click the green
<> Code
button at the top right of the file list. - Click
Download ZIP
- Extract the file to your preferred location.
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 theparser.py
provided byLuaLS-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.
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.
- Open
VSCode
. - Click the
View
button at the top of the screen and open theCommand Palette
(or pressCtrl
+Shift
+P
) - Search for
Settings
and selectOpen Settings (UI)
- Search for
lua.workspace.library
in theSearch settings
textbox. - Click
Add Item
button and add the path that contains the language files and pressOK
.
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.