fix: lsp rename twice or more if multiple lsp's are active
This commit is contained in:
@@ -99,7 +99,6 @@ return {
|
||||
-- For example, in C this would take you to the header.
|
||||
map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
|
||||
|
||||
|
||||
-- Find references for the word under your cursor.
|
||||
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.
|
||||
-- Similar to document symbols, except searches over your entire project.
|
||||
map(
|
||||
"<leader>lw",
|
||||
require("telescope.builtin").lsp_dynamic_workspace_symbols,
|
||||
"[W]orkspace symbols"
|
||||
)
|
||||
map("<leader>lw", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace symbols")
|
||||
map("<leader>li", vim.cmd.LspInfo, "Show lsp info")
|
||||
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")
|
||||
|
||||
-- Rename the variable under your cursor.
|
||||
local function rename()
|
||||
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", vim.lsp.buf.rename, "[R]ename")
|
||||
map("<leader>lr", rename, "[R]ename")
|
||||
|
||||
-- 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.
|
||||
|
||||
Reference in New Issue
Block a user