@@ -221,48 +221,92 @@ return { -- LSP Plugins
221221 -- By default, Neovim doesn't support everything that is in the LSP specification.
222222 -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
223223 -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
224- local capabilities = require (' blink.cmp' ).get_lsp_capabilities ()
225-
226- -- Enable the following language servers
227- -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
224+ -- NOTE: The following line is now commented as blink.cmp extends capabilites by default from its internal code: 1Code has comments. Press enter to view.
225+ -- https://github.com/Saghen/blink.cmp/blob/102db2f5996a46818661845cf283484870b60450/plugin/blink-cmp.lua
226+ -- It has been left here as a comment for educational purposes (as the predecessor completion plugin required this explicit step).
228227 --
229- -- Add any additional override configuration in the following tables. Available keys are:
230- -- - cmd (table): Override the default command used to start the server
231- -- - filetypes (table): Override the default list of associated filetypes for the server
232- -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
233- -- - settings (table): Override the default settings passed when initializing the server.
234- -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
228+ -- local capabilities = require("blink.cmp").get_lsp_capabilities()
229+
230+ -- Language servers can broadly be installed in the following ways:
231+ -- 1) via the mason package manager; or
232+ -- 2) via your system's package manager; or
233+ -- 3) via a release binary from a language server's repo that's accessible somewhere on your system.
234+
235+ -- The servers table comprises the following sub-tables:
236+ -- 1. mason
237+ -- 2. others
238+ -- Both these tables have an identical structure of language server names as keys and
239+ -- a table of language server configuration as values.
240+ --- @class LspServersConfig
241+ --- @field mason table<string , vim.lsp.Config>
242+ --- @field others table<string , vim.lsp.Config>
235243 local servers = {
236- emmet_language_server = {},
237- ruby_lsp = {},
238- -- clangd = {},
239- -- gopls = {},
240- -- pyright = {},
241- -- rust_analyzer = {},
242- -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
243- --
244- -- Some languages (like typescript) have entire language plugins that can be useful:
245- -- https://github.com/pmizio/typescript-tools.nvim
246- --
247- -- But for many setups, the LSP (`ts_ls`) will work just fine
248- ts_ls = {},
244+ -- Add any additional override configuration in any of the following tables. Available keys are:
245+ -- - cmd (table): Override the default command used to start the server
246+ -- - filetypes (table): Override the default list of associated filetypes for the server
247+ -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
248+ -- - settings (table): Override the default settings passed when initializing the server.
249+ -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
249250 --
251+ -- Feel free to add/remove any LSPs here that you want to install via Mason. They will automatically be installed and setup.
252+ mason = {
253+ -- emmet_language_server = {
254+ -- filetypes = {
255+ -- 'css',
256+ -- 'eelixir',
257+ -- 'elixir',
258+ -- 'heex',
259+ -- 'html',
260+ -- 'javascript',
261+ -- 'javascriptreact',
262+ -- 'less',
263+ -- 'sass',
264+ -- 'scss',
265+ -- 'typescriptreact',
266+ -- },
267+ -- -- init_options = {
268+ -- -- includeLanguages = {
269+ -- -- eelixir = 'html',
270+ -- -- elixir = 'html',
271+ -- -- heex = 'html',
272+ -- -- },
273+ -- -- },
274+ -- },
275+ ruby_lsp = {},
276+ -- clangd = {},
277+ -- gopls = {},
278+ -- pyright = {},
279+ -- rust_analyzer = {},
280+ -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
281+ --
282+ -- Some languages (like typescript) have entire language plugins that can be useful:
283+ -- https://github.com/pmizio/typescript-tools.nvim
284+ --
285+ -- But for many setups, the LSP (`ts_ls`) will work just fine
286+ ts_ls = {},
287+ --
250288
251- lua_ls = {
252- -- cmd = { ... },
253- -- filetypes = { ... },
254- -- capabilities = {},
255- settings = {
256- Lua = {
257- completion = {
258- callSnippet = ' Replace' ,
289+ lua_ls = {
290+ -- cmd = { ... },
291+ -- filetypes = { ... },
292+ -- capabilities = {},
293+ settings = {
294+ Lua = {
295+ completion = {
296+ callSnippet = ' Replace' ,
297+ },
298+ -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
299+ -- diagnostics = { disable = { 'missing-fields' } },
300+ diagnostics = { globals = { ' vim' , ' require' } },
259301 },
260- -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
261- -- diagnostics = { disable = { 'missing-fields' } },
262- diagnostics = { globals = { ' vim' , ' require' } },
263302 },
264303 },
265304 },
305+ -- This table contains config for all language servers that are *not* installed via Mason.
306+ -- Structure is identical to the mason table from above.
307+ others = {
308+ -- dartls = {},
309+ },
266310 }
267311
268312 -- Ensure the servers and tools above are installed
@@ -278,58 +322,32 @@ return { -- LSP Plugins
278322 --
279323 -- You can add other tools here that you want Mason to install
280324 -- for you, so that they are available from within Neovim.
281- local ensure_installed = vim .tbl_keys (servers or {})
325+ local ensure_installed = vim .tbl_keys (servers . mason or {})
282326 vim .list_extend (ensure_installed , {
283327 ' stylua' , -- Used to format Lua code
284328 -- 'vale',
285329 })
286330 require (' mason-tool-installer' ).setup { ensure_installed = ensure_installed }
287331
332+ -- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
333+ -- to the default language server configs as provided by nvim-lspconfig, or
334+ -- define a custom server config that's unavailable on nvim-lspconfig.
335+ for server , config in pairs (vim .tbl_extend (' keep' , servers .mason , servers .others )) do
336+ if not vim .tbl_isempty (config ) then
337+ vim .lsp .config (server , config )
338+ end
339+ end
340+
341+ -- After configuring our language servers, we now enable them.
288342 require (' mason-lspconfig' ).setup {
289343 ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
290- automatic_enable = {
291- exclude = {
292- -- HACK: I was unable to get the `filetypes` and `init_options` working in the emmet table above, and this
293- -- was the solution :(
294- ' emmet_language_server' ,
295- },
296- },
297- automatic_installation = false ,
298- handlers = {
299- function (server_name )
300- local server = servers [server_name ] or {}
301- -- This handles overriding only values explicitly passed
302- -- by the server configuration above. Useful when disabling
303- -- certain features of an LSP (for example, turning off formatting for ts_ls)
304- server .capabilities = vim .tbl_deep_extend (' force' , {}, capabilities , server .capabilities or {})
305- require (' lspconfig' )[server_name ].setup (server )
306- end ,
307- },
344+ automatic_installation = true , -- automatically run vim.lsp.enable() for all servers that are installed via Mason
308345 }
309346
310- -- HACK: See above hack
311- require (' lspconfig' )[' emmet_language_server' ].setup {
312- filetypes = {
313- ' css' ,
314- ' eelixir' ,
315- ' elixir' ,
316- ' heex' ,
317- ' html' ,
318- ' javascript' ,
319- ' javascriptreact' ,
320- ' less' ,
321- ' sass' ,
322- ' scss' ,
323- ' typescriptreact' ,
324- },
325- init_options = {
326- includeLanguages = {
327- eelixir = ' html' ,
328- elixir = ' html' ,
329- heex = ' html' ,
330- },
331- },
332- }
347+ -- Manually run vim.lsp.enable for all langauge servers that are *not* installed via Mason
348+ if not vim .tbl_isempty (servers .others ) then
349+ vim .lsp .enable (vim .tbl_keys (servers .others ))
350+ end
333351 end ,
334352 },
335353 {
0 commit comments