nvim: refactor LSP config
This commit is contained in:
parent
6a43247c4c
commit
2f2ac372f4
1 changed files with 47 additions and 41 deletions
|
@ -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)
|
||||||
|
map_local("n", "<localleader>c", vim.lsp.buf.code_action)
|
||||||
|
map_local("n", "<localleader>f", vim.lsp.buf.format)
|
||||||
|
map_local("n", "gd", vim.lsp.buf.definition)
|
||||||
|
map_local("n", "gD", vim.lsp.buf.declaration)
|
||||||
|
map_local("n", "gi", vim.lsp.buf.implementation)
|
||||||
|
map_local("n", "grr", vim.lsp.buf.rename)
|
||||||
|
map_local("n", "gt", vim.lsp.buf.type_definition)
|
||||||
|
map_local("n", "gs", vim.lsp.buf.signature_help)
|
||||||
|
map_local("i", "<c-s>", vim.lsp.buf.signature_help)
|
||||||
|
map_local("n", "K", vim.lsp.buf.hover)
|
||||||
|
-- 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 {
|
return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
|
|
||||||
|
@ -8,6 +52,8 @@ return {
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
event = { "BufReadPre", "BufNewFile" },
|
||||||
|
|
||||||
config = function()
|
config = function()
|
||||||
|
make_lsp_builtins_use_rounded_border()
|
||||||
|
|
||||||
local capabilities = (function()
|
local capabilities = (function()
|
||||||
local cmp_nvim_lsp = vim.F.npcall(require, "cmp_nvim_lsp")
|
local cmp_nvim_lsp = vim.F.npcall(require, "cmp_nvim_lsp")
|
||||||
if cmp_nvim_lsp then
|
if cmp_nvim_lsp then
|
||||||
|
@ -25,46 +71,6 @@ return {
|
||||||
vim.lsp.enable("omnisharp")
|
vim.lsp.enable("omnisharp")
|
||||||
vim.lsp.enable("pyright")
|
vim.lsp.enable("pyright")
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("LspAttach", {
|
vim.api.nvim_create_autocmd("LspAttach", { callback = lsp_on_attach })
|
||||||
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,
|
end,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue