Skip to content

Commit

Permalink
feat(lsp): added support for dynamic capabilities (#2594)
Browse files Browse the repository at this point in the history
(cherry picked from commit 276362a)
  • Loading branch information
folke authored and Conni2461 committed May 22, 2024
1 parent d829aa6 commit 08a2810
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions lua/telescope/builtin/__lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -348,55 +348,56 @@ lsp.dynamic_workspace_symbols = function(opts)
:find()
end

local function check_capabilities(feature, bufnr)
--TODO(clason): remove when dropping support for Nvim 0.9
local clients = vim.fn.has "nvim-0.10" == 1 and vim.lsp.get_clients { bufnr = bufnr }
or vim.lsp.buf_get_clients(bufnr)
local function check_capabilities(method, bufnr)
local clients = (function()
if vim.fn.has "nvim-0.10" == 1 then
return vim.lsp.get_clients { bufnr = bufnr }
elseif vim.lsp.get_active_clients then
return vim.lsp.get_active_clients { bufnr = bufnr }
else
return vim.lsp.buf_get_clients(bufnr)
end
end)()

local supported_client = false
for _, client in pairs(clients) do
supported_client = client.server_capabilities[feature]
if supported_client then
break
-- we always pass opts, even though older nvim version might not have a second param
if client.supports_method(method, { bufnr = bufnr }) then
return true
end
end

if supported_client then
return true
if #clients == 0 then
utils.notify("builtin.lsp_*", {
msg = "no client attached",
level = "INFO",
})
else
if #clients == 0 then
utils.notify("builtin.lsp_*", {
msg = "no client attached",
level = "INFO",
})
else
utils.notify("builtin.lsp_*", {
msg = "server does not support " .. feature,
level = "INFO",
})
end
return false
utils.notify("builtin.lsp_*", {
msg = "server does not support " .. method,
level = "INFO",
})
end
return false
end

local feature_map = {
["document_symbols"] = "documentSymbolProvider",
["references"] = "referencesProvider",
["definitions"] = "definitionProvider",
["type_definitions"] = "typeDefinitionProvider",
["implementations"] = "implementationProvider",
["workspace_symbols"] = "workspaceSymbolProvider",
["incoming_calls"] = "callHierarchyProvider",
["outgoing_calls"] = "callHierarchyProvider",
["document_symbols"] = "textDocument/documentSymbol",
["references"] = "textDocument/references",
["definitions"] = "textDocument/definition",
["type_definitions"] = "textDocument/typeDefinition",
["implementations"] = "textDocument/implementation",
["workspace_symbols"] = "workspace/symbol",
["incoming_calls"] = "callHierarchy/incomingCalls",
["outgoing_calls"] = "callHierarchy/outgoingCalls",
}

local function apply_checks(mod)
for k, v in pairs(mod) do
mod[k] = function(opts)
opts = opts or {}

local feature_name = feature_map[k]
if feature_name and not check_capabilities(feature_name, opts.bufnr) then
local method = feature_map[k]
if method and not check_capabilities(method, opts.bufnr) then
return
end
v(opts)
Expand Down

0 comments on commit 08a2810

Please sign in to comment.