Skip to content

Commit cacaa62

Browse files
committed
fix(nvim): lspconfig doesn't detect custom command nvim-lua/kickstart.nvim#1590
1 parent a8a933e commit cacaa62

File tree

1 file changed

+82
-54
lines changed

1 file changed

+82
-54
lines changed

nvim/.config/nvim/lua/plugins/lang.lua

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -194,55 +194,78 @@ return {
194194
-- By default, Neovim doesn't support everything that is in the LSP specification.
195195
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
196196
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
197-
local capabilities = require('blink.cmp').get_lsp_capabilities()
198-
199-
-- Enable the following language servers
200-
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
197+
-- NOTE: The following line is now commented as blink.cmp extends capabilites by default from its internal code:
198+
-- https://github.com/Saghen/blink.cmp/blob/102db2f5996a46818661845cf283484870b60450/plugin/blink-cmp.lua
199+
-- It has been left here as a comment for educational purposes (as the predecessor completion plugin required this explicit step).
201200
--
202-
-- Add any additional override configuration in the following tables. Available keys are:
203-
-- - cmd (table): Override the default command used to start the server
204-
-- - filetypes (table): Override the default list of associated filetypes for the server
205-
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
206-
-- - settings (table): Override the default settings passed when initializing the server.
207-
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
201+
-- local capabilities = require("blink.cmp").get_lsp_capabilities()
202+
203+
-- Language servers can broadly be installed in the following ways:
204+
-- 1) via the mason package manager; or
205+
-- 2) via your system's package manager; or
206+
-- 3) via a release binary from a language server's repo that's accessible somewhere on your system.
207+
208+
-- The servers table comprises of the following sub-tables:
209+
-- 1. mason
210+
-- 2. others
211+
-- Both these tables have an identical structure of language server names as keys and
212+
-- a table of language server configuration as values.
213+
---@class LspServersConfig
214+
---@field mason table<string, vim.lsp.Config>
215+
---@field others table<string, vim.lsp.Config>
208216
local servers = {
209-
-- NOTE: Language Support
210-
-- Step 1: Install the LSP
211-
clangd = {},
212-
-- gopls = {},
213-
pyright = {},
214-
rust_analyzer = {},
215-
bashls = {
216-
settings = {
217-
filetypes = { 'sh', 'zsh' },
218-
},
219-
},
220-
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
221-
--
222-
-- Some languages (like typescript) have entire language plugins that can be useful:
223-
-- https://github.com/pmizio/typescript-tools.nvim
217+
-- Add any additional override configuration in any of the following tables. Available keys are:
218+
-- - cmd (table): Override the default command used to start the server
219+
-- - filetypes (table): Override the default list of associated filetypes for the server
220+
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
221+
-- - settings (table): Override the default settings passed when initializing the server.
222+
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
224223
--
225-
-- But for many setups, the LSP (`ts_ls`) will work just fine
226-
ts_ls = {},
227-
--
228-
html = {},
229-
cssls = {},
230-
marksman = {},
231-
232-
lua_ls = {
233-
-- cmd = {...},
234-
-- filetypes = { ...},
235-
-- capabilities = {},
236-
settings = {
237-
Lua = {
238-
completion = {
239-
callSnippet = 'Replace',
224+
-- Feel free to add/remove any LSPs here that you want to install via Mason. They will automatically be installed and setup.
225+
mason = {
226+
-- NOTE: Language Support
227+
-- Step 1: Install the LSP
228+
clangd = {},
229+
-- gopls = {},
230+
pyright = {},
231+
rust_analyzer = {},
232+
bashls = {
233+
settings = {
234+
filetypes = { 'sh', 'zsh' },
235+
},
236+
},
237+
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
238+
--
239+
-- Some languages (like typescript) have entire language plugins that can be useful:
240+
-- https://github.com/pmizio/typescript-tools.nvim
241+
--
242+
-- But for many setups, the LSP (`ts_ls`) will work just fine
243+
ts_ls = {},
244+
--
245+
html = {},
246+
cssls = {},
247+
marksman = {},
248+
249+
lua_ls = {
250+
-- cmd = {...},
251+
-- filetypes = { ...},
252+
-- capabilities = {},
253+
settings = {
254+
Lua = {
255+
completion = {
256+
callSnippet = 'Replace',
257+
},
258+
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
259+
-- diagnostics = { disable = { 'missing-fields' } },
240260
},
241-
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
242-
-- diagnostics = { disable = { 'missing-fields' } },
243261
},
244262
},
245263
},
264+
-- This table contains config for all language servers that are *not* installed via Mason.
265+
-- Structure is identical to the mason table from above.
266+
others = {
267+
-- dartls = {},
268+
},
246269
}
247270

248271
-- Ensure the servers and tools above are installed
@@ -258,7 +281,7 @@ return {
258281
--
259282
-- You can add other tools here that you want Mason to install
260283
-- for you, so that they are available from within Neovim.
261-
local ensure_installed = vim.tbl_keys(servers or {})
284+
local ensure_installed = vim.tbl_keys(servers.mason or {})
262285
vim.list_extend(ensure_installed, {
263286
-- NOTE: Language Support
264287
-- Step 2: Install the formatter
@@ -270,20 +293,25 @@ return {
270293
})
271294
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
272295

296+
-- Either merge all additional server configs from the `servers.mason` and `servers.others` tables
297+
-- to the default language server configs as provided by nvim-lspconfig or
298+
-- define a custom server config that's unavailable on nvim-lspconfig.
299+
for server, config in pairs(vim.tbl_extend('keep', servers.mason, servers.others)) do
300+
if not vim.tbl_isempty(config) then
301+
vim.lsp.config(server, config)
302+
end
303+
end
304+
305+
-- After configuring our language servers, we now enable them
273306
require('mason-lspconfig').setup {
274307
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
275-
automatic_installation = false,
276-
handlers = {
277-
function(server_name)
278-
local server = servers[server_name] or {}
279-
-- This handles overriding only values explicitly passed
280-
-- by the server configuration above. Useful when disabling
281-
-- certain features of an LSP (for example, turning off formatting for ts_ls)
282-
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
283-
require('lspconfig')[server_name].setup(server)
284-
end,
285-
},
308+
automatic_enable = true, -- automatically run vim.lsp.enable() for all servers that are installed via Mason
286309
}
310+
311+
-- Manually run vim.lsp.enable for all language servers that are *not* installed via Mason
312+
if not vim.tbl_isempty(servers.others) then
313+
vim.lsp.enable(vim.tbl_keys(servers.others))
314+
end
287315
end,
288316
},
289317

0 commit comments

Comments
 (0)