summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorSenghan Bright <senghan.bright@deltaprojects.com>2020-12-20 10:46:58 +0100
committerGitHub <noreply@github.com>2020-12-20 10:46:58 +0100
commit76f94588d361f9514f6f6574c171360684f184b4 (patch)
tree635ac4dd1eeba2ddf965f0a48b9b88f314fbde92 /lua
parent2488e31df8ff13cb3c008f846a137bf39287f048 (diff)
LSP check capabilities (#356)
* check server capabilities before using LSP finders * client indices do not always start at [1] * succeed on first supported client * use apply_checks method * removed debug comment * rename mappings table
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/lsp.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua
index b37f93a..3d135dc 100644
--- a/lua/telescope/builtin/lsp.lua
+++ b/lua/telescope/builtin/lsp.lua
@@ -181,11 +181,44 @@ lsp.workspace_symbols = function(opts)
}):find()
end
+local function check_capabilities(feature)
+ local clients = vim.lsp.buf_get_clients(0)
+
+ local supported_client = false
+ for _, client in pairs(clients) do
+ supported_client = client.resolved_capabilities[feature]
+ if supported_client then goto continue end
+ end
+
+ ::continue::
+ if supported_client then
+ return true
+ else
+ if #clients == 0 then
+ print("LSP: no client attached")
+ else
+ print("LSP: server does not support " .. feature)
+ end
+ return false
+ end
+end
+
+local feature_map = {
+ ["code_actions"] = "code_action",
+ ["document_symbols"] = "document_symbol",
+ ["references"] = "find_references",
+ ["workspace_symbols"] = "workspace_symbol",
+}
+
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) then
+ return
+ end
v(opts)
end
end