feat(picker.help): add more color to help tags

This commit is contained in:
Folke Lemaitre 2025-01-22 22:15:59 +01:00
parent caf20764f1
commit 5778234e39
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 17 additions and 5 deletions

View file

@ -281,7 +281,7 @@ function M.text(item, picker)
if ft then
Snacks.picker.highlight.format(item, item.text, ret, { lang = ft })
else
ret[#ret + 1] = { item.text }
ret[#ret + 1] = { item.text, item.text_hl }
end
return ret
end

View file

@ -42,15 +42,27 @@ function M.help(opts)
for _, file in ipairs(tag_files[lang] or {}) do
for line in io.lines(file) do
local fields = vim.split(line, string.char(9), { plain = true })
if not line:match("^!_TAG_") and #fields == 3 and not done[fields[1]] then
done[fields[1]] = true
local tag = fields[1]
if not line:match("^!_TAG_") and #fields == 3 and not done[tag] then
done[tag] = true
---@type snacks.picker.finder.Item
local item = {
text = fields[1],
tag = fields[1],
text = tag,
tag = tag,
file = help_files[fields[2]],
search = "/\\V" .. fields[3]:sub(2),
}
if tag:find("^[vbg]?:") or tag:find("^/") then
item.ft = "vim"
elseif tag:find("%(%)$") then
item.ft = "lua"
elseif tag:find("^'.*'$") then
item.text_hl = "String"
elseif tag:find("^E%d+$") then
item.text_hl = "Error"
elseif tag:find("^hl%-") then
item.text_hl = tag:sub(4)
end
if item.file then
cb(item)
end