bug: Recent picker does not update until Neovim is restarted
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
- Open a file in a buffer.
- Close the file.
:lua Snacks.picker.recent()returns empty list- Close and restart Neovim
: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
},
})
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.
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.
is it possible to add the option for updating recent picker even Neovim is not restarted?
@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.
I see, thanks for your responding.
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.
Would be nice if the issue could be fixed.
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.
Not stale yet.
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.
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.
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.
Sorry, you are right. It is working for me because of some changes in my emacs environment.
Not stale yet.
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 yet.
Facing the same issue, moved from telescope to snacks and the recent files picker is breaking unfortunately.
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. 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.