bug: Multiple actions that include `picker_explorer/files/recent` not working
Did you check docs and existing issues?
- [x] I have read all the snacks.nvim docs
- [x] I have updated the plugin to the latest version before submitting this issue
- [x] I have searched the existing issues of snacks.nvim
- [x] I have searched the existing issues of plugins related to this issue
Neovim version (nvim -v)
NVIM v0.11.0-dev-1897+g47cfe901d7
Operating system/version
Linux Mint 21.3
Describe the bug
Defining multiple actions for snacks.picker.projects not working when you include picker_explorer/files/recent in the table like confirm = { "load_session", "picker_explorer" }.
Doing a print here https://github.com/folke/snacks.nvim/blob/bc0630e43be5699bb94dadc302c0d21615421d93/lua/snacks/picker/actions.lua#L265 always returns files.
Also doing the following confirm = { "picker_explorer", "load_session" } throws an error about not being able to concatenate because of value at first index being nil at this point in code https://github.com/folke/snacks.nvim/blob/bc0630e43be5699bb94dadc302c0d21615421d93/lua/snacks/picker/core/actions.lua#L103-L108
I managed to make it work locally with the following patch
diff --git a/lua/snacks/picker/actions.lua b/lua/snacks/picker/actions.lua
index 6e6050e..7604be8 100644
--- a/lua/snacks/picker/actions.lua
+++ b/lua/snacks/picker/actions.lua
@@ -274,9 +274,9 @@ function M.picker(picker, item, action)
})
end
-M.picker_files = { action = "picker", source = "files" }
-M.picker_explorer = { action = "picker", source = "explorer" }
-M.picker_recent = { action = "picker", source = "recent" }
+M.picker_files = { action = "picker", source = "files", desc = "files" }
+M.picker_explorer = { action = "picker", source = "explorer", desc = "explorer" }
+M.picker_recent = { action = "picker", source = "recent", desc = "recent" }
function M.pick_win(picker, item, action)
if not picker.layout.split then
diff --git a/lua/snacks/picker/core/actions.lua b/lua/snacks/picker/core/actions.lua
index dcaf103..a2239f6 100644
--- a/lua/snacks/picker/core/actions.lua
+++ b/lua/snacks/picker/core/actions.lua
@@ -8,6 +8,7 @@ local M = {}
---@field action snacks.picker.Action.fn
---@field desc? string
---@field name? string
+---@field source? string
---@param picker snacks.Picker
function M.get(picker)
@@ -95,9 +96,9 @@ function M.resolve(action, picker, name, stack)
return M.resolve(a, picker, nil, stack)
end, action)
return {
- action = function(p, i, aa)
+ action = function(p, i, _)
for _, a in ipairs(actions) do
- a.action(p, i, aa)
+ a.action(p, i, a)
end
end,
desc = table.concat(
but am not confident this is 100% the correct solution and will not cause other side-effects.
Steps To Reproduce
Put the following in your personal configuration
return {
{
"folke/snacks.nvim",
dev = true,
opts = {
picker = {
sources = {
projects = {
confirm = { "load_session", "picker_explorer" },
},
},
},
},
},
}
and observe that always the picker_files is opened.
Expected Behavior
Should open the explorer instead of the files picker.
Doing
projects = {
confirm = function(picker)
picker:action("load_session")
picker:action("picker_explorer")
end,
},
},
also works correctly.
Repro
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").repro({
spec = {
{ "folke/snacks.nvim", opts = {} },
-- add any other plugins here
},
})
I'm having a similar issue/bug with recent.
When running Recent Files using dashboard:
:lua Snacks.picker.recent()
Error 04:37:26 msg_show.emsg E5108: Error executing lua: ...hare/nvim/lazy/snacks.nvim/lua/snacks/picker/util/kv.lua:32: unexpected end of buffer
stack traceback:
[C]: in function 'decode'
...hare/nvim/lazy/snacks.nvim/lua/snacks/picker/util/kv.lua:32: in function 'new'
...nvim/lazy/snacks.nvim/lua/snacks/picker/util/history.lua:30: in function 'new'
.../nvim/lazy/snacks.nvim/lua/snacks/picker/core/picker.lua:101: in function 'recent'
/home/maurice/.config/nvim/lua/plugins/snacks.lua:348: in function </home/maurice/.config/nvim/lua/plugins/snacks.lua:348>
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Still valid.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Not stale
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Don't think so
I encountered the [C]: in function 'decode' problem today. I was able to work around it by cleaning up the history files
rm ~/.local/share/nvim/snacks/*.history
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
...
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
.
.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
.
Also came across this, the workaround above has resolved things for now at least 🙂
Both issues should be fixed. Sorry for the delay! :)