fix: telescope codeaction properly columnates and indexes client name (#6)

This commit is contained in:
Steven Arcangeli 2022-05-29 18:42:36 -07:00
parent e3b31d45bc
commit b2406a0ea7
1 changed files with 37 additions and 17 deletions

View File

@ -8,31 +8,51 @@ M.custom_kind = {
codeaction = function(opts, defaults, items) codeaction = function(opts, defaults, items)
local entry_display = require("telescope.pickers.entry_display") local entry_display = require("telescope.pickers.entry_display")
local finders = require("telescope.finders") local finders = require("telescope.finders")
local displayer = entry_display.create({ local displayer
separator = " ",
items = {
{ remaining = true },
{ width = 16 },
},
})
local function make_display(entry) local function make_display(entry)
local client_name = vim.lsp.get_client_by_id(entry.client_id).name
local columns = { local columns = {
opts.format_item(entry.value), entry.text,
{ client_name, "Comment" }, { entry.client_name, "Comment" },
} }
return displayer(columns) return displayer(columns)
end end
defaults.finder = finders.new_table({
results = items, local entries = {}
entry_maker = function(item) local client_width = 1
return { local text_width = 1
for _, item in ipairs(items) do
local client_id = item[1]
local client_name = vim.lsp.get_client_by_id(client_id).name
local len = vim.api.nvim_strwidth(client_name)
if len > client_width then
client_width = len
end
local text = opts.format_item(item)
len = vim.api.nvim_strwidth(text)
if len > text_width then
text_width = len
end
table.insert(entries, {
display = make_display, display = make_display,
client_id = item[1], text = text,
ordinal = opts.format_item(item), client_name = client_name,
ordinal = text .. " " .. client_name,
value = item, value = item,
} })
end
displayer = entry_display.create({
separator = " ",
items = {
{ width = text_width },
{ width = client_width },
},
})
defaults.finder = finders.new_table({
results = entries,
entry_maker = function(item)
return item
end, end,
}) })
end, end,