tiagovla/scope.nvim

Inactive buffers in inactive tabpages won't be restored after restoring the session

Closed this issue · 3 comments

Steps to reproduce

  1. Open neovim. Let's call current tab as Tab A
  2. Open file 1, 2. Now the main window shows file 2.
  3. Create a new tab, called Tab B.
  4. Enter Tab B, and open file 3, 4.
  5. Leave neovim, the session is saved.
  6. Enter neovim again, now the session should be restored. We should be in Tab B, and file 3 and 4 are fine.
    Go to Tab A, only file 2 is loaded.

showcase

Session manager

I use olimorris/persisted.nvim as the session manager, and I call ScopeSaveState before save the session and ScopeLoadState after load the session.

Some discoveries

I found that vim.g.ScopeState was correctly set after restoring the session. So I went to have a check on the session file. Then I found that the session file actually didn't load the file 1 at all. Since the session manager is built upon mksession, I dived into neovim's source codes.

https://github.com/neovim/neovim/blob/c614969570ac13cfc1ff6642fcaf56ebce6d40be/src/nvim/ex_session.c#L650-L668

It seems that only listed buffers are saved.

https://github.com/neovim/neovim/blob/c614969570ac13cfc1ff6642fcaf56ebce6d40be/src/nvim/ex_session.c#L739-L761

Here it loads the files showed in the windows of a tabpage.

Since scope.nvim hides other tabs' buffers by setting nobuflisted, the inactive tabs' buffers aren't listed and they won't be saved, except for ones showed because neovim will save them even they aren't listed.

If I misunderstood anything, please correct me. Thanks!

Thanks for the detailed report.

@v1nh1shungry, I have a PR to fix this.

Thanks @aidigital! I can confirm the issue is resolved in my machine with the PR.