mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-20 18:45:08 +02:00
fix(lsp): prevent repeated setup call (#2048)
Check if the manager `autocomd` has already been configured, since some servers can take a while to initialize.
This commit is contained in:
parent
6505826f0b
commit
e4752692e5
1 changed files with 16 additions and 1 deletions
|
@ -45,13 +45,28 @@ local function buf_try_add(server_name, bufnr)
|
|||
require("lspconfig")[server_name].manager.try_add_wrapper(bufnr)
|
||||
end
|
||||
|
||||
-- check if the manager autocomd has already been configured since some servers can take a while to initialize
|
||||
-- this helps guarding against a data-race condition where a server can get configured twice
|
||||
-- which seems to occur only when attaching to single-files
|
||||
local function client_is_configured(server_name, ft)
|
||||
ft = ft or vim.bo.filetype
|
||||
local active_autocmds = vim.split(vim.fn.execute("autocmd FileType " .. ft), "\n")
|
||||
for _, result in ipairs(active_autocmds) do
|
||||
if result:match(server_name) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---Setup a language server by providing a name
|
||||
---@param server_name string name of the language server
|
||||
---@param user_config table [optional] when available it will take predence over any default configurations
|
||||
function M.setup(server_name, user_config)
|
||||
vim.validate { name = { server_name, "string" } }
|
||||
|
||||
if lvim_lsp_utils.is_client_active(server_name) then
|
||||
if lvim_lsp_utils.is_client_active(server_name) or client_is_configured(server_name) then
|
||||
Log:debug(string.format("[%q] is already configured. Ignoring repeated setup call.", server_name))
|
||||
return
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue