feat(lsp): added support for dynamic capabilities (#2594)

This commit is contained in:
Folke Lemaitre
2023-07-07 00:30:43 +02:00
committed by GitHub
parent 0e0600908d
commit 276362a802

View File

@@ -393,44 +393,38 @@ lsp.dynamic_workspace_symbols = function(opts)
:find() :find()
end end
local function check_capabilities(feature, bufnr) local function check_capabilities(method, bufnr)
local clients = vim.lsp.buf_get_clients(bufnr) local clients = vim.lsp.get_active_clients { bufnr = bufnr }
local supported_client = false
for _, client in pairs(clients) do for _, client in pairs(clients) do
supported_client = client.server_capabilities[feature] if client.supports_method(method, { bufnr = bufnr }) then
if supported_client then return true
break
end end
end end
if supported_client then if #clients == 0 then
return true utils.notify("builtin.lsp_*", {
msg = "no client attached",
level = "INFO",
})
else else
if #clients == 0 then utils.notify("builtin.lsp_*", {
utils.notify("builtin.lsp_*", { msg = "server does not support " .. method,
msg = "no client attached", level = "INFO",
level = "INFO", })
})
else
utils.notify("builtin.lsp_*", {
msg = "server does not support " .. feature,
level = "INFO",
})
end
return false
end end
return false
end end
local feature_map = { local feature_map = {
["document_symbols"] = "documentSymbolProvider", ["document_symbols"] = "textDocument/documentSymbol",
["references"] = "referencesProvider", ["references"] = "textDocument/references",
["definitions"] = "definitionProvider", ["definitions"] = "textDocument/definition",
["type_definitions"] = "typeDefinitionProvider", ["type_definitions"] = "textDocument/typeDefinition",
["implementations"] = "implementationProvider", ["implementations"] = "textDocument/implementation",
["workspace_symbols"] = "workspaceSymbolProvider", ["workspace_symbols"] = "workspace/symbol",
["incoming_calls"] = "callHierarchyProvider", ["incoming_calls"] = "callHierarchy/incomingCalls",
["outgoing_calls"] = "callHierarchyProvider", ["outgoing_calls"] = "callHierarchy/outgoingCalls",
} }
local function apply_checks(mod) local function apply_checks(mod)
@@ -438,8 +432,8 @@ local function apply_checks(mod)
mod[k] = function(opts) mod[k] = function(opts)
opts = opts or {} opts = opts or {}
local feature_name = feature_map[k] local method = feature_map[k]
if feature_name and not check_capabilities(feature_name, opts.bufnr) then if method and not check_capabilities(method, opts.bufnr) then
return return
end end
v(opts) v(opts)