Neovim with native LSP

The Language Server Protocol (LSP) implementation in neovim 0.11.0 has been rewritten making it possible for mere mortals to rely on the native LSP capabilities within neovim. Here is an example:

$ cat ~/.config/nvim/init.lua
vim.lsp.enable({
  "ansible",
  "python"
})

The vim.lsp.enable API tells neovim to auto-start the listed LSP’s based on the LSP configuration in ~/.config/nvim/lsp.

$ cat ~/.config/nvim/lsp/ansible.lua
return {
  cmd = { "ansible-language-server", "--stdio" },
  filetypes = { "yaml.ansible" },
}

$ cat ~/.config/nvim/lsp/python.lua
return {
  cmd = { "pyright-langserver", "--stdio" },
  filetypes = { "python" },
}

In these examples, the LSP’s will be activated based on file types, but more complex options like root_markers are also available.

Finally, the LSP’s must manually be installed:

$ npm install --prefix ~/.local/npm @ansible/ansible-language-server
$ ln -s ~/.local/npm/node_modules/@ansible/ansible-language-server/bin/ansible-language-server ~/.local/bin

$ pip install pyright

Use :checkhealth vim.lsp to check diagnostics.

My complete dotfiles for neovim are located here.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *