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] Session is not AutoCreated on nvim . #393

Closed
jack-obrien opened this issue Nov 13, 2024 · 3 comments
Closed

[BUG] Session is not AutoCreated on nvim . #393

jack-obrien opened this issue Nov 13, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jack-obrien
Copy link

jack-obrien commented Nov 13, 2024

Describe the bug
A clear and concise description of what the bug is.

When I open a directory with nvim ., auto-session does not save the session. See the additional context - i think it is an issue with allow_files_auto_save

To Reproduce
Steps to reproduce the behavior:

Set the auto_create option to True. cd to a new directory with no saved session named after it. call nvim . No session is created on startup (fair I guess, as there's no session to restore). But still no session is saved on close.

Expected behavior
A clear and concise description of what you expected to happen.
When I run :q after the "To Reproduce" steps, it should create a new session on save.

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

Checkhealth
Paste the contents of checkhealth auto-session here

auto-session: require("auto-session.health").check()

vim options ~
- OK vim.o.sessionoptions

Lazy.nvim settings ~
- OK Lazy.nvim support is enabled
- OK auto-session is not lazy loaded

Config ~
- OK 
  {
    log_level = "debug",
    suppressed_dirs = { "~/", "~/Projects", "~/Downloads", "/" }
  }

General Info ~
- Session directory: /home/grabba/.local/share/nvim/sessions/
- Current session: 
- 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 HP-Workstation 6.8.0-48-generic #48~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct 7 11:24:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
  • Neovim version nvim --version
NVIM v0.10.2
Build type: RelWithDebInfo
LuaJIT 2.1.1713484068

Additional context
I typically run nvim through neovide, but for this report I have just used the command line to call nvim.

With debug enabled, it looks like auto-session thinks my command line argument is a file, not a directory. (This is just when running nvim .)
auto-session DEBUG: args_allow_files_auto_save is false, not enabling restoring/saving

Thanks for reading! Let me know if you need anything else :)

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

cameronr commented Nov 13, 2024

The issue is that nvimtree changes the command line argument before autosession has a chance to see it (changing it from . to NvimTree_1).

To fix, you can lazy load NvimTree:

  1. Change your nvim-tree config to lazy load:
return {
  'nvim-tree/nvim-tree.lua',
  version = '*',
  -- lazy = false,
  cmd = {
    'NvimTreeOpen',
    'NvimTreeClose',
    'NvimTreeToggle',
    'NvimTreeFocus',
    'NvimTreeRefresh',
    'NvimTreeFindFile',
    'NvimTreeFindFileToggle',
    'NvimTreeClipboard',
    'NvimTreeResize',
    'NvimTreeCollapse',
    'NvimTreeCollapseKeepBuffers',
    'NvimTreeHiTest',
  },
  -- can use opts instead of a config function
  opts = {
    sync_root_with_cwd = true,
    renderer = {
      add_trailing = true,
    },
  },
}
  1. This is a weird one, but apparently fidget.nvim has nvimtree support (which triggers loading nvimtree) so you have to lazy load nvim-lspconfig so it doesn't load figet.nvim right away:
...
  {
    -- Main LSP Configuration
    'neovim/nvim-lspconfig',
    event = { 'BufReadPre', 'BufNewFile' },
    dependencies = {
...
  1. Not totally, required, but if you always want to have NvimTree open, you could add no_restore_cmds to your autosession config:
  {
    'rmagatti/auto-session',
    lazy = false,
...
    opts = {
...
      no_restore_cmds = {
        function()
          require('custom.plugins.utils.barbar-tree-offset').toggle()
        end,
      },
    },
  },

@jack-obrien
Copy link
Author

Thank you so much for your detailed help! Lazy loading nvim-tree definitely helped with the path overwriting issue. I found that to disable lazy loading I had to actively specify lazy = true in my nvim-tree options.

@cameronr
Copy link
Collaborator

Glad it's working!

If you specify keys, cmd, event, or ft in a plugin spec, you shouldn't need to explicitly set lazy = true (but you can't have lazy = false as that will force it to be not lazy):

https://lazy.folke.io/spec/lazy_loading
https://lazy.folke.io/spec#spec-lazy-loading

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