by

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 we start enable it to autostart when it runs the filetype and finds the root_marker.

vim.lsp.enable("lua_ls")

And that’s all you need to do.

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

Alternatively to keep your config cleaner we can use file loading for the LSP.

There is a new directory where we can store our LSP configs.

~/.config/nvim/lsp
~/.config/nvim/after/lsp

I suggest setting it in the after/ if you want to be sure it is setting your config and not overwritten by a default from a plugin.

And then in our config file we put our 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

Additionally special commands can be added, but the documentation is a little more limited.

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 the various 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.