folke / persistence.nvim

💾 Simple session management for Neovim
Apache License 2.0
591 stars 26 forks source link

lack of compatability with `autochdir` #42

Closed n-crespo closed 3 weeks ago

n-crespo commented 6 months ago

I noticed there is no documentation about compatibility with the autochdir option, and as far as I can tell this plugin occasionally breaks when the option is set to true. (autochdir will change the current directory to the path to the current open buffer whenever a new buffer is opened or switched to)

Here is an example scenario what I experienced before I disabled this option:

"keymaps.lua" [New] 60L, 2754B
WARNING: The file has been changed since reading it!!!
Do you really want to write to it (y/n)?

This doesn't happen when autochdir is set to false.

Rizhiy commented 6 months ago

I guess forcibly changing cwd to original before saving the session might make it work.

1. Save cwd to session file 4. Save as normal 5. Navigate to stored wd before loading session

But curdir is supposed to take care of that, maybe it is loaded in wrong order? Looking at session file, the cwd is stored correctly, so not sure why files are not loading properly. I guess the problem lies with other buffers opening before and changing cwd. Need to probably disable autochdir while the session is being loaded. There is SessionLoad variable which gets set, can probably use that to disable autochdir during session loading.

Rizhiy commented 6 months ago

I have my own function to automatically change directory, I've added the following snippet to make it working properly:

if vim.g.SessionLoad == 1 then return end

I think autochdir might be a wider neovim bug. Actually, I've just tested and can't reproduce what you are describing, autochdir works properly for me. What neovim version are you on? I'm on 0.9.4

n-crespo commented 6 months ago

I'm on 0.9.5, and honestly I haven't had this problem in a while since I've just disabled autochdir. Thanks for the help though!

P.S. Just tried it again and I got the same error. I noticed that for a brief period Lualine shows the correct path to the file, (lua/config/keymaps.lua), then changes to just display keymaps.lua, meaning that it is in the current working directory, which is just ~/.config/nvim. I think it may be the fault of some other plugin causing problems but I couldn't guess for the life of me. It also seems to happen even when only one buffer is loaded.

P.P.S. Correction:

These are the error messages I'm getting

21:39:40 msg_show "lua/config/keymaps.lua" 
21:39:40 msg_show "lua/config/keymaps.lua" 94L, 4381B
21:39:42 msg_show "keymaps.lua" 
21:39:42 msg_show "keymaps.lua" [New] 94L, 4381B
21:39:44 msg_show "keymaps.lua" 
21:39:44 msg_show WARNING: The file has been changed since reading it!!!
21:39:44 msg_show return require'lazyvim.util'.ui.statuscolumn(...)

P.P.P.S. Not sure it's related but the path on lualine seems to always change at the exact same time as the LSP loading information pops up in the bottom right of Neovim (I think this is nvim-notify)... so this might be lua_ls's doing.

Disabling lua_ls makes the problem goes away. I'm blaming either lua_ls or some LSP configuration in LazyVim.

what I did: (besides sacrificing lua_ls)

return {
  {
    "neovim/nvim-lspconfig",
      servers = {
        lua_ls = { enabled = false },
      }, 
    }
  },
}
github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

n-crespo commented 3 weeks ago

Closing this since I haven't experienced it in a while. I think the problem may have been that I was restoring the session before lualine could fully load.