auto-session icon indicating copy to clipboard operation
auto-session copied to clipboard

[BUG] `auto_restore_enabled = true` not working

Open craigrosie opened this issue 1 year ago • 3 comments

Describe the bug When I open nvim without any arguments, I expect auto-session to automatically restore the previous session for the directory that I'm in. Instead, neovim just starts with the standard intro screen.

To Reproduce

return {
  'rmagatti/auto-session',
  event = 'VeryLazy',
  opts = {
    auto_save_enabled = true,
    auto_restore_enabled = true,
  },
}
  • Ensure that sessions directory is empty so there are no existing sessions.
  • Run nvim
  • Open "a.txt"
  • I can see session file being created for the directory I ran nvim in
  • Run :qa in neovim
  • Run nvim again
  • Expect "a.txt" to be opened automatically. Instead I get the standard neovim welcome screen.
  • If I manually run :SessionRestore, then "a.txt" is opened as expected

Screenshots If applicable, add screenshots to help explain your problem.

Baseline (please complete the following information):

  • Result of set sessionoptions?: sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize,terminal
  • OS. e.g uname -a: MacOS
  • Neovim version nvim --version: v0.10.0
  • URL to your current config (if public)

Additional context

craigrosie avatar Jun 17 '24 18:06 craigrosie

Can you add log_level = 'debug' to your opts and paste what it shows?

cameronr avatar Jun 26 '24 20:06 cameronr

I second what @cameronr said but also I wouldn't recommend using VeryLazy with auto-session necessarily. auto-session does some things that themselves depend on events that are fired after plugins are loaded but way before the VeryLazy event from lazy. This might even be the cause of your issues.

rmagatti avatar Jun 27 '24 05:06 rmagatti

Just noticed that your config has event = 'VeryLazy'. That will break session auto-restore because the VeryLazy event happens after the VimEnter event we use to trigger session loading. It will work if you change the config to:

return {
  'rmagatti/auto-session',
  lazy = false,
  opts = {
    -- auto_restore and auto_save are true by default so don't have to set them here
  },
}

I'm going to look into adding a checkhealth alert if event = VeryLazy and auto_restore = true

cameronr avatar Aug 26 '24 19:08 cameronr