feat(lsp): added support for dynamic capabilities (#2594)
This commit is contained in:
@@ -393,20 +393,15 @@ 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
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
if #clients == 0 then
|
if #clients == 0 then
|
||||||
utils.notify("builtin.lsp_*", {
|
utils.notify("builtin.lsp_*", {
|
||||||
msg = "no client attached",
|
msg = "no client attached",
|
||||||
@@ -414,23 +409,22 @@ local function check_capabilities(feature, bufnr)
|
|||||||
})
|
})
|
||||||
else
|
else
|
||||||
utils.notify("builtin.lsp_*", {
|
utils.notify("builtin.lsp_*", {
|
||||||
msg = "server does not support " .. feature,
|
msg = "server does not support " .. method,
|
||||||
level = "INFO",
|
level = "INFO",
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user