@@ -270,13 +270,15 @@ require('lazy').setup({
270
270
{
271
271
' neovim/nvim-lspconfig' ,
272
272
dependencies = {
273
- -- Automatically install LSPs and related tools to stdpath for Neovim.
274
- { ' williamboman/mason.nvim' , config = true }, -- NOTE: Must be loaded before dependants
275
- ' williamboman/mason-lspconfig.nvim' ,
273
+ -- NOTE: passing `opts = {}` is the same as calling `require(...).setup({})`
274
+ --
275
+ -- Automatically install LSPs and related tools to stdpath for Neovim
276
+ -- Mason must be loaded before its dependents so we need to set it up here.
277
+ { ' mason-org/mason.nvim' , opts = {} },
278
+ ' mason-org/mason-lspconfig.nvim' ,
276
279
' WhoIsSethDaniel/mason-tool-installer.nvim' ,
277
280
278
281
-- Useful status updates for LSP.
279
- -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
280
282
{ ' j-hui/fidget.nvim' , opts = {} },
281
283
282
284
-- `neodev` configures Lua LSP for your Neovim config, runtime and plugins
@@ -349,93 +351,109 @@ require('lazy').setup({
349
351
})
350
352
351
353
-- LSP servers and clients are able to communicate to each other what features they support.
352
- -- By default, Neovim doesn't support everything that is in the LSP specification.
353
- -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
354
- -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
355
- local capabilities = vim .lsp .protocol .make_client_capabilities ()
356
- capabilities = require (' blink.cmp' ).get_lsp_capabilities (capabilities )
354
+ -- By default, Neovim doesn't support everything that is in the LSP specification. When you
355
+ -- add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. So, in theory, we need to
356
+ -- create new capabilities with blink.cmp, and then broadcast that to the servers.
357
+ --
358
+ -- However, blink.cmp now extends capabilites by default from its internal code[1]. But,
359
+ -- previously, the following line was required by the completion plugin that preceeded
360
+ -- blink.cmp.
361
+ --
362
+ -- local capabilities = require("blink.cmp").get_lsp_capabilities()
363
+ --
364
+ -- [1]: https://github.com/Saghen/blink.cmp/blob/102db2f5996a/plugin/blink-cmp.lua
357
365
358
- -- Enable the following language servers. They will automatically be installed.
366
+ -- Language server configuration.
367
+ --
368
+ -- Comprised by the following sub-tables:
369
+ --
370
+ -- - mason: servers automatically installed with mason
371
+ -- - others: other servers available on the system
372
+ --
373
+ -- Both tables have an identical structure of language server names as keys and a table of
374
+ -- language server (override) configuration as values. The available keys are:
359
375
--
360
- -- Add any additional override configuration in the following tables. Available keys are:
361
376
-- - cmd (table): Override the default command used to start the server
362
377
-- - filetypes (table): Override the default list of associated filetypes for the server
363
378
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
364
379
-- - settings (table): Override the default settings passed when initializing the server.
365
380
--
366
- -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
367
- --
368
381
-- See `:help lspconfig-all` for a list of all the pre-configured LSPs.
382
+ --- @class LspServersConfig
383
+ --- @field mason table<string , vim.lsp.Config>
384
+ --- @field others table<string , vim.lsp.Config>
369
385
local servers = {
370
- -- rust-analyzer
371
- --
372
- -- Documentation:
373
- -- - https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
374
- -- - https://github.com/rust-lang/rust-analyzer/blob/master/docs/user/generated_config.adoc
375
- -- - https://rust-analyzer.github.io/manual.html
376
- --
377
- -- TODO: look into https://github.com/mrcjkb/rustaceanvim for a more advanced setup.
378
- -- TODO: support workspace/project-specific settings (see rustaceanvim).
379
- rust_analyzer = {
380
- settings = {
381
- [ ' rust-analyzer ' ] = {
382
- imports = {
383
- granularity = {
384
- enforce = true ,
385
- group = ' module ' ,
386
+ mason = {
387
+ rust_analyzer = {
388
+ -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
389
+ -- https://rust-analyzer. github.io/manual.html
390
+ -- TODO: look into https://github.com/mrcjkb/rustaceanvim for a more advanced setup
391
+ -- TODO: support workspace/project-specific settings (see rustaceanvim)
392
+ settings = {
393
+ [ ' rust-analyzer ' ] = {
394
+ imports = {
395
+ granularity = {
396
+ enforce = true ,
397
+ group = ' module ' ,
398
+ },
399
+ },
400
+ check = {
401
+ command = ' clippy ' ,
386
402
},
387
- },
388
- check = {
389
- command = ' clippy' ,
390
403
},
391
404
},
392
405
},
393
- -- cmd = { '/usr/bin/rust-analyzer' },
394
- },
395
406
396
- lua_ls = {
397
- settings = {
398
- Lua = {
399
- completion = {
400
- callSnippet = ' Replace' ,
407
+ lua_ls = {
408
+ settings = {
409
+ Lua = {
410
+ completion = {
411
+ callSnippet = ' Replace' ,
412
+ },
413
+ diagnostics = { disable = { ' missing-fields' } },
401
414
},
402
- -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
403
- -- diagnostics = { disable = { 'missing-fields' } },
404
415
},
405
416
},
406
- },
407
417
408
- pyright = {},
409
- clangd = {},
418
+ -- For many servers and setups, the defaults work just fine.
419
+ eslint = {},
420
+ tailwindcss = {},
421
+ ts_ls = {},
422
+ pyright = {},
423
+ clangd = {},
424
+ },
425
+ others = {},
410
426
}
411
427
412
- -- Ensure the servers and tools above are installed.
428
+ -- Ensure the servers and tools managed by Mason ( above) are installed.
413
429
--
414
- -- To check the current status of installed tools and/or manually install other tools:
415
- -- :Mason
416
- -- (You can press `g?` for help in that menu).
417
- require (' mason' ).setup ()
418
-
419
- -- You can add other tools here that you want Mason to install
420
- -- for you, so that they are available from within Neovim.
421
- local ensure_installed = vim .tbl_keys (servers or {})
430
+ -- You can add other tools here that you want Mason to install for you, so that they are
431
+ -- available from within Neovim.
432
+ local ensure_installed = vim .tbl_keys (servers .mason or {})
422
433
vim .list_extend (ensure_installed , {
423
434
' stylua' , -- Used to format Lua code
424
435
})
425
436
require (' mason-tool-installer' ).setup { ensure_installed = ensure_installed }
426
437
438
+ -- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
439
+ -- to the default language server configs as provided by nvim-lspconfig or
440
+ -- define a custom server config that's unavailable on nvim-lspconfig.
441
+ for server , config in pairs (vim .tbl_extend (' keep' , servers .mason , servers .others )) do
442
+ if not vim .tbl_isempty (config ) then
443
+ vim .lsp .config (server , config )
444
+ end
445
+ end
446
+
447
+ -- After configuring our language servers, we now enable them
427
448
require (' mason-lspconfig' ).setup {
428
- handlers = {
429
- function (server_name )
430
- local server = servers [server_name ] or {}
431
- -- This handles overriding only values explicitly passed
432
- -- by the server configuration above. Useful when disabling
433
- -- certain features of an LSP (for example, turning off formatting for tsserver).
434
- server .capabilities = vim .tbl_deep_extend (' force' , {}, capabilities , server .capabilities or {})
435
- require (' lspconfig' )[server_name ].setup (server )
436
- end ,
437
- },
449
+ ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
450
+ automatic_enable = true , -- automatically run vim.lsp.enable() for all servers that are installed via Mason
438
451
}
452
+
453
+ -- Manually run vim.lsp.enable for all language servers that are *not* installed via Mason
454
+ if not vim .tbl_isempty (servers .others ) then
455
+ vim .lsp .enable (vim .tbl_keys (servers .others ))
456
+ end
439
457
end ,
440
458
},
441
459
0 commit comments