mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(picker.commands): added builtin commands. Fixes #634
This commit is contained in:
parent
6815739114
commit
ee988fa4b0
4 changed files with 20 additions and 1 deletions
|
@ -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",
|
||||
|
|
|
@ -76,7 +76,7 @@ M.command_history = {
|
|||
-- Neovim commands
|
||||
M.commands = {
|
||||
finder = "vim_commands",
|
||||
format = "text",
|
||||
format = "command",
|
||||
preview = "preview",
|
||||
confirm = "cmd",
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue