summaryrefslogtreecommitdiff
path: root/lua/telescope/builtin/lsp.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-04-21 02:48:29 +0200
committerGitHub <noreply@github.com>2021-04-20 17:48:29 -0700
commit3adeab2bed42597c8495fbe3a2376c746232f2e3 (patch)
treea4cd1f60c32a11d869af92d5c535fba05de73a40 /lua/telescope/builtin/lsp.lua
parent13dae8c4d924472933443f14109a0739dbacbeda (diff)
fix: support multiple clients in lsp code actions (#722)
* fix: support multiple clients in lsp code actions * no goto * reduce diff a bit * use displayer, also include lsp client name for each entry * review comments
Diffstat (limited to 'lua/telescope/builtin/lsp.lua')
-rw-r--r--lua/telescope/builtin/lsp.lua62
1 files changed, 51 insertions, 11 deletions
diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua
index 285a047..91097ba 100644
--- a/lua/telescope/builtin/lsp.lua
+++ b/lua/telescope/builtin/lsp.lua
@@ -3,6 +3,7 @@ local action_state = require('telescope.actions.state')
local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local pickers = require('telescope.pickers')
+local entry_display = require('telescope.pickers.entry_display')
local utils = require('telescope.utils')
local a = require('plenary.async_lib')
local async, await = a.async, a.await
@@ -131,20 +132,56 @@ lsp.code_actions = function(opts)
return
end
- local _, response = next(results_lsp)
- if not response then
- print("No code actions available")
- return
+ local idx = 1
+ local results = {}
+ local widths = {
+ idx = 0,
+ command_title = 0,
+ client_name = 0,
+ }
+
+ for client_id, response in pairs(results_lsp) do
+ if response.result then
+ local client = vim.lsp.get_client_by_id(client_id)
+
+ for _, result in pairs(response.result) do
+ local entry = {
+ idx = idx,
+ command_title = result.title,
+ client_name = client and client.name or "",
+ command = result,
+ }
+
+ for key, value in pairs(widths) do
+ widths[key] = math.max(value, utils.strdisplaywidth(entry[key]))
+ end
+
+ table.insert(results, entry)
+ idx = idx + 1
+ end
+ end
end
- local results = response.result
- if not results or #results == 0 then
+ if #results == 0 then
print("No code actions available")
return
end
- for i,x in ipairs(results) do
- x.idx = i
+ local displayer = entry_display.create {
+ separator = " ",
+ items = {
+ { width = widths.idx + 1 }, -- +1 for ":" suffix
+ { width = widths.command_title },
+ { width = widths.client_name },
+ },
+ }
+
+ local function make_display(entry)
+ return displayer {
+ {entry.idx .. ":", "TelescopePromptPrefix"},
+ {entry.command_title},
+ {entry.client_name, "TelescopeResultsComment"},
+ }
end
pickers.new(opts, {
@@ -154,9 +191,12 @@ lsp.code_actions = function(opts)
entry_maker = function(line)
return {
valid = line ~= nil,
- value = line,
- ordinal = line.idx .. line.title,
- display = line.idx .. ': ' .. line.title
+ value = line.command,
+ ordinal = line.idx .. line.command_title,
+ command_title = line.command_title,
+ idx = line.idx,
+ client_name = line.client_name,
+ display = make_display,
}
end
},