Skip to content
David Briscoe edited this page May 13, 2019 · 6 revisions

Get luarocks.

brew install luarocks
# or
sudo apt-get install luarocks
# etc

Install lua components

On Windows, requires Visual Studio C++ tools and Windows SDK. Run from "Developer Command Prompt for VS" so cl.exe is in $PATH.

luarocks install --server=http://luarocks.org/dev lua-lsp
luarocks install luacheck # optional. for linting.
luarocks install Formatter # lua 5.1 only. optional. for code formatting.
luarocks install lcf # lua 5.3 only. optional. for code formatting.

vim-lsp setup

if executable('lua-lsp')
    au User lsp_setup call lsp#register_server({
                \ 'name': 'lua-lsp',
                \ 'cmd': {server_info->[&shell, &shellcmdflag, 'lua-lsp']},
                \ 'whitelist': ['lua'],
                \ })
endif

Project setup

For completion support, you need a .luacompleterc in the root of the project. It should contain something like this:

{
  "global": {
  },
  "luaVersion": "luajit-2.0",
  "packagePath": "src/?.lua;src/?/init.lua;src/lib/?.lua;src/lib/?/init.lua",
  "cwd": "~/code/game/projectname"
}
# vim:set ft=json:

Ensure luaVersion is correct (may be "5.2", "5.1", etc). This is the most important value in this file. See also luacompleterc documentation.