lsp layer#
The lsp layer configures the Nvim LSP client via
nvim-lspconfig. It is a dependency
for layers requiring LSPs, such as most language layers.
LSs are installed by mason.nvim by default.
Neovim itself can also act as an LS to inject new LSP-like features via none-ls.nvim, a community fork of the discontinued “null-ls.nvim”. All documentation and code still refer to null-ls, as none-ls does not rename its API for compatibility concerns.
Bindings#
In normal mode:
gDgoes to declaration;gdgoes to definition;Kshows hover;gigoes to implementation;<C-K>shows signature help;<leader>Dshows type definition;<leader>rnrenames the current symbol;<leader>caruns a code action;<gr>goes to references;<leader>eshow line diagnostics;[dgoes to previous diagnostic;]ddoes to next diagnostic;gfformats the current buffer.
Configuration#
install(defaulttrue): whether Mason should attempt to install language servers when none are explicitly specified;progress(default{}): if nil, LSP progress reports are disabled;mason(default{}): a validmason.nvimconfig;mason-tool-installer(default{}): a validmason-tool-installer.nvimconfig. Itsensure_installedfield will be extended with the language servers required by the enabled language layers;nullls(default{}): strings used as keys are considered null-ls source names, and their values the respective configs. When non-strings are used as keys (e.g. implicit number indices in arrays), their values are assumed to be null-ls source names w/o configs;binds(default as above): bindings as would be passed to thebindslayer;
Examples#
-- path/of/your/vim/config/init.lua
require("visimp")({
nullls = {
'code_actions.gitsigns',
['formatting.latexindent'] = {
extra_args = { '-m' },
}, -- LaTeX
'formatting.stylua', -- Lua
},
})Layer-specific API#
Other layers (mostly language layers) may interact with lsp via the
following methods.
use_server(lang:string, install:boolean, srv:string, settings:table)#
Enables an LSP sever at startup, where:
langis the name of the language (used by Mason);installistrueif the server should be installed via Mason;srvis the name of the server executable (if any);settingsare any optional settings for the language server.
layers.get('lsp').use_server('go', true, 'gopls', {})on_attach(fn:function)#
Adds an “on-attach”-like handler to be invoked when LSs get enabled for a buffer.
on_attach_one_time(fn:function)#
Adds an “on-attach”-like handler to be invoked each time a buffer sees an LS enabled for the first time.
get_callbacks()#
Returns the list of “on-attach”-like handlers.
get_callbacks_one_time()#
Returns the list of “on-attach-one-time”-like handlers.
get_capabilities()#
Returns the capabilities’ handler.
Documentation#
You are encouraged to read the documentation for nvim-lspconfig, mason.nvim,
and nulls.nvim. These projects are linked at the beginning of this page.