rmagatti / auto-session

A small automated session manager for Neovim
MIT License
1.26k stars 47 forks source link

[ Bug ] cmdheight after restore is incorrect #64

Closed Chaitanyabsprip closed 2 years ago

Chaitanyabsprip commented 3 years ago

Screenshot 2021-09-02 at 18 34 46

If neovim is closed with nvim-tree open, this is caused.

jameshiew commented 3 years ago

On Linux, working around this currently by putting 'silent !kill -s SIGWINCH $PPID' in post_restore_cmds during plugin setup, so Neovim gets resized after a session is restored.

See https://github.com/neovim/neovim/issues/11330

Chaitanyabsprip commented 3 years ago

I am using MacOS Big Sur 11.5.2

rmagatti commented 3 years ago

This happens to me too (though not all the time). I just quickly resize the terminal and get the correct sizes back. I don't think it's something this plugin can solve though.

A better idea is what @jameshiew mentions so the resizing happens automatically instead of doing it manually.

kunzaatko commented 2 years ago

This happens to me too (though not all the time). I just quickly resize the terminal and get the correct sizes back. I don't think it's something this plugin can solve though.

A better idea is what @jameshiew mentions so the resizing happens automatically instead of doing it manually.

I think I figured out what is causing this issue. This is either a popupwindow or a notification from the nvim-notify plugin. When the session is saved when a popup or the notify buffer is open (a notification is visible) it saves it too. I currently do not have any idea how to solve this but I guess this issue should be reopened @rmagatti. It could possibly be solved by calling automatic :bd on the buffers of the notifications in the pre_save_callback function but I don't currently know, how to distinguish them from the other buffers (I don't know how to get the buffertypes, but that could probably be a distinguishing feature)... Any idea?

rmagatti commented 2 years ago

I actually feel pretty strongly about adding specific code to work around what/how other plugins do things. As in I don't think it's the right call to do so. The hooks exist for this very reason, so people can customize things before and after session loading happens, auto-session can't conceivably cover every possible edge case for every possible plugin.

As for how one would do this through the hooks, by quickly looking at nvim-notify code, I can't really see a specific thing that can be used to identify a notification buffer, at least from a quick skim. The author of that plugin might be able to tell you more about it.

kunzaatko commented 2 years ago

I actually fully back you in this. I agree that it wouldn't be hygienic to specify exceptions for other plugins. To clarify, I am suggesting to reopen the issue, until we find a solution using hooks and then documenting the solution in the wiki or the docs under Troubleshooting. I also browsed the code of nvim-notify and I didn't land on any straightforward solution. How do you feel about this?

rmagatti commented 2 years ago

I'm okay with that suggestion. Reopening 👍

ok-nick commented 2 years ago

I had this issue with neovim 0.6.0, but after upgrading to 0.7.0 the issue was fixed.

EDIT: nvm I just got lucky

rockyzhang24 commented 2 years ago

This issue exists in not only this plugin, but other session management plugins like vim-startify. Floating window is the culprit. When we save the session, if there are floating windows open, then the floating window information will be recored into the session file and they cannot be restored correctly when we load the session in the future.

I am using nvim-treesitter-context, fidget.nvim and nvim-scrollview and all of them will bring about this problem. One workaround is close all the floating windows before saving the session. The code below can be a reference.

function M.close_all_floating_wins()
  for _, win in ipairs(vim.api.nvim_list_wins()) do
    local config = vim.api.nvim_win_get_config(win)
    if config.relative ~= "" then
      vim.api.nvim_win_close(win, false)
      -- print('Closing window', win)
    end
  end
end
kunzaatko commented 2 years ago

I will test this and if it works well for this issue, will add it under troubleshooting. @rmagatti, could you enable wiki for this repo? I don't think this and any other issue fix should pollute the README... right?

rmagatti commented 2 years ago

Sounds good!

kunzaatko commented 2 years ago

Unfortunately, I still cannot add a wikipage it seems. The wiki exists but there must be some kind of switch for letting people add pages... However, here is what I am suggesting:


Issue: cmdheight after restore is incorrect

description: On restore the cmdheight (location where ex commands can be written) spans almost the full window.

Issue: cmdheight after restore is incorrect

cause: Floating windows are not saved correctly in sessions. This means that when a floating window is present when the session is saved the parameters of the window are saved into the session but it does not include the window being floating.

fix: You can register a callback function for removing all the floating windows on save of a session. auto-session allows to do this by the conf key pre_save_cmds.

function _G.close_all_floating_wins()
  for _, win in ipairs(vim.api.nvim_list_wins()) do
    local config = vim.api.nvim_win_get_config(win)
    if config.relative ~= '' then
      vim.api.nvim_win_close(win, false)
    end
  end
end

-- ...

require('auto-session').setup {
  -- ...
  pre_save_cmds = { _G.close_all_floating_wins },
  -- ...
}

(credits: @rockyzhang24)


I have it now in my forked repo wiki entry here: https://github.com/kunzaatko/auto-session/wiki/Troubleshooting

@rmagatti could you either flip the switch in the settings (if there is any) so that I can add it by myself or copy it in? Thanks :)

rockyzhang24 commented 2 years ago

An addition:

If the floating windows were closed by pre_save hook, we can restore them (or part of) by post_save hook. For example, nvim-treesitter-context and nvim-scrollview show context information and scrollbar via floating windows. Before saving a session, we use the script above to close them. After saving, we can enable them by their builtin commands like TSContextEnable and ScrollViewEnable via post_save hook.

Thanks.

rmagatti commented 2 years ago

@kunzaatko odd, wiki is enabled, I wonder if there are any permission settings. 🤔

rmagatti commented 2 years ago

I guess I had to add the first page? I'll copy that over tomorrow if you really can't add it there. 👍

kunzaatko commented 2 years ago

No, unfortunately it still does not allow me to add the page.

0x7a7a commented 2 years ago

This issue exists in not only this plugin, but other session management plugins like vim-startify. Floating window is the culprit. When we save the session, if there are floating windows open, then the floating window information will be recored into the session file and they cannot be restored correctly when we load the session in the future.

I am using nvim-treesitter-context, fidget.nvim and nvim-scrollview and all of them will bring about this problem. One workaround is close all the floating windows before saving the session. The code below can be a reference.

function M.close_all_floating_wins()
  for _, win in ipairs(vim.api.nvim_list_wins()) do
    local config = vim.api.nvim_win_get_config(win)
    if config.relative ~= "" then
      vim.api.nvim_win_close(win, false)
      -- print('Closing window', win)
    end
  end
end

@rmagatti How about using this code as an option?

rockyzhang24 commented 2 years ago

@0x7a7a Some floating windows cannot be closed completely using this piece of code. For example, I cannot close the floating windows of fidget.nvim using this code. I already posted an issue in fidget.nvim repo and am waiting for the author's response.

0x7a7a commented 2 years ago

@rockyzhang24 I saw your issue in fidget. I think fidget's FidgetClose can only deal with the state of the fidget after it's finished running, not while it's running. This is a fidget problem, not auto-session. Let's see how to solve this very distressing problem

rmagatti commented 2 years ago

@kunzaatko I've updated the wiki, thanks for that!

@0x7a7a I don't use any of those plugins myself so I haven't really tested this but this does look like it should work! Some plugins including my goto-preview for example set properties on the floating windows so they are identifiable by the plugin, those could be used here if you can find out if any of those plugins do that too.

rockyzhang24 commented 2 years ago

With this commit (https://github.com/neovim/neovim/commit/3fe6bf3a1e50299dbdd6314afbb18e468eb7ce08) merged, this issue is solved. It ignores the floating windows when we save the session, so no disordered layout when we restore it.

This issue can be closed.

kunzaatko commented 2 years ago

Great! This means that the page in the wiki is no longer necessary and can be dropped. Again, unfortunately, I can not edit it... Can you remove it, please, @rmagatti?

rockyzhang24 commented 2 years ago

The page can still be left there for a while at least wait until neovim 0.8 release. I believe most users will persist on the stable neovim version or use an older one, and they still need that snippet.

pronvis commented 10 months ago

I have same issue with NVIM v0.9.4 and use('tpope/vim-obsession'). What is interesting - I have vim.opt.cmdheight = 2 at 41 line in set.lua and if I open nvim with nvim -S -V9nvimlog to restore session from Session.vim and save log file. In log file I found:

  cmdheight=1
    Last set from ~/config_repo/nvim/lua/pronvis/set.lua line 41

which is weird...