Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
dpetka2001 opened this issue Mar 4, 2025 · 1 comment
Open
4 tasks done
Labels
bug Something isn't working

Comments

@dpetka2001
Copy link
Contributor

Did you check docs and existing issues?

  • I have read all the snacks.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of snacks.nvim
  • 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

local source = action.source or "files"
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
desc = table.concat(
vim.tbl_map(function(a)
return a.desc
end, actions),
", "
),

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 dpetka2001 added the bug Something isn't working label Mar 4, 2025
@mau-mauricelim
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants