-
Notifications
You must be signed in to change notification settings - Fork 40.3k
fix(lsp): updated config for mason to v2 #1663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -700,6 +700,15 @@ require('lazy').setup({ | |
}, | ||
} | ||
|
||
-- The following loop will configure each server with the capabilities we defined above. | ||
-- This will ensure that all servers have the same base configuration, but also | ||
-- allow for server-specific overrides. | ||
for server_name, server_config in pairs(servers) do | ||
server_config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server_config.capabilities or {}) | ||
vim.lsp.config(server_name, server_config) | ||
vim.lsp.enable(server_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I added this line to my config, it brought up every LSP I had installed without regard to if it's needed. Another approach is necessary. Using ftplugin or something else, maybe autocommands, something needs to trigger vim.lsp.enable for the appropriate LSP's only, at the appropriate time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That simply isn't true, at least not with regards to "this line".
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, maybe I've made a mistake somewhere in my config which is almost identical in this part. Sorry for the comment and thanks for prompting me. EDIT: actually I have bashls with config = {} , I have luals with filetypes={'lua'} and it enables both of them without me even opening a buffer, so what you say cannot be true because I don't enable them anywhere and when I comment this line, nothing is brought up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of these claims is covered by tests, the other is a vague description that I can only guess at. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you even checked LspInfo when you fire up Neovim without opening any file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After some more research I can say the above statement is misinformed:
Nowhere here it is said anything about auto commands. You need to set the auto commands yourself and they need to enable the LSP (call vim.lsp.enable) in case a buffer with a configured file type is opened. We don't want LSP's loaded for no reason. They need to be only loaded when they are needed. Auto commands can be set right there instead of that line. However since nvim-lspconfig should go as well, this should not be done in its config function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --- @param name string|string[] Name(s) of client(s) to enable.
--- @param enable? boolean `true|nil` to enable, `false` to disable (actively stops and detaches
--- clients as needed)
function lsp.enable(name, enable)
validate('name', name, { 'string', 'table' })
local names = vim._ensure_list(name) --[[@as string[] ]]
for _, nm in ipairs(names) do
if nm == '*' then
error('Invalid name')
end
lsp._enabled_configs[nm] = enable ~= false and {} or nil
end
if not next(lsp._enabled_configs) then
-- If there are no remaining LSPs enabled, remove the enable autocmd.
if lsp_enable_autocmd_id then
api.nvim_del_autocmd(lsp_enable_autocmd_id)
lsp_enable_autocmd_id = nil
end
else
-- Only ever create autocmd once to reuse computation of config merging.
lsp_enable_autocmd_id = lsp_enable_autocmd_id
or api.nvim_create_autocmd('FileType', {
group = api.nvim_create_augroup('nvim.lsp.enable', {}),
callback = function(args)
lsp_enable_callback(args.buf)
end,
})
end
-- Ensure any pre-existing buffers start/stop their LSP clients.
if enable ~= false then
if vim.v.vim_did_enter == 1 then
vim.cmd.doautoall('nvim.lsp.enable FileType')
end
else
for _, nm in ipairs(names) do
for _, client in ipairs(lsp.get_clients({ name = nm })) do
client:stop()
end
end
end
end You can read the source code yourself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You both seem to be unable to comprehend what I'm talking about. One doesn't need the LSP's to be enabled when they are not needed and vim.lsp.enable here does exactly that. Did any of you run :LspInfo or :healthcheck vim.lsp on a blank buffer in a freshly started Neovim? You should not see anything there and yet, there's a list of enabled configurations. However many times you may read the code, that's the result. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existing code suffices. The editor auto enables LSPs for the filetypes a user is concerned with. Enabled only means that the autocmd is set up, and the lsp process will spawn only when the filetype is detected, no other overhead. If you do not want or need an LSP, then remove its configuration. It should be fine for the vast majority of use cases, except "maybe" for those that have configs for LSPs counting far into the double digits, at which point it becomes a personal problem. If you still want to overengineer this though, you can hijack There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This one I didn't need to read twice. Thank you for the explanation. Actually I had already started doubting my understanding and your explanation just confirmed my doubts. Thank you!
If I understand that properly, it means the |
||
end | ||
|
||
-- Ensure the servers and tools above are installed | ||
-- | ||
-- To check the current status of installed tools and/or manually install | ||
|
@@ -718,21 +727,6 @@ require('lazy').setup({ | |
'stylua', -- Used to format Lua code | ||
}) | ||
require('mason-tool-installer').setup { ensure_installed = ensure_installed } | ||
|
||
require('mason-lspconfig').setup { | ||
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) | ||
automatic_installation = false, | ||
handlers = { | ||
function(server_name) | ||
local server = servers[server_name] or {} | ||
-- This handles overriding only values explicitly passed | ||
-- by the server configuration above. Useful when disabling | ||
-- certain features of an LSP (for example, turning off formatting for ts_ls) | ||
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) | ||
require('lspconfig')[server_name].setup(server) | ||
end, | ||
}, | ||
} | ||
end, | ||
}, | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.