From de69eef601cb5a93c07ccd9cdbb5024f3f0b7a89 Mon Sep 17 00:00:00 2001 From: jint_lzxy_ <50296129+Jint-lzxy@users.noreply.github.com> Date: Sun, 19 Jan 2025 23:31:59 +0800 Subject: [PATCH] fix(lsp): only merge configs when absolutely needed (#1400) * Revert "fix: merge user customized config with predefined. (#1376)" This reverts commit 42ce15d3a408a45f2fef5aa24334703283245177. * fix(lsp): only merge configs when absolutely needed This commit is a follow-up fix for #1376 to delay merging user & default configs as much as we can to avoid extra overhead Signed-off-by: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> --------- Signed-off-by: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> --- .../configs/completion/mason-lspconfig.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lua/modules/configs/completion/mason-lspconfig.lua b/lua/modules/configs/completion/mason-lspconfig.lua index 4e8bb74d5..9e2b18803 100644 --- a/lua/modules/configs/completion/mason-lspconfig.lua +++ b/lua/modules/configs/completion/mason-lspconfig.lua @@ -52,26 +52,30 @@ please REMOVE your LSP configuration (rust_analyzer.lua) from the `servers` dire end local ok, custom_handler = pcall(require, "user.configs.lsp-servers." .. lsp_name) - local predefined_ok, predefined = pcall(require, "completion.servers." .. lsp_name) + local default_ok, default_handler = pcall(require, "completion.servers." .. lsp_name) -- Use preset if there is no user definition if not ok then - ok, custom_handler = predefined_ok, predefined - else - if type(custom_handler) == "table" and type(predefined) == "table" then - custom_handler = vim.tbl_deep_extend("force", predefined, custom_handler) - end + ok, custom_handler = default_ok, default_handler end if not ok then -- Default to use factory config for server(s) that doesn't include a spec nvim_lsp[lsp_name].setup(opts) + return elseif type(custom_handler) == "function" then --- Case where language server requires its own setup --- Make sure to call require("lspconfig")[lsp_name].setup() in the function --- See `clangd.lua` for example. custom_handler(opts) elseif type(custom_handler) == "table" then - nvim_lsp[lsp_name].setup(vim.tbl_deep_extend("force", opts, custom_handler)) + nvim_lsp[lsp_name].setup( + vim.tbl_deep_extend( + "force", + opts, + type(default_handler) == "table" and default_handler or {}, + custom_handler + ) + ) else vim.notify( string.format(