Compare commits

...

3 commits

Author SHA1 Message Date
264a7f1210 nvim: add descriptions to LSP key bindings 2025-06-27 19:41:50 +02:00
2f2ac372f4 nvim: refactor LSP config 2025-06-27 19:41:50 +02:00
6a43247c4c nvim: patch built-in LSP functions instead of wrapping them
This causes the behavior to be what I expect anytime I call one of these
functions globally.
2025-06-27 19:41:50 +02:00

View file

@ -1,3 +1,47 @@
local toggle_inlay_hints = function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end
local map_local = function(mode, lhs, rhs, opts)
opts = vim.tbl_deep_extend("force", opts or {}, { buffer = 0 })
vim.keymap.set(mode, lhs, rhs, opts)
end
local lsp_on_attach = function(args)
-- stylua: ignore start
map_local("n", "<leader>sh", toggle_inlay_hints, { desc = "LSP: toggle inlay hints" } )
map_local("n", "<localleader>c", vim.lsp.buf.code_action, { desc = "LSP: code action" } )
map_local("n", "<localleader>f", vim.lsp.buf.format, { desc = "LSP: format" } )
map_local("n", "gd", vim.lsp.buf.definition, { desc = "LSP: go to definition" } )
map_local("n", "gD", vim.lsp.buf.declaration, { desc = "LSP: go to declaration" } )
map_local("n", "gi", vim.lsp.buf.implementation, { desc = "LSP: go to implementation" } )
map_local("n", "grr", vim.lsp.buf.rename, { desc = "LSP: rename" } )
map_local("n", "gt", vim.lsp.buf.type_definition, { desc = "LSP: go to type definition" } )
map_local("n", "gs", vim.lsp.buf.signature_help, { desc = "LSP: show signature help" } )
map_local("i", "<c-s>", vim.lsp.buf.signature_help, { desc = "LSP: show signature help" } )
map_local("n", "K", vim.lsp.buf.hover, { desc = "LSP: display hover information" } )
-- stylua: ignore end
-- Opt out of semantic highlighting because it has been causing issues
-- https://github.com/neovim/nvim-lspconfig/issues/2542#issuecomment-1547019213
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client and client.server_capabilities then
client.server_capabilities.semanticTokensProvider = nil
end
end
local make_lsp_builtins_use_rounded_border = function()
local patch = function(name)
local builtin = vim.lsp.buf[name]
vim.lsp.buf[name] = function(opts)
builtin(vim.tbl_deep_extend("force", opts or {}, { border = "rounded" }))
end
end
patch("signature_help")
patch("hover")
end
return {
"neovim/nvim-lspconfig",
@ -8,6 +52,8 @@ return {
event = { "BufReadPre", "BufNewFile" },
config = function()
make_lsp_builtins_use_rounded_border()
local capabilities = (function()
local cmp_nvim_lsp = vim.F.npcall(require, "cmp_nvim_lsp")
if cmp_nvim_lsp then
@ -25,37 +71,6 @@ return {
vim.lsp.enable("omnisharp")
vim.lsp.enable("pyright")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local toggle_inlay_hints = function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end
local rounded = function(action)
return function() action { border = "rounded" } end
end
-- stylua: ignore start
vim.keymap.set("n", "<leader>sh", toggle_inlay_hints, { buffer = 0 })
vim.keymap.set("n", "<localleader>c", vim.lsp.buf.code_action, { buffer = 0 } )
vim.keymap.set("n", "<localleader>f", vim.lsp.buf.format, { buffer = 0 } )
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = 0 } )
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { buffer = 0 } )
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { buffer = 0 } )
vim.keymap.set("n", "grr", vim.lsp.buf.rename, { buffer = 0 } )
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, { buffer = 0 } )
vim.keymap.set("n", "gs", rounded(vim.lsp.buf.signature_help), { buffer = 0 } )
vim.keymap.set("i", "<c-s>", rounded(vim.lsp.buf.signature_help), { buffer = 0 } )
vim.keymap.set("n", "K", rounded(vim.lsp.buf.hover), { buffer = 0 } )
-- stylua: ignore end
-- Opt out of semantic highlighting because it has been causing issues
-- https://github.com/neovim/nvim-lspconfig/issues/2542#issuecomment-1547019213
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client and client.server_capabilities then
client.server_capabilities.semanticTokensProvider = nil
end
end,
})
vim.api.nvim_create_autocmd("LspAttach", { callback = lsp_on_attach })
end,
}