Skip to content
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

[BUG] auto-restore-last-session not working #377

Closed
jack-obrien opened this issue Sep 16, 2024 · 5 comments
Closed

[BUG] auto-restore-last-session not working #377

jack-obrien opened this issue Sep 16, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@jack-obrien
Copy link

jack-obrien commented Sep 16, 2024

Describe the bug
When I open nvim with the auto-session plugin enabled and the config option auto-restore-last-session, the last session is not restored.

To Reproduce
Steps to reproduce the behavior:

  1. Ensure there is no session file in ~/.local/share/nvim/sessions corresponding to /home/user.
  2. Ensure that the last session opened was in a different directory to /home/user.
  3. cd ~
  4. Start nvim with the auto-session plugin enabled and the config option auto-restore-last-session.

Expected behavior
The last session is restored.

Screenshots

Checkhealth

  1                                                                                                                                              
    1 ──────────────────────────────────────────────────────────────────────────────
    2 auto-session: require("auto-session.health").check()
    3  
    4 vim options  
    5 - OK vim.o.sessionoptions
    6  
    7 Lazy.nvim settings  
    8 - OK Lazy.nvim support is enabled
    9 - OK auto-session is not lazy loaded
   10  
   11 Config  
   12 - OK·
   13   {
   14     auto_restore_last_session = true,
   15     log_level = "debug"
   16   }
   17  
   18 General Info  
   19 - Session directory: /home/jackus/.local/share/nvim/sessions/
   20 - Current session:·
   21 - Current session file:·

Baseline (please complete the following information):

  • Result of set sessionoptions?: sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions
  • OS. e.g uname -a: Linux pcname 6.10.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 12 Sep 2024 17:21:02 +0000 x86_64 GNU/Linux
  • Neovim version nvim --version:
Build type: Release
LuaJIT 2.1.1725453128

Additional context
Thanks for any help! I love your work.

@jack-obrien jack-obrien added the bug Something isn't working label Sep 16, 2024
@cameronr
Copy link
Collaborator

cameronr commented Sep 16, 2024

Thanks for the report! A trivial test case works for me so there must be more going on. Can you do the following:

  1. add log_level = 'debug', to your auto-session config
  2. start nvim where it doesn't restore the last session as expected
  3. Post the logs to this issue, as reported by either :Notifications or :messages (depending on if you have nvim-notify or not)?

@jack-obrien
Copy link
Author

Yes, here are the logs! Thank you for a quick response :)

For this example, my previous session i want to restore is my neovim config with cwd .local/nvim/. My workflow to reproduce the bug is:

  1. cd .local/nvim
  2. nvim
  3. :e init.lua
  4. :q
  5. cd ~
  6. nvim

And after doing that, here is the debug output from auto-session as reported by :messages:

auto-session DEBUG: Config at start of setup {                                                                                                                                                                                                                      
  args_allow_files_auto_save = false,                                                                                                                                                                                                                                         
  args_allow_single_directory = true,                                                                                                                                                                                                                                         
  auto_create = true,                                                                                                                                                                                                                                                         
  auto_restore = true,                                                                                                                                                                                                                                                        
  auto_restore_last_session = true,                                                                                                                                                                                                                                           
  auto_save = true,                                                                                                                                                                                                                                                           
  close_unsupported_windows = true,                                                                                                                                                                                                                                           
  continue_restore_on_error = true,                                                                                                                                                                                                                                           
  cwd_change_handling = false,                                                                                                                                                                                                                                                
  enabled = true,                                                                                                                                                                                                                                                             
  lazy_support = true,                                                                                                                                                                                                                                                        
  log_level = "debug",                                                                                                                                                                                                                                                        
  root_dir = "/home/jackus/.local/share/nvim/sessions/",                                                                                                                                                                                                                      
  session_lens = {                                                                                                                                                                                                                                                            
    load_on_setup = true,                                                                                                                                                                                                                                                     
    mappings = {                                                                                                                                                                                                                                                              
      alternate_session = { "i", "<C-S>" },                                                                                                                                                                                                                                   
      delete_session = { "i", "<C-D>" }                                                                                                                                                                                                                                       
    },                                                                                                                                                                                                                                                                        
    previewer = false,                                                                                                                                                                                                                                                        
    session_control = {                                                                                                                                                                                                                                                       
      control_dir = "/home/jackus/.local/share/nvim/auto_session/",                                                                                                                                                                                                           
      control_filename = "session_control.json"                                                                                                                                                                                                                               
    },                                                                                                                                                                                                                                                                        
    theme_conf = {}                                                                                                                                                                                                                                                           
  },                                                                                                                                                                                                                                                                          
  use_git_branch = false                                                                                                                                                                                                                                                      
}                                                                                                                                                                                                                                                                             
auto-session DEBUG: Root dir set to: /home/jackus/.local/share/nvim/sessions/                                                                                                                                                                                                 
auto-session DEBUG: cwd_change_handling is disabled, skipping setting DirChangedPre and DirChanged autocmd handling                                                                                                                                                           
auto-session DEBUG: Loading session lens                                                                                                                                                                                                                                      
auto-session DEBUG: Lazy is loaded, but not visible, will try to restore session                                                                                                                                                                                              
auto-session DEBUG: enabled_for_command_line_argv, launch_argv: {}                                                                                                                                                                                                            
auto-session DEBUG: No arguments, saving/restoring enabled                                                                                                                                                                                                                    
auto-session DEBUG: find_matching_directory {                                                                                                                                                                                                                                 
  dirToFind = "/home/jackus",                                                                                                                                                                                                                                                 
  dirsToCheck = {}                                                                                                                                                                                                                                                            
}                                                                                                                                                                                                                                                                             
auto-session DEBUG: suppress_session didn't find a match, returning false                                                                                                                                                                                                     
auto-session DEBUG: RestoreSessionFromDir start { "/home/jackus/.local/share/nvim/sessions/" }                                                                                                                                                                                
auto-session DEBUG: RestoreSessionFromDir validated session_dir:  /home/jackus/.local/share/nvim/sessions/                                                                                                                                                                    
auto-session DEBUG: get_session_file_name no session_name, using cwd: /home/jackus                                                                                                                                                                                            
auto-session DEBUG: RestoreSessionFromDir escaped session name: %2Fhome%2Fjackus.vim                                                                                                                                                                                          
auto-session DEBUG: RestoreSessionFromDir session does not exist: /home/jackus/.local/share/nvim/sessions/%2Fhome%2Fjackus.vim                                                                                                                                                
auto-session DEBUG: get_session_file_name no session_name, using cwd: /home/jackus                                                                                                                                                                                            
auto-session DEBUG: No session restored, call no_restore hooks   

@cameronr
Copy link
Collaborator

cameronr commented Sep 16, 2024

Ah, it's a typo in the recent config name migration I did:

if Config.auto_restore_last_lession then

It wasn't caught by the unit tests because they use the old config names and when I did the "trivial" test, I typed it using auto-complete so it completed the config name with the typo. I'll get a PR submitted shortly. In the meantime, you can set the old config name and it should work:

auto_session_enable_last_session = true

cameronr added a commit to cameronr/auto-session that referenced this issue Sep 16, 2024
@jack-obrien
Copy link
Author

Perfect! Thank you, that fixes it. still better than vscode

@cameronr
Copy link
Collaborator

@jack-obrien the new config name auto_restore_last_session should now work

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

No branches or pull requests

3 participants