# Visual Studio Code and EmmyLua

## Visual Studio Code

[Visual Studio Code](https://code.visualstudio.com/) is a lightweight programming IDE
created by Microsoft. It includes a variety of plugins, most useful of which is
[Sumneko's Lua plugin](https://marketplace.visualstudio.com/items?itemName=sumneko.lua).
The plugin makes use of [EmmyLua](https://emmylua.github.io/)'s type annotations,
allowing for VS Code to autocomplete and make code suggestions.

## EmmyLua generator

The EmmyLua API can be generated by first running the `scrap_doc.py` script found
[here](D:\Git\solarus\work\ZBStudioPlugin\scrap_doc.py), then running the
`generate_solarus.lua` script in Lua. If done correctly, this will create a new
folder called `api`. After this, you will need to tell Sumneko's Lua plugin where to
look. You can do this by clicking the magnifying glass at the top of the IDE,
typing `> User Settings` and clicking `Preferences: Open User Settings (JSON)`.

If there is no property called `"Lua.workspace.library"`, create it at the bottom of
the file like so:
```lua
    "Lua.workspace.library": [
        "<path_to_solarus>\\work\\EmmyLua\\api"
    ],
```
Be sure to add a comma before creating this property if there are others before it.

If there is a property called `"Lua.workspace.library"` then add
`"<path_to_solarus>\\work\\EmmyLua\\api"` in the square brackets. If there is other
elements already there, be sure to add a comma before taking a new line.

Be sure to replace `<path_to_solarus>` with the path to the Solarus local repository.

## Use VS Code as text editor from Solarus Quest Editor

You can tell Solarus Quest Editor to use VS Code to edit Lua scripts,
instead of the default internal code editor.

In Solarus Quest Editor, go to Tools > Options > Text Editor and enable
External Editor.
In the command field, put `<path_to_vscode> "%p/data/" "%f"`.
On Linux or Mac OS X,
`<path_to_vscode>` can be as simple as `vscode`.
Windows users can either add
Code.exe to their `PATH` or paste the full path of the executable.
