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.
|
-- 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.
|
||||||
|
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.
|
--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
|
-- 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user