feat(picker.commands): added builtin commands. Fixes #634

This commit is contained in:
Folke Lemaitre 2025-01-19 13:01:24 +01:00
parent 6815739114
commit ee988fa4b0
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
4 changed files with 20 additions and 1 deletions

View file

@ -19,9 +19,12 @@ Snacks.util.set_hl({
Row = "String",
Col = "LineNr",
Comment = "Comment",
Desc = "Comment",
Delim = "Delimiter",
Spinner = "Special",
Selected = "Number",
Cmd = "Function",
CmdBuiltin = "@constructor",
Unselected = "NonText",
Idx = "Number",
Bold = "Bold",

View file

@ -76,7 +76,7 @@ M.command_history = {
-- Neovim commands
M.commands = {
finder = "vim_commands",
format = "text",
format = "command",
preview = "preview",
confirm = "cmd",
}

View file

@ -218,6 +218,16 @@ function M.text(item)
}
end
function M.command(item)
local ret = {} ---@type snacks.picker.Highlight[]
ret[#ret + 1] = { item.cmd, "SnacksPickerCmd" .. (item.cmd:find("^[a-z]") and "Builtin" or "") }
if item.desc then
ret[#ret + 1] = { " " }
ret[#ret + 1] = { item.desc, "SnacksPickerDesc" }
end
return ret
end
function M.diagnostic(item, picker)
local ret = {} ---@type snacks.picker.Highlight[]
local diag = item.item ---@type vim.Diagnostic

View file

@ -22,6 +22,11 @@ function M.commands()
commands[k] = v
end
end
for _, c in ipairs(vim.fn.getcompletion("", "command")) do
if not commands[c] and c:find("^[a-z]") then
commands[c] = { definition = "completion" }
end
end
---@async
---@param cb async fun(item: snacks.picker.finder.Item)
return function(cb)
@ -32,6 +37,7 @@ function M.commands()
local def = commands[name]
cb({
text = name,
desc = def.script_id and def.script_id < 0 and def.definition or nil,
command = def,
cmd = name,
preview = {