fix: lsp rename twice or more if multiple lsp's are active
This commit is contained in:
@@ -2,160 +2,170 @@
|
|||||||
-- NOTE: this adds a Language Server Provider for source files like C++, Java/-Script, etc.
|
-- NOTE: this adds a Language Server Provider for source files like C++, Java/-Script, etc.
|
||||||
-- It will check the code for errors, warnings, variables and structures and give suggestions.
|
-- It will check the code for errors, warnings, variables and structures and give suggestions.
|
||||||
return {
|
return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
version = "*",
|
version = "*",
|
||||||
config = function()
|
config = function()
|
||||||
-- local lspconfig = require("lspconfig")
|
-- local lspconfig = require("lspconfig")
|
||||||
|
|
||||||
vim.cmd([[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]])
|
vim.cmd([[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]])
|
||||||
vim.cmd([[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]])
|
vim.cmd([[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]])
|
||||||
|
|
||||||
-- Beautiful borders around LSP stuff like hover/signature_help
|
-- Beautiful borders around LSP stuff like hover/signature_help
|
||||||
local border = {
|
local border = {
|
||||||
{ "┌", "FloatBorder" },
|
{ "┌", "FloatBorder" },
|
||||||
{ "─", "FloatBorder" },
|
{ "─", "FloatBorder" },
|
||||||
{ "┐", "FloatBorder" },
|
{ "┐", "FloatBorder" },
|
||||||
{ "│", "FloatBorder" },
|
{ "│", "FloatBorder" },
|
||||||
{ "┘", "FloatBorder" },
|
{ "┘", "FloatBorder" },
|
||||||
{ "─", "FloatBorder" },
|
{ "─", "FloatBorder" },
|
||||||
{ "└", "FloatBorder" },
|
{ "└", "FloatBorder" },
|
||||||
{ "│", "FloatBorder" },
|
{ "│", "FloatBorder" },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 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++)" },
|
||||||
},
|
},
|
||||||
cmd = {
|
cmd = {
|
||||||
"clangd",
|
"clangd",
|
||||||
"--offset-encoding=utf-16",
|
"--offset-encoding=utf-16",
|
||||||
"--background-index",
|
"--background-index",
|
||||||
"--clang-tidy",
|
"--clang-tidy",
|
||||||
"--header-insertion=iwyu",
|
"--header-insertion=iwyu",
|
||||||
"--completion-style=detailed",
|
"--completion-style=detailed",
|
||||||
"--function-arg-placeholders",
|
"--function-arg-placeholders",
|
||||||
"-j4",
|
"-j4",
|
||||||
"--fallback-style=llvm",
|
"--fallback-style=llvm",
|
||||||
},
|
},
|
||||||
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto", "hpp", "h" },
|
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto", "hpp", "h" },
|
||||||
-- init_options = {
|
-- init_options = {
|
||||||
-- fallbackFlags = { '-std=c17' },
|
-- fallbackFlags = { '-std=c17' },
|
||||||
-- },
|
-- },
|
||||||
})
|
})
|
||||||
|
|
||||||
-- 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" },
|
||||||
})
|
})
|
||||||
|
|
||||||
-- diagnostics border
|
-- diagnostics border
|
||||||
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
|
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
|
||||||
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
||||||
-- I would love to retrieve the severity level just here in order to modify opts.border
|
-- I would love to retrieve the severity level just here in order to modify opts.border
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts.border = opts.border or border
|
opts.border = opts.border or border
|
||||||
return orig_util_open_floating_preview(contents, syntax, opts, ...)
|
return orig_util_open_floating_preview(contents, syntax, opts, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- adding filetypes to get glsl things
|
-- adding filetypes to get glsl things
|
||||||
vim.filetype.add({
|
vim.filetype.add({
|
||||||
extension = {
|
extension = {
|
||||||
vert = "glsl",
|
vert = "glsl",
|
||||||
tesc = "glsl",
|
tesc = "glsl",
|
||||||
tese = "glsl",
|
tese = "glsl",
|
||||||
frag = "glsl",
|
frag = "glsl",
|
||||||
geom = "glsl",
|
geom = "glsl",
|
||||||
comp = "glsl",
|
comp = "glsl",
|
||||||
vs = "glsl",
|
vs = "glsl",
|
||||||
fs = "glsl",
|
fs = "glsl",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- lspconfig.rust_analyzer.setup({
|
-- lspconfig.rust_analyzer.setup({
|
||||||
vim.lsp.config("rust_analyzer",{
|
vim.lsp.config("rust_analyzer", {
|
||||||
settings = {
|
settings = {
|
||||||
["rust-analyzer"] = {},
|
["rust-analyzer"] = {},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- These lsp keybinds only load when an LSP is attatched to the buffer.
|
-- These lsp keybinds only load when an LSP is attatched to the buffer.
|
||||||
vim.api.nvim_create_autocmd("LspAttach", {
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
-- Enable completion triggered by <c-x><c-o>
|
-- Enable completion triggered by <c-x><c-o>
|
||||||
vim.bo[event.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
vim.bo[event.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
||||||
|
|
||||||
local map = function(keys, func, desc)
|
local map = function(keys, func, desc)
|
||||||
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
|
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Jump to the definition of the word under your cursor.
|
-- Jump to the definition of the word under your cursor.
|
||||||
-- This is where a variable was first declared, or where a function is defined, etc.
|
-- This is where a variable was first declared, or where a function is defined, etc.
|
||||||
-- To jump back, press <C-t>.
|
-- To jump back, press <C-t>.
|
||||||
map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition")
|
map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition")
|
||||||
|
|
||||||
-- WARN: This is not Goto Definition, this is Goto Declaration.
|
-- WARN: This is not Goto Definition, this is Goto Declaration.
|
||||||
-- 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.
|
||||||
|
map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
|
||||||
|
|
||||||
-- Find references for the word under your cursor.
|
-- Jump to the implementation of the word under your cursor.
|
||||||
map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
|
-- Useful when your language has ways of declaring types without an actual implementation.
|
||||||
|
map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation")
|
||||||
|
|
||||||
-- Jump to the implementation of the word under your cursor.
|
-- Jump to the type of the word under your cursor.
|
||||||
-- Useful when your language has ways of declaring types without an actual implementation.
|
-- Useful when you're not sure what type a variable is and you want to see
|
||||||
map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation")
|
-- the definition of its *type*, not where it was *defined*.
|
||||||
|
map("<leader>ld", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition")
|
||||||
|
|
||||||
-- Jump to the type of the word under your cursor.
|
-- Jump to the type of the word under your cursor.
|
||||||
-- Useful when you're not sure what type a variable is and you want to see
|
-- Useful when you're not sure what type a variable is and you want to see
|
||||||
-- the definition of its *type*, not where it was *defined*.
|
-- the definition of its *type*, not where it was *defined*.
|
||||||
map("<leader>ld", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition")
|
map("<leader>lD", vim.lsp.buf.declaration, "Go to [D]eclaration")
|
||||||
|
|
||||||
-- Jump to the type of the word under your cursor.
|
-- Fuzzy find all the symbols in your current document.
|
||||||
-- Useful when you're not sure what type a variable is and you want to see
|
-- Symbols are things like variables, functions, types, etc.
|
||||||
-- the definition of its *type*, not where it was *defined*.
|
map("<leader>ls", require("telescope.builtin").lsp_document_symbols, "document [S]ymbols")
|
||||||
map("<leader>lD", vim.lsp.buf.declaration, "Go to [D]eclaration")
|
|
||||||
|
|
||||||
-- Fuzzy find all the symbols in your current document.
|
-- Format file
|
||||||
-- Symbols are things like variables, functions, types, etc.
|
map("<leader>lf", vim.lsp.buf.format, "[F]ormat")
|
||||||
map("<leader>ls", require("telescope.builtin").lsp_document_symbols, "document [S]ymbols")
|
|
||||||
|
|
||||||
-- Format file
|
-- Fuzzy find all the symbols in your current workspace.
|
||||||
map("<leader>lf", vim.lsp.buf.format, "[F]ormat")
|
-- 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>li", vim.cmd.LspInfo, "Show lsp info")
|
||||||
|
map("<leader>lp", vim.diagnostic.goto_prev, "Go to [P]revious diagnostic message")
|
||||||
|
|
||||||
-- Fuzzy find all the symbols in your current workspace.
|
map("<leader>ln", vim.diagnostic.goto_next, "Go to [N]ext diagnostic message")
|
||||||
-- 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>li", vim.cmd.LspInfo, "Show lsp info")
|
|
||||||
map("<leader>lp", vim.diagnostic.goto_prev, "Go to [P]revious diagnostic message")
|
|
||||||
|
|
||||||
map("<leader>ln", vim.diagnostic.goto_next, "Go to [N]ext diagnostic message")
|
map("<leader>le", vim.diagnostic.open_float, "Show diagnostic [E]rror messages")
|
||||||
|
vim.diagnostic.config({ virtual_text = false })
|
||||||
|
|
||||||
map("<leader>le", vim.diagnostic.open_float, "Show diagnostic [E]rror messages")
|
map("<leader>lq", vim.diagnostic.setloclist, "Open diagnostic [Q]uickfix list")
|
||||||
vim.diagnostic.config({ virtual_text = false })
|
|
||||||
|
|
||||||
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", rename, "[R]ename")
|
||||||
|
|
||||||
-- Rename the variable under your cursor.
|
-- Execute a code action, usually your cursor needs to be on top of an error
|
||||||
-- Most Language Servers support renaming across files, etc.
|
-- or a suggestion from your LSP for this to activate.
|
||||||
map("<leader>lr", vim.lsp.buf.rename, "[R]ename")
|
map("<leader>la", vim.lsp.buf.code_action, "code [A]ction")
|
||||||
|
|
||||||
-- Execute a code action, usually your cursor needs to be on top of an error
|
-- Opens a popup that displays documentation about the word under your cursor
|
||||||
-- or a suggestion from your LSP for this to activate.
|
-- See `:help K` for why this keymap.
|
||||||
map("<leader>la", vim.lsp.buf.code_action, "code [A]ction")
|
|
||||||
|
|
||||||
-- Opens a popup that displays documentation about the word under your cursor
|
map("<leader>th", function()
|
||||||
-- See `:help K` for why this keymap.
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
|
||||||
|
end, "[T]oggle Inlay [H]ints")
|
||||||
map("<leader>th", function()
|
end,
|
||||||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
|
})
|
||||||
end, "[T]oggle Inlay [H]ints")
|
end,
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user