Skip to content

Restoring a session containing a neo-tree sidebar breaks neo-tree #740

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

Closed
dhazel opened this issue Feb 9, 2023 · 13 comments · Fixed by #748
Closed

Restoring a session containing a neo-tree sidebar breaks neo-tree #740

dhazel opened this issue Feb 9, 2023 · 13 comments · Fixed by #748
Assignees
Labels
bug Something isn't working

Comments

@dhazel
Copy link

dhazel commented Feb 9, 2023

Thanks for the great plugin!

Neovim version: 0.8.2
OS: Windows 10

Steps to reproduce:

  1. Open neovim
  2. Open the neo-tree sidebar, :Neotree
  3. Save the session, :mksession mysession.vim
  4. Close neovim
  5. Open neovim
  6. Restore the session, :source mysession.vim
  7. Observe that the sidebar is created but neo-tree does not render in the sidebar
  8. Attempt to toggle the neotree sidebar, :Neotree
  9. Observe that neo-tree does not render and an error is thrown in messages:
Error executing vim.schedule lua callback: ...vim-data/lazy/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:867: Failed to rename buffer
stack traceback:
	[C]: in function 'nvim_buf_set_name'
	...vim-data/lazy/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:867: in function 'create_window'
	...vim-data/lazy/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:1015: in function 'draw'
	...vim-data/lazy/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:1177: in function 'show_nodes'
	...ree.nvim/lua/neo-tree/sources/filesystem/lib/fs_scan.lua:98: in function 'render_context'
	...ree.nvim/lua/neo-tree/sources/filesystem/lib/fs_scan.lua:126: in function <...ree.nvim/lua/neo-tree/sources/filesystem/lib/fs_scan.lua:125>
@nhat-vo
Copy link
Collaborator

nhat-vo commented Feb 10, 2023

Hi! Indeed, this looks like a bug. The neo-tree buffer was saved along with the session, and neo-tree is unable to overwrite that buffer when it is created again. A workaround would be to close the tree before creating the session. I will have a look to see if there is any way to do this automatically.

@nhat-vo nhat-vo added the bug Something isn't working label Feb 11, 2023
@nhat-vo nhat-vo self-assigned this Feb 11, 2023
@cseickel cseickel linked a pull request Feb 17, 2023 that will close this issue
@nyngwang
Copy link

@nhat-vo Does #748 resolve this now?

@nhat-vo
Copy link
Collaborator

nhat-vo commented Feb 19, 2023

Yes, thanks for reminding me. I thought the issue will automatically be closed on PR merge.

@nhat-vo nhat-vo closed this as completed Feb 19, 2023
@cseickel
Copy link
Contributor

Yes, thanks for reminding me. I thought the issue will automatically be closed on PR merge.

The issue will get automatically closed on release in this repo. It's not a big deal either way if you want to close it on merge to main though.

@ehaynes99
Copy link

I don't think this actually works. The function executes, but restoring a session like nvim -S Session.vim, I end up with the restored session having these buffers:

:buffers
  9 #    "~/all-workspaces/external/neo-tree.nvim/README.md" line 1
 10 %a   "lua/neo-tree/ui/renderer.lua" line 32
 11  a   "neo-tree filesystem [1]"      line 0

the neo-tree filesystem buffer is normal size and blank. Toggling the tree resumes the proper behavior.

Also, plugins like auto-session open session files like this:

silent source <SESSION_FILE>

In this case, the clean_neotree_buffers function is never called.

@nhat-vo
Copy link
Collaborator

nhat-vo commented Feb 21, 2023

Good point! I actually thought of adding the cleanup step right after a session was load, but somehow forgot about it.

@nyngwang
Copy link

nyngwang commented Feb 22, 2023

@nhat-vo Can confirm that your fix does work, and thank you! A minor issue is that there is a blink after restoring the session (so I did see the empty split was there and got closed during restoring)

@nhat-vo
Copy link
Collaborator

nhat-vo commented Feb 22, 2023

@nyngwang thanks for helping me test! Unfortunately, the neo-tree buffer will be loaded on session restore, which causes the blink that you see. I couldn't find any workaround to that, as the built-in :mksession does not provide any functionality to exclude a buffer or to emit an event to handle closing the neo-tree buffer.

@PriceHiller
Copy link

Unfortunately, at least for me, this fix causes the file tree to randomly close on opening some files in git projects.

It's related to clean_invalid_neotree_buffers. I don't have an autosession plugin or anything like that, so I'm not quite sure what's loading a session that would kick off the closing of the neotree sidebar.

@nhat-vo
Copy link
Collaborator

nhat-vo commented Feb 23, 2023

@treatybreaker thanks for letting me know. Could you tell me how to reproduce it? I tried to open files from the git source, but it was running fine.

@nhat-vo nhat-vo reopened this Feb 23, 2023
@PriceHiller
Copy link

PriceHiller commented Feb 24, 2023

Apologies for not responding until now. I'm going to dig into it tonight and see if I can't get a reproducible error action.

Lets close this issue out and if I'm still seeing the issue with a bare bones nvim install, I'll open an issue reporting it. Could just be something funky with my config.

@PriceHiller
Copy link

PriceHiller commented Feb 24, 2023

@nhat-vo

#771 resolves the issues I had above. I no longer have the issue when pointing lazy to your ref in #771.

Also, here's my neo-tree configuration, rather minimal.

@cseickel
Copy link
Contributor

cseickel commented Mar 1, 2023

Hi everyone, I just pushed a bit of a breaking change to the new session cleanup functionality. The feature which automatically cleans broken neo-tree buffers restored from a session is now opt-in. If you want to keep it, you need to add this option to your config:

  auto_clean_after_session_restore = false, -- Automatically clean up broken neo-tree buffers saved in sessions

@nhat-vo nhat-vo closed this as completed Mar 28, 2023
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

Successfully merging a pull request may close this issue.

6 participants