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 load cwd with auto save will save blank session first #60

Closed
josh-nz opened this issue Jun 11, 2024 · 1 comment
Closed

bug: auto load cwd with auto save will save blank session first #60

josh-nz opened this issue Jun 11, 2024 · 1 comment

Comments

@josh-nz
Copy link
Contributor

josh-nz commented Jun 11, 2024

Relates to #55

If configured with autosave.cwd = true and autoload.cwd = true, when starting Neovim M.load in session.lua will try to autosave. It looks like this should be skipped but for whatever reason, autosave_skip() is returning true for me.

This has the follow behaviour:

  1. The cwd json file is parsed first, so session data is in memory.
  2. The cwd session is loaded, triggering autosave
  3. autosave saves the blank Neovim buffers into the cwd session file
  4. session is loaded from data in memory.

While this works, if you have other autosave settings turned off (or Neovim crashes etc), then there is a chance the session will be lost.

Ideally, we skip saving when autoloading from cwd. It looks like this was the intent, and autosave_skip() has a bug. I don't know the nuance of Neovim that the skip function is trying to achieve, but results from my tests are below:

Screen Shot 2024-06-11 at 18 56 29
local function autosave_skip()
    -- Skip scratch buffer e.g. startscreen
    local unscratch_buffers = vim.tbl_filter(function(buf)
        return 'nofile' ~= vim.bo[buf].buftype
    end, vim.api.nvim_list_bufs())
    -- unscratch_buffers is true
    -- next(unscratch_buffers) is true
    -- so return evaluates to false
    return not unscratch_buffers or not next(unscratch_buffers)
end
@jedrzejboczar
Copy link
Owner

Fixed in #55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants