snacks.nvim icon indicating copy to clipboard operation
snacks.nvim copied to clipboard

bug: Multiple actions that include `picker_explorer/files/recent` not working

Open dpetka2001 opened this issue 9 months ago • 5 comments

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
  },
})

dpetka2001 avatar Mar 04 '25 18:03 dpetka2001

I'm having a similar issue/bug with recent.

When running Recent Files using dashboard:

Image

: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>

mau-mauricelim avatar Mar 07 '25 04:03 mau-mauricelim

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.

github-actions[bot] avatar Apr 07 '25 02:04 github-actions[bot]

Still valid.

dpetka2001 avatar Apr 07 '25 06:04 dpetka2001

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.

github-actions[bot] avatar May 08 '25 02:05 github-actions[bot]

Not stale

dpetka2001 avatar May 08 '25 05:05 dpetka2001

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.

github-actions[bot] avatar Jun 08 '25 02:06 github-actions[bot]

Don't think so

dpetka2001 avatar Jun 08 '25 07:06 dpetka2001

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

noprompt avatar Jun 09 '25 18:06 noprompt

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.

github-actions[bot] avatar Jul 31 '25 02:07 github-actions[bot]

...

dpetka2001 avatar Jul 31 '25 03:07 dpetka2001

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.

github-actions[bot] avatar Sep 01 '25 02:09 github-actions[bot]

.

dpetka2001 avatar Sep 01 '25 04:09 dpetka2001

.

stackanthony avatar Sep 05 '25 18:09 stackanthony

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.

github-actions[bot] avatar Oct 06 '25 02:10 github-actions[bot]

.

dpetka2001 avatar Oct 06 '25 06:10 dpetka2001

Also came across this, the workaround above has resolved things for now at least 🙂

TheseusGrey avatar Oct 17 '25 13:10 TheseusGrey

Both issues should be fixed. Sorry for the delay! :)

folke avatar Oct 17 '25 19:10 folke