Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit b2406a0

Browse files
committed
fix: telescope codeaction properly columnates and indexes client name (#6)
1 parent e3b31d4 commit b2406a0

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

lua/dressing/select/telescope.lua

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,51 @@ M.custom_kind = {
88
codeaction = function(opts, defaults, items)
99
local entry_display = require("telescope.pickers.entry_display")
1010
local finders = require("telescope.finders")
11-
local displayer = entry_display.create({
12-
separator = " ",
13-
items = {
14-
{ remaining = true },
15-
{ width = 16 },
16-
},
17-
})
11+
local displayer
1812

1913
local function make_display(entry)
20-
local client_name = vim.lsp.get_client_by_id(entry.client_id).name
2114
local columns = {
22-
opts.format_item(entry.value),
23-
{ client_name, "Comment" },
15+
entry.text,
16+
{ entry.client_name, "Comment" },
2417
}
2518
return displayer(columns)
2619
end
20+
21+
local entries = {}
22+
local client_width = 1
23+
local text_width = 1
24+
for _, item in ipairs(items) do
25+
local client_id = item[1]
26+
local client_name = vim.lsp.get_client_by_id(client_id).name
27+
local len = vim.api.nvim_strwidth(client_name)
28+
if len > client_width then
29+
client_width = len
30+
end
31+
local text = opts.format_item(item)
32+
len = vim.api.nvim_strwidth(text)
33+
if len > text_width then
34+
text_width = len
35+
end
36+
table.insert(entries, {
37+
display = make_display,
38+
text = text,
39+
client_name = client_name,
40+
ordinal = text .. " " .. client_name,
41+
value = item,
42+
})
43+
end
44+
displayer = entry_display.create({
45+
separator = " ",
46+
items = {
47+
{ width = text_width },
48+
{ width = client_width },
49+
},
50+
})
51+
2752
defaults.finder = finders.new_table({
28-
results = items,
53+
results = entries,
2954
entry_maker = function(item)
30-
return {
31-
display = make_display,
32-
client_id = item[1],
33-
ordinal = opts.format_item(item),
34-
value = item,
35-
}
55+
return item
3656
end,
3757
})
3858
end,

0 commit comments

Comments
 (0)