From 76f94588d361f9514f6f6574c171360684f184b4 Mon Sep 17 00:00:00 2001 From: Senghan Bright Date: Sun, 20 Dec 2020 10:46:58 +0100 Subject: [PATCH] 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 --- lua/telescope/builtin/lsp.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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