How to Install Lua LSP on Neovim
Series on how to configure LSP for your programming language in Neovim
Today we are going to start a series on how to install Language Server Protocol (LSP) for different programming languages on Neovim.
This article assumes you already know:
- What is an LSP, if you don’t know see here .
- You already know how to configure your Neovim, if you don’t know, see here .
- You already have basic knowledge of Lua, if you don’t, see here .
In this first article of the series we will configure the LSP for Lua .
Lua uses the LSP that is in the repository https://github.com/sumneko/lua-language-server, the same one used in VS Code .
For this article we are going to use Ubuntu 22.04 , if it is in a different version or different operating system or even in another distribution, just use search
from your package manager.
Dependencies
First of all, make sure you have the following packages/software installed on your system:
- Ninja Build
- GCC, G++ and Clang
Example:
Installation of LSP
1st - Prepare a directory where the LSP will be stored
In this case I will store it in
${HOME}/.config/lsp
, change the path if you are more interested
Create the directory and enter it
2nd - Now clone and compile the lua-language-server
binary
With the following commands in order:
3rd - Add the binary to your $PATH
Neovim already has several LSPs built in, what is missing is for it to find the path to the binary in its $PATH
.
To do this, run the commands below:
If you used a path other than
~/.config/lsp
, change it accordingly.
Configuring Neovim
Add LSP support for Lua as per the configuration style you chose. In this case, as an example, let’s use init.lua
.
vim ~/.config/nvim/init.lua
And add the code below
If everything is ok, you will have: function details, error and warning information, autocomplete according to tables and so on. Examples:
Useful links
- https://github.com/sumneko/lua-language-server/wiki/
- https://github.com/sumneko/lua-language-server
- https://jdhao.github.io/2021/08/12/nvim_sumneko_lua_conf/
Comments