dotfiles/config/nvim/lua/fschauen/plugins/lspconfig.lua

76 lines
2.8 KiB
Lua

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",
dependencies = {
"Hoffs/omnisharp-extended-lsp.nvim",
},
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
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 = lsp_on_attach })
end,
}