Skip to content

Commit 327a441

Browse files
committed
add fix for deprecated Mason setup, adds back LSP settings
applies patch from nvim-lua#1475 , should be altered to the upstream version when it propagates down to kickstar-modular
1 parent 8cce409 commit 327a441

File tree

1 file changed

+101
-76
lines changed

1 file changed

+101
-76
lines changed

lua/kickstart/plugins/lspconfig.lua

Lines changed: 101 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ return {
1919
-- Automatically install LSPs and related tools to stdpath for Neovim
2020
-- Mason must be loaded before its dependents so we need to set it up here.
2121
-- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
22-
{ 'mason-org/mason.nvim', opts = {} },
22+
{
23+
'mason-org/mason.nvim',
24+
---@module 'mason.settings'
25+
---@type MasonSettings
26+
---@diagnostic disable-next-line: missing-fields
27+
opts = {},
28+
},
2329
'mason-org/mason-lspconfig.nvim',
2430
'WhoIsSethDaniel/mason-tool-installer.nvim',
2531

@@ -109,26 +115,18 @@ return {
109115
-- the definition of its *type*, not where it was *defined*.
110116
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
111117

112-
-- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
113-
---@param client vim.lsp.Client
114-
---@param method vim.lsp.protocol.Method
115-
---@param bufnr? integer some lsp support methods only in specific files
116-
---@return boolean
117-
local function client_supports_method(client, method, bufnr)
118-
if vim.fn.has 'nvim-0.11' == 1 then
119-
return client:supports_method(method, bufnr)
120-
else
121-
return client.supports_method(method, { bufnr = bufnr })
122-
end
123-
end
118+
-- Toggle to show/hide diagnostic messages
119+
map('<leader>td', function()
120+
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
121+
end, '[T]oggle [D]iagnostics')
124122

125123
-- The following two autocommands are used to highlight references of the
126124
-- word under your cursor when your cursor rests there for a little while.
127125
-- See `:help CursorHold` for information about when this is executed
128126
--
129127
-- When you move your cursor, the highlights will be cleared (the second autocommand).
130128
local client = vim.lsp.get_client_by_id(event.data.client_id)
131-
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
129+
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
132130
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
133131
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
134132
buffer = event.buf,
@@ -155,7 +153,7 @@ return {
155153
-- code, if the language server you are using supports them
156154
--
157155
-- This may be unwanted, since they displace some of your code
158-
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
156+
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
159157
map('<leader>th', function()
160158
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
161159
end, '[T]oggle Inlay [H]ints')
@@ -168,7 +166,6 @@ return {
168166
vim.diagnostic.config {
169167
severity_sort = true,
170168
float = { border = 'rounded', source = 'if_many' },
171-
underline = { severity = vim.diagnostic.severity.ERROR },
172169
signs = vim.g.have_nerd_font and {
173170
text = {
174171
[vim.diagnostic.severity.ERROR] = '󰅚 ',
@@ -180,68 +177,84 @@ return {
180177
virtual_text = {
181178
source = 'if_many',
182179
spacing = 2,
183-
format = function(diagnostic)
184-
local diagnostic_message = {
185-
[vim.diagnostic.severity.ERROR] = diagnostic.message,
186-
[vim.diagnostic.severity.WARN] = diagnostic.message,
187-
[vim.diagnostic.severity.INFO] = diagnostic.message,
188-
[vim.diagnostic.severity.HINT] = diagnostic.message,
189-
}
190-
return diagnostic_message[diagnostic.severity]
191-
end,
192180
},
181+
-- Display multiline diagnostics as virtual lines
182+
-- virtual_lines = true,
193183
}
194184

195185
-- LSP servers and clients are able to communicate to each other what features they support.
196186
-- By default, Neovim doesn't support everything that is in the LSP specification.
197187
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
198188
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
199-
local capabilities = require('blink.cmp').get_lsp_capabilities()
200-
201-
-- Enable the following language servers
202-
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
189+
-- NOTE: The following line is now commented as blink.cmp extends capabilites by default from its internal code:
190+
-- https://github.com/Saghen/blink.cmp/blob/102db2f5996a46818661845cf283484870b60450/plugin/blink-cmp.lua
191+
-- It has been left here as a comment for educational purposes (as the predecessor completion plugin required this explicit step).
203192
--
204-
-- Add any additional override configuration in the following tables. Available keys are:
205-
-- - cmd (table): Override the default command used to start the server
206-
-- - filetypes (table): Override the default list of associated filetypes for the server
207-
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
208-
-- - settings (table): Override the default settings passed when initializing the server.
209-
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
193+
-- local capabilities = require("blink.cmp").get_lsp_capabilities()
194+
195+
-- Language servers can broadly be installed in the following ways:
196+
-- 1) via the mason package manager; or
197+
-- 2) via your system's package manager; or
198+
-- 3) via a release binary from a language server's repo that's accessible somewhere on your system.
199+
200+
-- The servers table comprises of the following sub-tables:
201+
-- 1. mason
202+
-- 2. others
203+
-- Both these tables have an identical structure of language server names as keys and
204+
-- a table of language server configuration as values.
205+
---@class LspServersConfig
206+
---@field mason table<string, vim.lsp.Config>
207+
---@field others table<string, vim.lsp.Config>
210208
local servers = {
211-
-- clangd = {},
212-
-- gopls = {},
213-
-- pyright = {},
214-
-- rust_analyzer = {},
215-
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
209+
-- Add any additional override configuration in any of the following tables. Available keys are:
210+
-- - cmd (table): Override the default command used to start the server
211+
-- - filetypes (table): Override the default list of associated filetypes for the server
212+
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
213+
-- - settings (table): Override the default settings passed when initializing the server.
214+
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
216215
--
217-
-- Some languages (like typescript) have entire language plugins that can be useful:
218-
-- https://github.com/pmizio/typescript-tools.nvim
219-
--
220-
-- But for many setups, the LSP (`ts_ls`) will work just fine
221-
-- ts_ls = {},
222-
--
223-
svelte = {
224-
capabilities = { workspace = { didChangeWatchedFiles = false } },
225-
settings = {
226-
lint = { unknownAtRules = 'ignore' },
227-
typescript = { enable = true, preferences = { importModuleSpecifier = 'non-relative' } },
228-
javascript = { enable = true, preferences = { importModuleSpecifier = 'non-relative' } },
229-
},
230-
},
231-
lua_ls = {
232-
-- cmd = { ... },
233-
-- filetypes = { ... },
234-
-- capabilities = {},
235-
settings = {
236-
Lua = {
237-
completion = {
238-
callSnippet = 'Replace',
216+
-- Feel free to add/remove any LSPs here that you want to install via Mason. They will automatically be installed and setup.
217+
mason = {
218+
-- clangd = {},
219+
-- gopls = {},
220+
-- pyright = {},
221+
-- rust_analyzer = {},
222+
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
223+
--
224+
-- Some languages (like typescript) have entire language plugins that can be useful:
225+
-- https://github.com/pmizio/typescript-tools.nvim
226+
--
227+
-- But for many setups, the LSP (`ts_ls`) will work just fine
228+
-- ts_ls = {},
229+
--
230+
lua_ls = {
231+
-- cmd = { ... },
232+
-- filetypes = { ... },
233+
-- capabilities = {},
234+
settings = {
235+
Lua = {
236+
completion = {
237+
callSnippet = 'Replace',
238+
},
239+
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
240+
-- diagnostics = { disable = { 'missing-fields' } },
239241
},
240-
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
241-
-- diagnostics = { disable = { 'missing-fields' } },
242+
},
243+
},
244+
svelte = {
245+
capabilities = { workspace = { didChangeWatchedFiles = false } },
246+
settings = {
247+
lint = { unknownAtRules = 'ignore' },
248+
typescript = { enable = true, preferences = { importModuleSpecifier = 'non-relative' } },
249+
javascript = { enable = true, preferences = { importModuleSpecifier = 'non-relative' } },
242250
},
243251
},
244252
},
253+
-- This table contains config for all language servers that are *not* installed via Mason.
254+
-- Structure is identical to the mason table from above.
255+
others = {
256+
-- dartls = {},
257+
},
245258
}
246259

247260
-- Ensure the servers and tools above are installed
@@ -257,26 +270,38 @@ return {
257270
--
258271
-- You can add other tools here that you want Mason to install
259272
-- for you, so that they are available from within Neovim.
260-
local ensure_installed = vim.tbl_keys(servers or {})
273+
local ensure_installed = vim.tbl_keys(servers.mason or {})
261274
vim.list_extend(ensure_installed, {
262275
'stylua', -- Used to format Lua code
276+
'markdownlint',
277+
'lua-language-server',
278+
'svelte-language-server',
279+
'typescript-language-server',
280+
'eslint-lsp',
281+
'prettier',
282+
'gdtoolkit',
263283
})
264284
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
265285

286+
-- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
287+
-- to the default language server configs as provided by nvim-lspconfig or
288+
-- define a custom server config that's unavailable on nvim-lspconfig.
289+
for server, config in pairs(vim.tbl_extend('keep', servers.mason, servers.others)) do
290+
if not vim.tbl_isempty(config) then
291+
vim.lsp.config(server, config)
292+
end
293+
end
294+
295+
-- After configuring our language servers, we now enable them
266296
require('mason-lspconfig').setup {
267297
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
268-
automatic_installation = false,
269-
handlers = {
270-
function(server_name)
271-
local server = servers[server_name] or {}
272-
-- This handles overriding only values explicitly passed
273-
-- by the server configuration above. Useful when disabling
274-
-- certain features of an LSP (for example, turning off formatting for ts_ls)
275-
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
276-
require('lspconfig')[server_name].setup(server)
277-
end,
278-
},
298+
automatic_enable = true, -- automatically run vim.lsp.enable() for all servers that are installed via Mason
279299
}
300+
301+
-- Manually run vim.lsp.enable for all language servers that are *not* installed via Mason
302+
if not vim.tbl_isempty(servers.others) then
303+
vim.lsp.enable(vim.tbl_keys(servers.others))
304+
end
280305
end,
281306
},
282307
}

0 commit comments

Comments
 (0)