1
0
Fork 0
mirror of https://github.com/pnx/dotfiles synced 2026-07-02 14:33:40 +02:00

nvim: lsp: add options to disable some LSP features globally and per server.

This commit is contained in:
Henrik Hautakoski 2024-11-03 13:46:54 +01:00
parent 777113d90f
commit 435b33ac3a

View file

@ -54,19 +54,31 @@ return {
} }
} }
}, },
--- @class LSPServerOptions : LSPFeatures
--- @field on_save function | nil
--- @class LSPOptions
opts = { opts = {
document_highlight = { --- @class LSPFeatures
enabled = true, features = {
}, document_highlight = {
codelens = { enabled = true,
enabled = false, },
}, codelens = {
inlay_hints = { enabled = false,
enabled = true, },
exclude = {}, inlay_hints = {
enabled = true,
exclude = {},
},
diagnostics = true,
hover = true,
definition = true,
}, },
--- @type { string: LSPServerOptions }
servers = {}, servers = {},
}, },
--- @param opts LSPOptions
config = function(_, opts) config = function(_, opts)
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
local utils = require("user.utils.lsp") local utils = require("user.utils.lsp")
@ -76,33 +88,47 @@ return {
vim.lsp.protocol.make_client_capabilities() or {}, vim.lsp.protocol.make_client_capabilities() or {},
has_cmp and cmp_lsp.default_capabilities() or {}) has_cmp and cmp_lsp.default_capabilities() or {})
--- @param server string
local function setup(server) local function setup(server)
local server_opts = opts.servers[server] or {} local server_opts = opts.servers[server] or {}
if type(server_opts) == "function" then if type(server_opts) == "function" then
server_opts = server_opts() server_opts = server_opts()
end end
local features = vim.tbl_deep_extend("force", { -- Set missing features to default ones in server options.
codelens = opts.codelens, server_opts = vim.tbl_deep_extend("keep", server_opts, opts.features)
inlay_hints = opts.inlay_hints,
document_highlight = opts.document_highlight
}, server_opts)
---@param client vim.lsp.Client ---@param client vim.lsp.Client
---@param bufnr number ---@param bufnr number
local on_attach = function(client, bufnr) 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 features.inlay_hints.enabled and client.supports_method("textDocument/inlayHint") then -- disable diagnostics
if server_opts.diagnostics == false then
client.server_capabilities.diagnosticProvider = false
vim.print(client.server_capabilities.diagnosticProvider)
end
-- disable hover
if server_opts.hover == false then
client.server_capabilities.hoverProvider = false
end
if server_opts.definition == false then
client.server_capabilities.definitionProvider = false
end
if server_opts.inlay_hints.enabled and client.supports_method("textDocument/inlayHint") then
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
end end
if features.codelens.enabled and client.supports_method("textDocument/codeLens") then if server_opts.codelens.enabled and client.supports_method("textDocument/codeLens") then
utils.codelens(augroup, bufnr) utils.codelens(augroup, bufnr)
end end
if features.document_highlight.enabled and client.supports_method("textDocument/documentHighlight") then if server_opts.document_highlight.enabled and client.supports_method("textDocument/documentHighlight") then
utils.document_highlight(bufnr) utils.document_highlight(bufnr)
end end