Awesome
mason-lspconfig.nvim
<p align="center"> <code>mason-lspconfig</code> bridges <a href="https://github.com/williamboman/mason.nvim"><code>mason.nvim</code></a> with the <a href="https://github.com/neovim/nvim-lspconfig"><code>lspconfig</code></a> plugin - making it easier to use both plugins together. </p> <p align="center"> <code>:help mason-lspconfig.nvim</code> </p> <p align="center"> <sup>Latest version: v1.31.0</sup> <!-- x-release-please-version --> </p>Table of Contents
Introduction
:h mason-lspconfig-introduction
mason-lspconfig.nvim
closes some gaps that exist between mason.nvim
and lspconfig
. Its main responsibilities are to:
- register a setup hook with
lspconfig
that ensures servers installed withmason.nvim
are set up with the necessary configuration - provide extra convenience APIs such as the
:LspInstall
command - allow you to (i) automatically install, and (ii) automatically set up a predefined list of servers
- translate between
lspconfig
server names andmason.nvim
package names (e.g.lua_ls <-> lua-language-server
)
It is recommended to use this extension if you use mason.nvim
and lspconfig
(it's strongly recommended for Windows
users).
Note: this plugin uses the lspconfig
server names in the APIs it exposes - not mason.nvim
package names. See this
table for a complete mapping.
Requirements
:h mason-lspconfig-requirements
- neovim
>= 0.9.0
mason.nvim
lspconfig
Installation
Packer
use {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig",
}
lazy.nvim
{
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig",
}
vim-plug
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'neovim/nvim-lspconfig'
Setup
:h mason-lspconfig-quickstart
It's important that you set up the plugins in the following order:
mason.nvim
mason-lspconfig.nvim
- Setup servers via
lspconfig
Pay extra attention to this if you lazy-load plugins, or somehow "chain" the loading of plugins via your plugin manager.
require("mason").setup()
require("mason-lspconfig").setup()
-- After setting up mason-lspconfig you may set up servers via lspconfig
-- require("lspconfig").lua_ls.setup {}
-- require("lspconfig").rust_analyzer.setup {}
-- ...
Refer to the Configuration section for information about which settings are available.
Automatic server setup (advanced feature)
:h mason-lspconfig-automatic-server-setup
mason-lspconfig
provides extra, opt-in, functionality that allows you to automatically set up LSP servers installed
via mason.nvim
without having to manually add each server setup to your Neovim configuration.
Refer to :h mason-lspconfig-automatic-server-setup
for more details.
Commands
:h mason-lspconfig-commands
:LspInstall [<server>...]
- installs the provided servers:LspUninstall <server> ...
- uninstalls the provided servers
Configuration
:h mason-lspconfig-settings
You may optionally configure certain behavior of mason-lspconfig.nvim
when calling the .setup()
function. Refer to
the default configuration for a list of all available settings.
Example:
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls", "rust_analyzer" },
}
Default configuration
local DEFAULT_SETTINGS = {
-- A list of servers to automatically install if they're not already installed. Example: { "rust_analyzer@nightly", "lua_ls" }
-- This setting has no relation with the `automatic_installation` setting.
---@type string[]
ensure_installed = {},
-- Whether servers that are set up (via lspconfig) should be automatically installed if they're not already installed.
-- This setting has no relation with the `ensure_installed` setting.
-- Can either be:
-- - false: Servers are not automatically installed.
-- - true: All servers set up via lspconfig are automatically installed.
-- - { exclude: string[] }: All servers set up via lspconfig, except the ones provided in the list, are automatically installed.
-- Example: automatic_installation = { exclude = { "rust_analyzer", "solargraph" } }
---@type boolean
automatic_installation = false,
-- See `:h mason-lspconfig.setup_handlers()`
---@type table<string, fun(server_name: string)>?
handlers = nil,
}