You will want to install two extensions; the love2d support extension and the lua extension so you have the language server which provides syntax highlighting and error checking. Do read their installation instructions.
This is not enough to complete the setup. To get rid of the undefined 'love' global error, you will want to, in an opened project, do the following:
- open the Visual Studio Code command palette (under the "View" menu)
- Search for "lua addon manager" and open it
- In the lua addon manager you will want to look for LOVE (should be at the top) and enable it.
This will resolve the undefined global error for this project. If you start a new project, you will need to repeat these steps.
Worth noting is that there are several versions of Lua that the language server supports; from Lua 5.1 to 5.4 and also LuaJIT. Love2d by default uses LuaJIT for performance reasons. LuaJIT is limited to the Lua 5.1 feature set, so something like the \\ operator which does an integer division is not supported. When starting a new project it is worth it to check that the Lua extension is configured for LuaJIT so the extension will warn you when you are using unsupported features, which should already be the case if you activated LOVE support as per the above instructions. You can do this by:
- Opening the extensions in the left menu
- Clicking on the gear next to the installed "lua" extension and then clicking "settings"
- In the search box at the top search for "lua runtime version" and make sure "LuaJIT" is selected in the select box.
Finally most documentation will tell you that you can run your Love2d project from Visual Studio Code using the ALT+L keyboard shortcut. This is likely to conflict with other extensions though. If it doesn't work, you should change the key binding to something like ALT+SHIFT+L. You can do this by taking the following steps:
- Open the visual studio code keyboard shortcuts (under File -> Preferences)
- In the search box at the top, search for "love2d"
- The keyboard shortcut you will want to change is the one named "Run Love2D on the workspace folder".
love .(assuming you are in folder withmain.lua), or drop folder containingmain.luaonto love.exe