dotfiles/config/nvim/lua/fschauen/plugins/lspconfig.lua
Fernando Schauenburg 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

70 lines
2.8 KiB
Lua

return {
"neovim/nvim-lspconfig",
dependencies = {
"Hoffs/omnisharp-extended-lsp.nvim",
},
event = { "BufReadPre", "BufNewFile" },
config = function()
local capabilities = (function()
local cmp_nvim_lsp = vim.F.npcall(require, "cmp_nvim_lsp")
if cmp_nvim_lsp then
return cmp_nvim_lsp.default_capabilities()
else
return vim.lsp.protocol.make_client_capabilities()
end
end)()
vim.lsp.config("*", { capabilities = capabilities })
vim.lsp.enable("clangd")
vim.lsp.enable("cmake")
vim.lsp.enable("lua_ls")
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
-- Patch some built-in LSP functions so they use custom borders.
(function(names)
for _, name in ipairs(names) do
local builtin = vim.lsp.buf[name]
vim.lsp.buf[name] = function(opts)
builtin(vim.tbl_deep_extend("force", opts or {}, { border = "rounded" }))
end
end
end) {
"signature_help",
"hover",
}
-- 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", vim.lsp.buf.signature_help, { buffer = 0 } )
vim.keymap.set("i", "<c-s>", vim.lsp.buf.signature_help, { buffer = 0 } )
vim.keymap.set("n", "K", 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,
})
end,
}