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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
*mason-lspconfig.nvim*
Minimum version of Neovim: 0.11.0
Author: William Boman
Type |gO| to see the table of contents.
==============================================================================
INTRODUCTION *mason-lspconfig-introduction*
`mason-lspconfig.nvim` closes some gaps that exist between `mason.nvim` and
`nvim-lspconfig`. Its main responsibilities are to:
- allow you to (i) automatically install, and (ii) automatically 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`)
==============================================================================
REQUIREMENTS *mason-lspconfig-requirements*
`mason-lspconfig` requires `mason.nvim` and `nvim-lspconfig` to be installed.
Note that `nvim-lspconfig` needs to be available in |rtp| before you set up
`mason-lspconfig`.
- `neovim >= 0.11.0`
- `mason.nvim >= 2.0.0`
- `nvim-lspconfig >= 2.0.0`
==============================================================================
QUICK START *mason-lspconfig-quickstart*
-----------------
Setting up mason-lspconfig.nvim
It's important that you set up `mason.nvim` and have `nvim-lspconfig`
available in |'runtimepath'| before setting up `mason-lspconfig.nvim`.
To enable the `mason-lspconfig` plugin, call the `setup()` function, like so:
>lua
require("mason").setup()
require("mason-lspconfig").setup()
<
Refer to |mason-lspconfig-settings| for available settings.
-----------------
Setting up servers
Next, you're ready to set up the servers you want to use. Refer to lspconfig's
documentation |lspconfig-quickstart| for more information on how to do so!
`mason-lspconfig.nvim` will automatically enable (|vim.lsp.enable()|) installed
servers for you by default, see |mason-automatic-enable|.
-----------------
Installation of servers
To install an LSP server supported by `nvim-lspconfig` (and `mason.nvim`) you
may use the `:LspInstall` command, like so:
>vim
:LspInstall rust_analyzer lua_ls
<
This command is more or less an alias of the |:MasonInstall| command, except
that it only accepts LSP servers and - more importantly - only accepts
`nvim-lspconfig` server names (as opposed to `mason.nvim` package names).
You may also run the same command without any arguments. This will prompt you
with a selection of servers that are recommended for the filetype of the
buffer you're currently editing:
>vim
:LspInstall
<
==============================================================================
COMMANDS *mason-lspconfig-commands*
------------------------------------------------------------------------------
INSTALLING AN LSP SERVER
*:LspInstall*
>vim
:LspInstall [<server>...]
<
Installs the provided servers. This command only accepts servers that have a
corresponding server configuration in `nvim-lspconfig`.
You may also provide a language, like `:LspInstall typescript`. This will
prompt you with a selection of all available servers for that given language.
When the command is ran without any arguments, the currently active buffer's
'filetype' will be used to identify relevant servers, and you will be prompted
with a selection of all suggested servers.
------------------------------------------------------------------------------
UNINSTALLING AN LSP SERVER
*:LspUninstall*
>vim
:LspUninstall <server> ...
<
Uninstalls the provided servers.
==============================================================================
SETTINGS *mason-lspconfig-settings*
You can configure certain behavior of `mason-lspconfig` when calling the
`.setup()` function.
Refer to |mason-lspconfig-default-settings| for all available settings.
Example:
>lua
require("mason-lspconfig").setup({
ensure_installed = { "rust_analyzer", "ts_ls" }
})
<
*mason-lspconfig-default-settings*
>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,
}
<
==============================================================================
AUTOMATICALLY ENABLE SERVERS *mason-automatic-enable*
By default, `mason-lspconfig` will automatically enable servers you have
installed in Mason. This means you don't have to call |vim.lsp.enable()|
yourself.
To disable this feature:
>lua
require("mason-lspconfig").setup({
automatic_enable = false
})
<
Note: ~
Servers that you have installed outside of Mason will not be recognized by
this feature. You will still have to manually enable (|vim.lsp.enable()|)
such servers yourself.
==============================================================================
Lua module: mason-lspconfig
*mason-lspconfig.setup()*
setup({config})
Sets up mason with the provided {config} (see |mason-lspconfig-settings|).
*mason-lspconfig.get_installed_servers()*
get_installed_servers()
Returns the installed LSP servers supported by lspconfig.
Note: ~
The returned strings are the nvim-lspconfig server names, not the
Mason package names. For example, "lua_ls" is returned instead of
"lua-language-server".
Returns: ~
string[]
See also: ~
|mason-registry.get_installed_packages()|
|mason-registry.get_installed_package_names()|
*mason-lspconfig.get_available_servers()*
get_available_servers({filter})
Returns the available (both installed & uninstalled) LSP servers.
Note: ~
The returned strings are the nvim-lspconfig server names, not the
Mason package names. For example, "lua_ls" is returned instead of
"lua-language-server".
Parameters: ~
{filter} (table|nil) A table with key-value pairs used to
filter the list of server names. The available keys are:
- filetype (string | string[]): Only return servers with
matching filetype
Returns: ~
string[]
See also: ~
|mason-registry.get_all_packages()|
|mason-registry.get_all_package_names()|
*mason-lspconfig.get_mappings()*
get_mappings()
Returns:
- server name mappings between nvim-lspconfig and Mason.
- filetype mappings for supported servers
Returns: ~
{
lspconfig_to_package: table<string, string>,
package_to_lspconfig: table<string, string>,
filetypes: table<string, string[]>
}
Note: ~
This function only returns nvim-lspconfig servers that are recognized
by Mason.
vim:tw=78:ft=help:norl:expandtab:sw=4
|