jedrzejboczar / possession.nvim

Flexible session management for Neovim.
MIT License
368 stars 19 forks source link

Buffers are closed after PossessionLoad or PossessionSave #4

Closed RaafatTurki closed 2 years ago

RaafatTurki commented 2 years ago

this has been driving me up the wall for the past 30 mins, why does my lua buffer close after a session save and why doesn't it show when I load said session. I've tried configuring it so it closes nothing and still got the same result.

https://asciinema.org/a/CeVVGybVHbj0Z1JXvoZ2JWCKE

minimal config on NVIM v0.7.0-dev+1275-g00effff56

return require('packer').startup(function()
        use 'wbthomason/packer.nvim'

        use {
                'jedrzejboczar/possession.nvim',
                requires = { 'nvim-lua/plenary.nvim' },
                config = function() require('possession').setup{
                        silent = false,
                        load_silent = false,
                        debug = true,
                        plugins = {
                                close_windows = false,
                                delete_hidden_buffers = false,
                                nvim_tree = false,
                                tabby = false,
                        },
                } end
        }
end)
RaafatTurki commented 2 years ago

just tried it on NVIM v0.6.1 and it works great sighs any clue why that's the case, I've got a couple things that use 0.7 functionality so I can't simply rollback

polak-jan commented 2 years ago

I have encountered what sound like the same issue, specifically I was able to figure out that the issue seems to be that the mksession output does not include any of the buffer information when used by this plugin. But running it manually within the same config does work as expected, and I don't see anything in the code that would cause this either.

jedrzejboczar commented 2 years ago

This is strange behaviour, I tried to reproduce the problem but I'm not able to. I used the same Neovim version NVIM v0.7.0-dev+1275-g00effff569 with the following minimal_init.lua:

vim.opt.runtimepath = vim.opt.runtimepath + './possession.nvim'
vim.opt.runtimepath = vim.opt.runtimepath + './plenary.nvim'

require('possession').setup {
    silent = false,
    load_silent = false,
    session_dir = '/tmp/possession',
    debug = true,
    plugins = {
        close_windows = false,
        delete_hidden_buffers = false,
        nvim_tree = false,
        tabby = false,
    },
}

then starting with nvim --clean -u minimal_init.lua test.lua (running inside ~/.local/share/nvim/site/pack/packer/start). Both saving and loading work without issues.

I wonder what could cause the buffer closing before (or after?) session save. Could this be somehow related to other plugins? Can you try to run with the same commands as I did (with --clean).

Or maybe you could try using verbose to debug what is happening. You would need to issue the following commands:

set verbosefile=/tmp/verbose.log
set verbose=15

then save the session and exit. Then you can check the file to search for autocommands that could be responsible for closing the buffer. You can use lower verbose level if there are too many logs.

RaafatTurki commented 2 years ago

@jedrzejboczar

then starting with nvim --clean -u minimal_init.lua test.lua

What's test.lua, you've only provided minimal_init.lua

(running inside ~/.local/share/nvim/site/pack/packer/start)

I don't really understand what you mean by that as that's where packer is installed.

I'm not an expert in nvim debugging as you could tell hahah

polak-jan commented 2 years ago

I jusked checked with the minimal config and it does work fine, will keep digging further.

polak-jan commented 2 years ago

It seems like the autocmd causing it is from neo-tree, specifically this function which is called on BufWinEnter through their own event system, because BufDelete is triggered right after it, but I can't really see anything obvious in that function that could cause something like this.

RaafatTurki commented 2 years ago

the issue happened in the minimal init.lua that I've pasted in the issue, the only plugins installed were packer and possession, I also don't use neotree.

I guess this is what you get when you live on the edge, since I really like this plugin I'm rolling back to 0.6.1, global statusline and full lua support can wait a bit longer

jedrzejboczar commented 2 years ago

@jedrzejboczar

then starting with nvim --clean -u minimal_init.lua test.lua

What's test.lua, you've only provided minimal_init.lua

(running inside ~/.local/share/nvim/site/pack/packer/start)

I don't really understand what you mean by that as that's where packer is installed.

I'm not an expert in nvim debugging as you could tell hahah

No problem :P This test.lua was some random file that I only used to check if its buffer will be closed. And the reason I started from ~/.local/share/nvim/site/pack/packer/start is because when you start Neovim with nvim --clean it won't load any plugins. So in the minimal_init.lua that I provided there are lines with vim.opt.runtimepath = ... that manually add plugin directories to the list of searched directories. This way only these two plugins will be loaded.

the issue happened in the minimal init.lua that I've pasted in the issue, the only plugins installed were packer and possession, I also don't use neotree.

You were probably running without --clean, so some other plugins may be loading from runtimepath. It may also load the packer-compiled code. Or did you actually remove (or didn't have) any other plugins from the path where packer stores plugins?

It seems like the autocmd causing it is from neo-tree, specifically this function which is called on BufWinEnter through their own event system, because BufDelete is triggered right after it, but I can't really see anything obvious in that function that could cause something like this.

Thanks for looking into it. To be able to help with this I need to find a way to reproduce the problem. I will try to install neo-tree when I have a moment to debug this issue. But if @RaafatTurki is not using neo-tree at all, there might be other plugin causing the problem :/ I wonder why changing version to 0.6.1 solves the issue. One guess would be that there is a plugin that has some functionality that is only enabled when version 0.7 is detected. If that's not a problem @RaafatTurki could you provide a list of plugins you use?

polak-jan commented 2 years ago

The only other autocmds in the verbose log are from luasnip but those only trigger after the buffers are closed so they don't seem to be the cause of it. I will try debugging it further today.

jedrzejboczar commented 2 years ago

I finally reproduced this and found a stupid error - strange that I didn't notice it earlier. Please confirm that https://github.com/jedrzejboczar/possession.nvim/commit/ac58abd802625a67005e4c515f2d0383bbf8d904 fixes the issue.

polak-jan commented 2 years ago

Yes, that seems to have fixed it. Thank you!

jedrzejboczar commented 2 years ago

Thanks for finding the issue :)