1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|



[](https://github.com/mason-org/mason-lspconfig.nvim/actions?query=workflow%3ATests+branch%3Amain+event%3Apush)
[](https://github.com/sponsors/mason-org)
<h1 align="center">mason-lspconfig.nvim</h1>
<p align="center">
<code>mason-lspconfig</code> bridges <a
href="https://github.com/mason-org/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: v2.0.0</sup> <!-- x-release-please-version -->
</p>
## Table of Contents
- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation & Usage](#installation--usage)
- [Recommended setup for `lazy.nvim`](#recommended-setup-for-lazynvim)
- [Automatically enable installed servers](#automatically-enable-installed-servers)
- [Commands](#commands)
- [Configuration](#configuration)
- [Default configuration](#default-configuration)
## Introduction
> `:h mason-lspconfig-introduction`
This plugin's main responsibilities are to:
- allow you to (i) automatically install, and (ii) automatically enable (`vim.lsp.enable()`) installed servers
- provide extra convenience APIs such as the `:LspInstall` command
- provide additional LSP configurations for a few servers
- translate between `nvim-lspconfig` server names and `mason.nvim` package names (e.g. `lua_ls <-> lua-language-server`)
> [!NOTE]
> Since the introduction of [`:h vim.lsp.config`](https://neovim.io/doc/user/lsp.html#vim.lsp.config()) in Neovim 0.11,
> this plugin's feature set has been reduced. Use this plugin if you want to automatically enable installed servers
> ([`:h vim.lsp.enable()`](https://neovim.io/doc/user/lsp.html#vim.lsp.enable())) or have access to the `:LspInstall`
> command.
## Requirements
> `:h mason-lspconfig-requirements`
- `neovim >= 0.11.0`
- `mason.nvim >= 2.0.0`
- `nvim-lspconfig >= 2.0.0`
## Installation & Usage
> `:h mason-lspconfig-quickstart`
Install using your plugin manager of choice. **Setup is required**:
```lua
require("mason-lspconfig").setup()
```
It's important that you set up `mason.nvim` _and_ have `nvim-lspconfig` available in [`:h
runtimepath`](https://neovim.io/doc/user/options.html#'runtimepath') before setting up `mason-lspconfig.nvim`.
Refer to the [Configuration](#configuration) section for information about which settings are available.
### Recommended setup for `lazy.nvim`
The following is the recommended setup when using `lazy.nvim`. It will set up the plugin for you, meaning **you don't have
to call `require("mason-lspconfig").setup()` yourself**.
```lua
{
"mason-org/mason-lspconfig.nvim",
opts = {},
dependencies = {
{ "mason-org/mason.nvim", opts = {} },
"neovim/nvim-lspconfig",
},
}
```
## Automatically enable installed servers
`mason-lspconfig.nvim` will automatically enable (`vim.lsp.enable()`) installed servers for you by default.
To disable this feature:
```lua
require("mason-lspconfig").setup {
automatic_enable = false
}
```
To exclude certain servers from being enabled:
```lua
require("mason-lspconfig").setup {
automatic_enable = {
exclude = {
"rust_analyzer",
"ts_ls"
}
}
}
```
Alternatively, to only enable specific servers:
```lua
require("mason-lspconfig").setup {
automatic_enable = {
"lua_ls",
"vimls"
}
}
```
> [!NOTE]
> This will only enable servers that are installed via Mason. It will not recognize servers installed elsewhere on your
> system.
## Commands
> `:h mason-lspconfig-commands`
- `:LspInstall [<server> ...]`: Installs the provided servers. If no server is provided you will be prompted to select a
server based on the current buffer's `&filetype`.
- `: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](#default-configuration) for a list of all available settings.
Example:
```lua
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls", "rust_analyzer" },
}
```
### Configuration using `lazy.nvim`
```lua
{
"mason-org/mason-lspconfig.nvim",
opts = {
ensure_installed = { "lua_ls", "rust_analyzer" },
},
dependencies = {
{ "mason-org/mason.nvim", opts = {} },
"neovim/nvim-lspconfig",
},
}
```
### Default configuration
```lua
local DEFAULT_SETTINGS = {
-- A list of servers to automatically install if they're not already installed. Example: { "rust_analyzer@nightly", "lua_ls" }
---@type string[]
ensure_installed = {},
-- Whether installed servers should automatically be enabled via `:h vim.lsp.enable()`.
--
-- To exclude certain servers from being automatically enabled:
-- ```lua
-- automatic_enable = {
-- exclude = { "rust_analyzer", "ts_ls" }
-- }
-- ```
--
-- To only enable certain servers to be automatically enabled:
-- ```lua
-- automatic_enable = {
-- "lua_ls",
-- "vimls"
-- }
-- ```
---@type boolean | string[] | { exclude: string[] }
automatic_enable = true,
}
```
|