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

bug: Recent picker does not update until Neovim is restarted

Open jbigler opened this issue 8 months ago • 8 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)

0.11.0

Operating system/version

Arch

Describe the bug

Recurrence of bug #487

If I open files into buffers and close them, they will not appear in Snacks.picker.recent() until I close Neovim and open it again.

Steps To Reproduce

  1. Open a file in a buffer.
  2. Close the file.
  3. :lua Snacks.picker.recent() returns empty list
  4. Close and restart Neovim
  5. :lua Snacks.picker.recent() shows the file that was opened in the last session.

Expected Behavior

Show all files that have been opened in Neovim, including the current session.

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

jbigler avatar Apr 15 '25 09:04 jbigler

I believe this happens because of this line https://github.com/folke/snacks.nvim/blob/bc0630e43be5699bb94dadc302c0d21615421d93/lua/snacks/picker/source/recent.lua#L36

The last part vim.bo[b].buflisted returns only listed buffers. Buffers that have been closed are not listed any more. Seems to be intended, but of course it could be omitted to show even buffers that have been closed.

dpetka2001 avatar Apr 15 '25 16:04 dpetka2001

A naive solution would be to use something like the following patch

diff --git a/lua/snacks/picker/config/sources.lua b/lua/snacks/picker/config/sources.lua
index d5bd8c3..01e8db9 100644
--- a/lua/snacks/picker/config/sources.lua
+++ b/lua/snacks/picker/config/sources.lua
@@ -739,6 +739,7 @@ M.qflist = {
 -- Find recent files
 ---@class snacks.picker.recent.Config: snacks.picker.Config
 ---@field filter? snacks.picker.filter.Config
+---@field current_session? boolean
 M.recent = {
   finder = "recent_files",
   format = "file",
diff --git a/lua/snacks/picker/source/recent.lua b/lua/snacks/picker/source/recent.lua
index 6ea98ce..c925786 100644
--- a/lua/snacks/picker/source/recent.lua
+++ b/lua/snacks/picker/source/recent.lua
@@ -33,7 +33,9 @@ function M.files(opts, ctx)
   local current_file = svim.fs.normalize(vim.api.nvim_buf_get_name(0), { _fast = true })
   ---@type number[]
   local bufs = vim.tbl_filter(function(b)
-    return vim.api.nvim_buf_get_name(b) ~= "" and vim.bo[b].buftype == "" and vim.bo[b].buflisted
+    return vim.api.nvim_buf_get_name(b) ~= ""
+      and vim.bo[b].buftype == ""
+      and (opts.current_session or vim.bo[b].buflisted)
   end, vim.api.nvim_list_bufs())
   table.sort(bufs, function(a, b)
     return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused

But I don't know if that's what the maintainer intended or not, so I'll defer to his judgement about this.

dpetka2001 avatar Apr 15 '25 16:04 dpetka2001

is it possible to add the option for updating recent picker even Neovim is not restarted?

GladioFeng avatar Apr 20 '25 07:04 GladioFeng

@GladioFeng It's not up to me. I'm just a simple user with limited programming knowledge.

Maybe my code has some other affects on the plugin (I haven't tested thoroughly since I don't use such option). That's why I just pasted my naive solution as a diff here, so that maintainer can see it and decide if maybe some other changes are needed as well if he decides to go forward with this.

dpetka2001 avatar Apr 20 '25 08:04 dpetka2001

I see, thanks for your responding.

GladioFeng avatar Apr 22 '25 02:04 GladioFeng

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 23 '25 02:05 github-actions[bot]

Would be nice if the issue could be fixed.

manfredlotz avatar May 23 '25 08:05 manfredlotz

Not stale.

jbigler avatar May 23 '25 19:05 jbigler

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 23 '25 02:06 github-actions[bot]

Not stale yet.

jbigler avatar Jun 23 '25 02:06 jbigler

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 30 '25 02:07 github-actions[bot]

I don't know what the bug here was but it looks like this has been solved in the meantime. So, IMHO, it could be closed.

manfredlotz avatar Jul 30 '25 07:07 manfredlotz

It’s still not working for me with NVIM v0.11.3. This is expected, given that the repository hasn’t seen any updates in the last five months.

nudzg avatar Jul 30 '25 07:07 nudzg

Sorry, you are right. It is working for me because of some changes in my emacs environment.

manfredlotz avatar Jul 30 '25 08:07 manfredlotz

Not stale yet.

jbigler avatar Jul 30 '25 09:07 jbigler

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]

Not stale yet.

jbigler avatar Sep 01 '25 09:09 jbigler

Facing the same issue, moved from telescope to snacks and the recent files picker is breaking unfortunately.

HemendraSinghShekhawat avatar Sep 03 '25 11:09 HemendraSinghShekhawat

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 04 '25 02:10 github-actions[bot]

Not stale. Claude gave me a temporary patch using an autocmd to track BufEnter and store a list of files opened during the session, which is working for files that were opened during the current session whether the buffer is still open or not.

jbigler avatar Oct 06 '25 04:10 jbigler