-
-
Notifications
You must be signed in to change notification settings - Fork 47
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] Error restoring session! ... Vim(help):E661: Sorry, no help for #325
Comments
Thanks for sending a precise repro! There isn't much we can do about the error as it's generated by neovim directly. That said, removing
Which raises the question of what the docs should recommend. On one hand, some folks may like to have |
How about analysing session file before loading and doing |
Or just adding their paths to some variable to make just a help files loadable even without Lazy knowledge? |
Or try to restore session as is, detect (and hide) an error, and in case of error TEMPORARY remove |
Those are some interesting ideas but probably too niche / too variable for a good heuristic to cover enough of the cases to be worth doing, IMO. Have you seen anything similar for something other than help pages?
I tested this case and it won't work. It seems like |
I'm not sure is there are other similar issues. After all, it's not about "help pages" per se, it's about lazy loading - which affect only |
A session file is just a series of vim commands that are run when the session is sourced and it's explicitly a help command that's failing in this issue: ...
exe '2resize ' . ((&lines * 31 + 32) / 65)
argglobal
enew | setl bt=help
help todo-comments.nvim.txt@en
balt a/a2.txt
setlocal keymap=
... I was asking if there are other cases of things not loading correctly other than help to see if there's a more generalized problem or if it's a problem that only shows up for help pages for things that have been lazy loaded. |
Does it work if you set the plugin as a dependency of auto-session like so? --[[ Minimal config to reproduce issues ]]
--
-- Usage: `nvim -u repro.lua`
-- 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',
'--single-branch',
'https://github.com/folke/lazy.nvim.git',
lazypath,
}
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
'folke/tokyonight.nvim',
-- add any other plugins here
{
'rmagatti/auto-session',
version = '*',
lazy = false, -- Needs to restore session on Neovim start.
init = function()
vim.opt.sessionoptions:append 'winpos'
vim.opt.sessionoptions:append 'localoptions'
end,
dependencies = {
"folke/todo-comments.nvim"
},
config = true,
},
{
'folke/todo-comments.nvim',
version = '*',
lazy = true, -- Must be loaded but not critical, so let's use event VeryLazy.
event = 'VeryLazy',
},
}
require('lazy').setup(plugins, {
root = root .. '/plugins',
})
vim.cmd.colorscheme 'tokyonight'
-- add anything else here The reason I ask is because I agree with @cameronr here that there's probably not a good heuristic to solve this, parsing the vim session file and forcing a specific order of plugin loading feels risky at best and like overreach from auto-session at worst; if adding plugins you normally have buffers open for in your sessions as a dependency solves the issue, that sounds like the more user-driven approach since everyone will have their own versions of this. This isn't a final opinion by any means but it's at least what's going through my head on this one so far |
I don't have some specific help files open "normally". Any one of them can be opened. So this way we effectively disable lazy loading for all plugins. |
As described in #337, I think we can actually keep loading the session file even if there are errors. I whipped up a test branch if you want to give it a try. You'll have to update your auto-session config as follows: -- 'rmagatti/auto-session', After changing the config, you'll have to open Lazy and update the plugin to actually pull it down (and restart nvim just to be sure) |
I just retested your repro case and it will show an error on loading the session but it will still restore the session as desired. You will still have to re-enable autosaving in that case, tho, as we disable it when there's an error |
Sounds like it makes more harm than good. This way we not only get partially restored session but also will lose all changes in that session if user forgets to re-enable autosaving (and user will forget it for sure). |
My point is: auto-saving is much more valuable than auto-restoring everything. |
Maybe I wasn't clear, the new behavior in that branch will restore as much of the session as possible (instead stopping at the first error like before), so I think that's strictly better. Disabling of autosave if there's an error is the same as it was before and I think that's the safer default as it gives the user time to debug the error if they want to. I could imagine a setting (eg 'disable_autosave_on_restore_error') that could be set to false for those that want to keep autosave on even after an error. The other option is having an 'on_restore_error' hook that would let the user decide the behavior (eg they could re-enable auto saving in that case). i probably lean towards the hook as the more general solution. @rmagatti any preference? |
Debugging is a valid reason but most users are not interested in this so it (disabling autosave on restore error) shouldn't be default behaviour IMO. |
This setting is true by default not because of debugging, but because if the session is saved after errors occur it can essentially cause undefined behaviour. At times I'd see errors for things that weren't valid anymore but because the session was saved after the errors occurred, some errors would manifest on load. So ultimately this is done to protect the user against much more frustrating behaviour down the road |
@rmagatti Can you please provide an example of such an issue? Probably I miss something, but I can't see how this may hurt UX. After session (partially) fails to restore I see these possible cases:
Also, let's consider user got error on restore and did nothing because of this (didn't re-enabled autosave or saved session manually - I suppose this will happens in most cases but it's a speculation of course). I suppose in this case user gets same error on next nvim start anyway - how it's differ from the case you've explained when auto-enabled autosave after error will save session which will error on restore? |
The misconception here is that these are the only possibilities. The third possibility is that the session saves with invalid configs, then suppose you go ahead the fix the errors in your config, you then attempt to restore that session and keep getting the same errors, you're left wondering why the fix in your config doesn't seem to take effect; until you delete the "corrupted" session file and create a new session, the error remains. This was the real reason for disabling auto save after errors restoring, like I mentioned, it leads to undefined behaviour but it also leads to issues that are hard to notice and fix when "corrupted sessions" are saved. |
You're right, this might happens sometimes. But isn't such a differences between current config and config in a saved session are anyway possible even without obvious errors on restore? AFAIR it often happens in workflow like this:
Still, I'd prefer to have a "broken" session with my files than a "bad surprise" when all my changes in a current session will be just lost. Is there any other possibilities to solve such an UX issue? Maybe it's possible to just ask user to save current "broken" session or not on some event like |
I do see where you're coming from on this. Here's my take:
The user can then control the behaviour themselves, but by default the current behaviour is safer and has already saved me personally many times from long session debugging so I am not willing to change that up. Thanks for the input on this so far! |
Describe the bug
If session file contains help buffers from plugins which will be loaded after VimEnter then session restore fails.
To Reproduce
Save as
repro.lua
:Then:
Expected behavior
I expect to restore at least all other buffers/windows/tabs, excluding missing help files, but only ones which was restored before this error are actually restored.
Baseline (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: