olimorris / persisted.nvim

💾 Simple session management for Neovim with git branching, autoloading and Telescope support
MIT License
418 stars 24 forks source link

[Bug]: Unable to turn off autosaving #54

Closed ewok closed 1 year ago

ewok commented 1 year ago

Your Persisted.nvim config

{
        save_dir = "sessions/",
        autoload = false,
        autosave = false,
}

Error messages

No response

Describe the bug

What I expect to happen

Not saved session

What actually happens

Session is saved

I did some small research. I guess it is related to the https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/init.lua#L148-L153 block.

Small test:

local function check(conf)
    if (conf.options.autosave and type(conf.options.should_autosave) == "function")
        and not conf.options.should_autosave()
    then
        print("not saving")
    else
        print("saving")
    end
end

-- Works as expected
-- autosave = true and should_autosave = true
local config1 = {}
config1.options = {}
config1.options.autosave = true
config1.options.should_autosave = function()
    return true
end

check(config1)
-- output: saving

-- Doesn't work as expected
-- autosave = false and should_autosave = true
local config2 = {}
config2.options = {}
config2.options.autosave = false
config2.options.should_autosave = function()
    return true
end

check(config2)
-- output: saving

-- Works as expected
-- autosave = true and should_autosave = false
local config3 = {}
config3.options = {}
config3.options.autosave = true
config3.options.should_autosave = function()
    return false
end

check(config3)
-- output: not saving

-- Doesn't work as expected
-- autosave = false and should_autosave = false
local config4 = {}
config4.options = {}
config4.options.autosave = false
config4.options.should_autosave = function()
    return false
end

check(config4)
-- output: saving

Reproduce the bug

Setup minimal.lua with my config.

1 Enter vim.

  1. Escape vim.
  2. ls sessions/ | wc -l
  3. in sessions folder is a saved session.

Final checks

Harsha9554 commented 1 year ago

yeah, I'm facing the same issue too. I hope we get a fix I love the plugin so much but I am unable to turn off autosaving. please help if there is a fix.

olimorris commented 1 year ago

@ewok thanks for raising this.

To confirm my understanding is correct, you expect:

  1. When autosave = false, Persisted should never save a session automatically
  2. Only when autosave = true should the plugin call the should_autosave function and based on it boolean output, save the session

The above is what the plugin should do and appreciate at the minute it doesn't.

ewok commented 1 year ago

@olimorris Yes that's right. imho autosave = false should completely turn off the autosaving, but it does't. Thank you!

olimorris commented 1 year ago

This should be fixed in PR #56. Can you guys confirm?

EDIT: I've also allowed for :SessionSave to override the autosave = false config option. Thoughts being that you may wish to manually save the session

ewok commented 1 year ago

@olimorris confirming! Now works like a charm. Thank you so much 👍🏼

ewok commented 1 year ago

closing