Playdate Development with Neovim
I have been using Vim/Neovim as my editor for two years now, but I haven’t made an effort to dive into the topic that is LSP—Language Server Protocol. Since I also want to get into game development for the Playdate, I figured I’d marry those two topics and see how far I can get making Neovim my Playdate IDE (integrated development environment).
Others have tried that before and have shared their approach in the Neovim central thread on the Playdate forum.
Add LSP Features to Neovim
Neovim supports LSP by acting as an LSP client. I decided not to go with a one-stop shop solution like LSP Zero to learn a bit more about the underlying mechanics. There is abundant material on (Neo)Vim and LSP online, but everyone does it a tiny bit different which makes it tricky to piece everything together. My advice: Take the time to learn Lua and learn from other people’s configuration files.
Some resources that helped me shape my understanding:
- Setup nvim-lspconfig + nvim-cmp
- Ultimate Neovim Config | 2024
- Neovim Config - Part 3 — LSP
- Config by ThePrimeagen
- Config by Treeman
After doing my research and understanding the vocabulary of the LSP landscape, I decided to go with these well-established plugins:
- nvim-lspconfig for LSP server configurations
- mason to install LSP servers
- For now, I have only installed the lua-language-server (or
lua-ls
inlspconfig
speak); I will need to improve my configuration once I want to add more language servers
- For now, I have only installed the lua-language-server (or
- nvim-cmp for autocompletion
- LuaSnip for snippets
My Neovim configuration is on Sourcehut. The other listed dependencies are necessary for plugins to play nice with each other and to extend the autocompletion capabilities.
Playdate-specific Configurations
After working through the Playdate documentation for Lua and installing the SDK (software development kit), I wanted to add Playdate-specific settings to my LSP configuration. All possible settings can be found in the wiki of the Lua language server.
I changed my settings to achieve three things:
- Add the SDK files as a library so that types are picked up by autocompletion
- Declare
import
of the Playdate runtime as an alternative torequire
- Make the additional assignment operators known
It was not enough to add $PLAYDATE_SDK_PATH/CoreLibs
as a library; I would get some autocompletion but not everything. For example, the global playdate
did not get picked up along with all fields as it seems. playdate-luacats is doing a much better job! In the end, I decided to add both: $PLAYDATE_SDK_PATH
(without the /CoreLibs
) to complete CoreLibs
import
s, and playdate-luacats
for everything else.