Closed carlosflorencio closed 1 year ago
Good evening! By "restoring" do you mean autoload = true
(namely restoring previous directory session at startup) or do you mean by selecting a session from the sessions list?
Would the session be restored normally if you manually run vim.cmd.source(<sessionpath>)
(this is to understand whether the problem is with the loading mechanism or with the session file itself that cannot re-open the nvim-tree buffer)?
Hi!
I mean restore by selecting a session from the list, sourcing the session file directly with vim.cmd.source(<sessionpath>)
has the same behaviour (blank nvim-tree
buffer).
I have reproduced it: the reason is that nvim-tree
does not save the content of the buffer upon closing, and hence the buffer does not exist in the list that is loaded in memory by sourcing the session. You can easily verify this by comparing, say, with other temporary-buffers like vim-fugitive
that are instead saved. Perform the following experiment:
vim-fugitive
(or other plugins)nvim-tree
bufferNow inspect the session file (located at ~/.local/share/nvim/sessions/<sessionfile>
) and you will see entries like
badd +X filename
badd +X //fugitive
badd ...
but in the above list you will not see nvim-tree
; instead, you will probably find an entry below with
file/edit NvimTree
which remembers the existence of such window but without having saved the content of the buffer.
This is a behaviour specific to nvim-tree
and unless they have an option to explicitly save the buffer content upon closing there isn't much we can do, as it doesn't depend on the session.
I see, thanks for the investigation.
A possible solution could be to toggle the nvim-tree
after loading a session, like this. Just tested and doesn't seem to work.
https://github.com/nvim-tree/nvim-tree.lua/pull/307 should already handle this scenario when the event SessionLoadPost
is fired.
I see, what they do is basically define user events that trigger as post-hooks, after loading. It should be possible to add it; I will work on it in the next days and see if I get a working prototype :)
I have drafted this PR to address the issue: would you mind helping me test it? You could install the specific branch post_hooks
and require at setup
require("nvim-possession").setup({
post_hook = function()
require('nvim-tree').toggle(false, true)
end
})
(see README for more instructions about the feature).
Yep, seems to work like a charm :). nvim-tree
opens after restoring a session (without focus).
Merged to main
and released in v0.0.4. You can now simply update and you're good to go :)
Awesome work 💪.
Hi,
When restoring a session which had
nvim-tree
opened, the plugin doesn't seem to be started, the buffer stays blank:Thanks for the plugin btw.