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:
parent
777113d90f
commit
435b33ac3a
1 changed files with 43 additions and 17 deletions
|
|
@ -54,7 +54,13 @@ return {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
--- @class LSPServerOptions : LSPFeatures
|
||||||
|
--- @field on_save function | nil
|
||||||
|
|
||||||
|
--- @class LSPOptions
|
||||||
opts = {
|
opts = {
|
||||||
|
--- @class LSPFeatures
|
||||||
|
features = {
|
||||||
document_highlight = {
|
document_highlight = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
},
|
},
|
||||||
|
|
@ -65,8 +71,14 @@ return {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
exclude = {},
|
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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue