Skip to content

Commit 62d99ed

Browse files
antonk52folke
andauthored
feat(picker.commands): do not autorun commands that require arguments (#879)
## Description Currently when you use picker.commands to select a command that requires an argument, it will cause an error. `:BlickCmd` is one example. To avoid the error we can feed the keys to enter the command mode and populate the command and leave it to the user what they want to do. This is also what telescope [does](https://github.com/nvim-telescope/telescope.nvim/blob/415af52339215926d705cccc08145f3782c4d132/lua/telescope/builtin/__internal.lua#L399) in its builtin command picker. nargs values `*` or `?` mean that the command can be executed both with arguments and without. I think it is safer to leave it to the user to decide if they want them to either trigger a run or provide the arguments. But happy to change it if you think running the commands by default makes sense. --------- Co-authored-by: Folke Lemaitre <[email protected]>
1 parent b6a84db commit 62d99ed

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lua/snacks/picker/actions.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,11 @@ function M.cmd(picker, item)
386386
picker:close()
387387
if item and item.cmd then
388388
vim.schedule(function()
389-
vim.cmd(item.cmd)
389+
if item.command and (item.command.nargs ~= "0") then
390+
vim.api.nvim_input(":" .. item.cmd .. " ")
391+
else
392+
vim.cmd(item.cmd)
393+
end
390394
end)
391395
end
392396
end

lua/snacks/picker/source/vim.lua

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ local M = {}
1515
---@class snacks.picker.history.Config: snacks.picker.Config
1616
---@field name string
1717

18-
local uv = vim.uv or vim.loop
19-
2018
function M.commands()
2119
local commands = vim.api.nvim_get_commands({})
2220
for k, v in pairs(vim.api.nvim_buf_get_commands(0, {})) do

0 commit comments

Comments
 (0)