mirror of
https://github.com/pnx/dotfiles
synced 2026-06-18 20:10:03 +02:00
nvim: lsp: add support for lsp functionalites.
This commit is contained in:
parent
313dcd0720
commit
8c0feb8acc
2 changed files with 32 additions and 4 deletions
|
|
@ -42,22 +42,41 @@ return {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
},
|
},
|
||||||
codelens = {
|
codelens = {
|
||||||
enabled = false,
|
enabled = true,
|
||||||
},
|
},
|
||||||
inlay_hints = {
|
inlay_hints = {
|
||||||
enabled = false,
|
enabled = true,
|
||||||
exclude = {},
|
exclude = {},
|
||||||
},
|
},
|
||||||
servers = {},
|
servers = {},
|
||||||
},
|
},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
local lspconfig = require("lspconfig")
|
local lspconfig = require("lspconfig")
|
||||||
|
local utils = require("user.utils.lsp")
|
||||||
local augroup = vim.api.nvim_create_augroup("Lsp", {})
|
local augroup = vim.api.nvim_create_augroup("Lsp", {})
|
||||||
|
local has_cmp, cmp_lsp = pcall(require, "cmp_nvim_lsp")
|
||||||
|
local capabilities = vim.tbl_deep_extend('force',
|
||||||
|
vim.lsp.protocol.make_client_capabilities() or {},
|
||||||
|
has_cmp and cmp_lsp.default_capabilities() or {})
|
||||||
|
|
||||||
for name, server_opts in pairs(opts.servers) do
|
for name, server_opts in pairs(opts.servers) do
|
||||||
local on_attach = function(_, bufnr)
|
---@param client vim.lsp.Client
|
||||||
|
---@param bufnr number
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||||
|
|
||||||
|
if (opts.inlay_hints.enabled or false) and client.server_capabilities.inlayHintProvider then
|
||||||
|
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
|
||||||
|
end
|
||||||
|
|
||||||
|
if opts.codelens.enabled and client.server_capabilities.codeLensProvider then
|
||||||
|
utils.codelens(augroup, bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
if opts.document_highlight.enabled and client.server_capabilities.documentHighlightProvider then
|
||||||
|
utils.document_highlight(bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
-- Setup on save handler
|
-- Setup on save handler
|
||||||
if server_opts.on_save then
|
if server_opts.on_save then
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
|
@ -69,7 +88,8 @@ return {
|
||||||
end
|
end
|
||||||
|
|
||||||
server_opts = vim.tbl_deep_extend("force", {
|
server_opts = vim.tbl_deep_extend("force", {
|
||||||
on_attach = on_attach
|
on_attach = on_attach,
|
||||||
|
capabilities = capabilities
|
||||||
}, server_opts or {})
|
}, server_opts or {})
|
||||||
|
|
||||||
lspconfig[name].setup(server_opts)
|
lspconfig[name].setup(server_opts)
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,12 @@ function M.signature_help_on_hover(bufnr)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.codelens(augroup, bufnr)
|
||||||
|
vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, {
|
||||||
|
group = augroup,
|
||||||
|
buffer = bufnr,
|
||||||
|
callback = vim.lsp.codelens.refresh,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue