Neovim LSP 0.11
In Neovim LSP 0.11 they added more support for LSP. This enables you to have native support for your LSP’s without requiring any plugins.
vim.lsp.config['lua_ls'] = {
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_markers = {
'.luarc.json',
'.luarc.jsonc',
'.luacheckrc',
'.stylua.toml',
'stylua.toml',
'selene.toml',
'selene.yml',
'.git',
}
}
And then you start enable it to autostart when it runs the filetype and finds
the root_marker.
vim.lsp.enable("lua_ls")
Now lua language server will be available when it matches the configuration
nvim-lspconfig
If you were using lspconfig, it’s probably still recommended to use it as it will have the configuration for the LSP you are using. Instead of setting up the config ourselves we can rely on the config from lspconfig. This will continue working going forward so you can chose your path there.
https://github.com/neovim/nvim-lspconfig
https://github.com/neovim/nvim-lspconfig/issues/3494
File config loading
To keep your config cleaner you can use file loading for the LSP.
A new directory where you can store your LSP configs.
~/.config/nvim/lsp
~/.config/nvim/after/lsp
Try setting it in the after/ set your config and not overwritten by a default from a plugin.
And then in your config file you put your config.
Enable the LSP to autostart
The name of the file should match the name of the LSP we use in the
vim.lsp.enable.
Ex: vim.lsp.enable('lua_ls')
~/.config/nvim/after/lsp/lua_ls.lua
return {
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_markers = {
'.luarc.json',
'.luarc.jsonc',
'.luacheckrc',
'.stylua.toml',
'stylua.toml',
'selene.toml',
'selene.yml',
'.git',
}
}
Then all you need in your config is the enable to make sure it starts when it matches.
vim.lsp.enable('lua_ls')
Commands
If you need special LSP commands, add them like the following:
vim.lsp.commands['PyrightOrganizeImports'] = function(command, handler)
-- not exactly sure what is in command and handler at this point
end
See :h vim.lsp for more information about vim.lsp integration and features.
See https://github.com/rockerBOO/neovim-lsp-0.11 for an example config.
See Neovim LspAttach Autocommand for some default recommended keybinds for LSP.