folke / persistence.nvim

💾 Simple session management for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: Sessions start saving/restoring intermittently when using the util.project extra in LazyVim.

catdadcode opened this issue · comments

Did you check docs and existing issues?

  • I have read all the persistence.nvim docs
  • I have searched the existing issues of persistence.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.10.0-dev-1325+gc4f8be464-Homebrew (true for stable nvim as well)

Operating system/version

Windows 11 Pro (build 22621.2428, 22H2)

Describe the bug

For some reason this is most prevalent from within my ~/.dotfiles repository, but it happens in other project directories as well. Persistence would often load old sessions and they would seem to get "stuck", meaning the same session would always load no matter how I modified things after restoring it. If I quit Neovim, re-open, and restore the session it would restore a session from further back. This same session would keep loading for every restore no matter how it got modified, but every once in a while it would somehow miraculously save a new session that would then also get stuck.

I am relatively new to Vim/Neovim within the last 6 months and I lack the skills to track this down easily so I just lived with it for a while since it seemed to work like 60-70% of the time in most of my projects. Then I redid my config switching over to use the :LazyExtras instead of hardcoding the extra specs. I forgot to re-include the util.project extra. I noticed right away that my sessions were working flawlessly. I figured some bug had been fixed and shrugged. Then I realized a bit ago that I forgot the project extra and enabled it. Immediately reproduced the session issue.

Sure enough I can reproduce it consistently by enabling/disabling the project extra. Project extra was not so special that I couldn't live without it so I've just removed it for now, but figured I ought to let ya know 🙂.

PS - I made an educated guess about which project I should log this issue with and chose the one experiencing the issues first. Do let me know if I should instead open this issue over at ahmedkhalf/project.nvim.

Steps To Reproduce

  1. Setup a default LazyVim starter config.
  2. Install the util.project extra.
  3. Try to modify sessions from within a repository directory.
  4. Quit nvim, re-open, restore previous session.

Do this a few times and you should hopefully reproduce the intermittent session saving behavior.

Expected Behavior

I expected persistence.nvim and project.nvim to operate as expected regardless of the presence of the other.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/persistence.nvim",
  "ahmedkhalf/project.nvim" --via the extra
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("gruvbox")
-- add anything else here

Oh and I did clear the sessions directory regularly while verifying this bug (~/.local/state/nvim/sessions). Forgot to mention that.

I'm pretty sure that's because project.nvim changes your current directory.
persistence saves sessions based on the cwd.
You can disable that option in projects.nvim I believe

Oh that makes sense. Thank you. I'll go see about disabling that option and try again 🙂