fix: lsp rename twice or more if multiple lsp's are active

This commit is contained in:
Ward Truyen
2026-04-20 21:13:57 +02:00
parent 1ee9a1932c
commit d7d2adcf13

View File

@@ -23,7 +23,7 @@ return {
} }
-- lspconfig.clangd.setup({ -- lspconfig.clangd.setup({
vim.lsp.config("clangd",{ vim.lsp.config("clangd", {
keys = { keys = {
{ "<leader>pc", "<cmd>ClangdSwitchSourceHeader<cr>", desc = "Switch Source/Header (C/C++)" }, { "<leader>pc", "<cmd>ClangdSwitchSourceHeader<cr>", desc = "Switch Source/Header (C/C++)" },
}, },
@@ -45,7 +45,7 @@ return {
}) })
-- lspconfig.glsl_analyzer.setup({ -- lspconfig.glsl_analyzer.setup({
vim.lsp.config("glsl_analyzer",{ vim.lsp.config("glsl_analyzer", {
filetypes = { "glsl", "vert", "tese", "frag", "geom", "comp", "vs", "fs" }, filetypes = { "glsl", "vert", "tese", "frag", "geom", "comp", "vs", "fs" },
}) })
@@ -73,7 +73,7 @@ return {
}) })
-- lspconfig.rust_analyzer.setup({ -- lspconfig.rust_analyzer.setup({
vim.lsp.config("rust_analyzer",{ vim.lsp.config("rust_analyzer", {
settings = { settings = {
["rust-analyzer"] = {}, ["rust-analyzer"] = {},
}, },
@@ -99,7 +99,6 @@ return {
-- For example, in C this would take you to the header. -- For example, in C this would take you to the header.
map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
-- Find references for the word under your cursor. -- Find references for the word under your cursor.
map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
@@ -126,11 +125,7 @@ return {
-- Fuzzy find all the symbols in your current workspace. -- Fuzzy find all the symbols in your current workspace.
-- Similar to document symbols, except searches over your entire project. -- Similar to document symbols, except searches over your entire project.
map( map("<leader>lw", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace symbols")
"<leader>lw",
require("telescope.builtin").lsp_dynamic_workspace_symbols,
"[W]orkspace symbols"
)
map("<leader>li", vim.cmd.LspInfo, "Show lsp info") map("<leader>li", vim.cmd.LspInfo, "Show lsp info")
map("<leader>lp", vim.diagnostic.goto_prev, "Go to [P]revious diagnostic message") map("<leader>lp", vim.diagnostic.goto_prev, "Go to [P]revious diagnostic message")
@@ -142,8 +137,23 @@ return {
map("<leader>lq", vim.diagnostic.setloclist, "Open diagnostic [Q]uickfix list") map("<leader>lq", vim.diagnostic.setloclist, "Open diagnostic [Q]uickfix list")
-- Rename the variable under your cursor. -- Rename the variable under your cursor.
-- Most Language Servers support renaming across files, etc. local function rename()
map("<leader>lr", vim.lsp.buf.rename, "[R]ename") local clients = vim.lsp.get_clients({ bufnr = 0, method = "textDocument/rename" })
if #clients > 0 then
local targetClient = clients[1] -- Use the first client .. or angularls if available
for _, client in ipairs(clients) do
if client.name == "angularls" then
targetClient = client
break
end
end
vim.lsp.buf.rename(nil, { name = targetClient.name })
else
print("No LSP attached supports renaming")
end
end
--Most Language Servers support renaming across files, etc.
map("<leader>lr", rename, "[R]ename")
-- Execute a code action, usually your cursor needs to be on top of an error -- Execute a code action, usually your cursor needs to be on top of an error
-- or a suggestion from your LSP for this to activate. -- or a suggestion from your LSP for this to activate.