跳到主要内容
版本:1.4

语言服务器

This page needs improvement

Installing and updating a server

Automatic server installation

By default, most supported language servers will get automatically installed once you open the supported file-type, e.g, opening a Python file for the first time will install Pyright and configure it automatically for you.

  • configuration option
lvim.lsp.automatic_servers_installation = true

Please refer to mason to see the updated full list of currently available servers.

To install a supported language server:

:LspInstall `<your_language_server>`

You can also toggle <:Mason> and interactively choose which servers to install.

Server override

lvim.lsp.automatic_configuration.skipped_servers contains a list of servers that will not be automatically configured by default, for example only tsserver is allowed for JS-family languages, and when a language has more than one server available, then the most popular one is usually chosen.

提示

Overriding a server will completely bypass the lsp-installer, so you would have to manage the installation for any of those servers manually.

See the current list

:lua print(vim.inspect(lvim.lsp.automatic_configuration.skipped_servers))

See the default list in lua/lvim/lsp/config.lua

提示

Any changes to lvim.lsp.automatic_configuration.skipped_servers must be followed by :LvimCacheReset to take effect.

Server setup

LunarVim uses filetype plugins to enable lazy-loading the setup of a language server. A template generator is used to create ftplugin files and populate them with the setup call.

  • configuration option
lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "after", "ftplugin")

A typical setup call with default arguments

-- edit this file by running `:lua vim.cmd("edit " .. lvim.lsp.templates_dir .. "/lua.lua")`
require("lvim.lsp.manager").setup("sumneko_lua")
提示

You can quickly find these files by running <leader>Lf -> "Find LunarVim Files"

Overriding the default setup options

Add the server you wish to configure manually to lvim.lsp.automatic_configuration.skipped_servers.

vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "pyright" })

Now you can set it up manually using the builtin lsp-manager

--- list of options that should take precedence over any of LunarVim's defaults
--- check the lspconfig documentation for a list of all possible options
local opts = {}
require("lvim.lsp.manager").setup("pyright", opts)

Alternatively, set it up using the lspconfig API directly

--- check the lspconfig documentation for a list of all possible options
local opts = {}
require("lspconfig")["pyright"].setup(opts)

Server settings

To set a setting for your language server:

:LspSettings <TAB>
:LspSettings <NAME_OF_LANGUAGE_SERVER>

This will create a file in $LUNARVIM_CONFIG_DIR/lsp-settings, to enable persistent changes. Refer to the documentation of nlsp-settings for a full updated list of supported language servers.

提示

Make sure to install jsonls for autocompletion.