Skip to content
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

Error: Cannot close last window #308

Closed
yetyetanotherusername opened this issue Jun 24, 2024 · 7 comments
Closed

Error: Cannot close last window #308

yetyetanotherusername opened this issue Jun 24, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@yetyetanotherusername
Copy link

yetyetanotherusername commented Jun 24, 2024

Describe the bug
Whenever I start neovim in my home folder and try to switch to a session with session-lens, I get the following error

Error executing vim.schedule lua callback: ...al/share/nvim/lazy/auto-session/lua/auto-session/lib.lua:196: Vim:E444: Cannot close last window                                                                                                 
stack traceback:                                                                                                                                                                                                                               
        [C]: in function 'nvim_win_close'                                                                                                                                                                                                      
        ...al/share/nvim/lazy/auto-session/lua/auto-session/lib.lua:196: in function 'close_unsupported_windows'                                                                                                                               
        ...l/share/nvim/lazy/auto-session/lua/auto-session/init.lua:399: in function 'AutoSaveSession'                                                                                                                                         
        ...y/auto-session/lua/auto-session/session-lens/actions.lua:53: in function ''                                                                                                                                                         
        vim/_editor.lua: in function ''                                                                                                                                                                                                        
        vim/_editor.lua: in function <vim/_editor.lua:0>

To Reproduce
Steps to reproduce the behavior:

  • cd to /home/username
  • call up session-lens telescope window & try to switch to any saved session

cd-ing to the folder of a saved session and opening neovim there works as expected, also from there switching with session-lens works. It is only when I open neovim in my user home that switching via session-lens does not work.

Expected behavior
auto-session opens the saved session chosen via session-lens

Baseline (please complete the following information):

  • Result of set sessionoptions?:
    image

  • OS. e.g uname -a neofetch:

OS: Fedora Linux 40 (Workstation Edition) x86_64 
Host: 30E5000DGE ThinkStation P350 
Kernel: 6.9.4-200.fc40.x86_64 
Uptime: 3 hours, 54 mins 
Packages: 2912 (rpm) 
Shell: bash 5.2.26 
Resolution: 3840x2160 
DE: GNOME 46.2 
WM: Mutter 
WM Theme: Adwaita 
Theme: Adwaita-dark [GTK2/3] 
Icons: Adwaita [GTK2/3] 
Terminal: kitty 
CPU: 11th Gen Intel i9-11900 (16) @ 5.000GHz 
GPU: Intel RocketLake-S GT1 [UHD Graphics 750] 
Memory: 9219MiB / 31440MiB 
  • Neovim version nvim --version
NVIM v0.10.0
Build type: RelWithDebInfo
LuaJIT 2.1.1713773202
@yetyetanotherusername yetyetanotherusername added the bug Something isn't working label Jun 24, 2024
@rmagatti
Copy link
Owner

rmagatti commented Jun 24, 2024

Ah I see. One of the latest features (closing unsupported windows) doesn't seem to account for this scenario. 👍
@cameronr fyi

@doanhtu07
Copy link

doanhtu07 commented Jun 25, 2024

Second this. My case is inconsistent. Sometimes it throws an error, and sometimes it doesn't. When it throws an error, Neovim either crashes and stuck (This only happened twice today, and that was how I knew the error came from auto-session); or Neovim exits successfully without even letting me check the error.

All I did was enter Neovim and then exit it right after (No edit or anything)

My setup for auto-session

return {
  "rmagatti/auto-session", -- This plugin is for restoring session from our last work period
  config = function()
    local auto_session = require("auto-session")

    auto_session.setup({
      auto_restore_enabled = false,
      auto_session_suppress_dirs = { "~/", "~/Downloads", "~/Documents", "~/Desktop/" },
    })

    local keymap = vim.keymap

    keymap.set("n", "<leader>wr", "<cmd>SessionRestore<CR>", { desc = "Restore session for cwd" }) -- restore last workspace session for current directory
    keymap.set("n", "<leader>ws", "<cmd>SessionSave<CR>", { desc = "Save session for auto session root dir" }) -- save workspace session for current working directory
  end,
}

Specifically, the error is at this code snippet.

  vim.api.nvim_create_autocmd({ "VimLeavePre" }, {
    group = group,
    pattern = "*",
    callback = function()
      if not vim.g.in_pager_mode then
        AutoSession.AutoSaveSession()
      end
    end,
  })

@yetyetanotherusername
Copy link
Author

yetyetanotherusername commented Jun 26, 2024

Thank you guys for having a look. 🙏

In the meantime I have resorted to setting close_unsupported_windows = false in my auto-session config and everything works as expected. 👌

@cameronr
Copy link
Collaborator

i have a fix that wraps close_unsupported_windows in a pcall but i'm looking more closely at this.

@cameronr
Copy link
Collaborator

@rmagatti PR for this is #309. Let me know what you think.

@rmagatti
Copy link
Owner

Should be fixed with @cameronr's PR. Thanks, you've been a big help!
@yetyetanotherusername hopefully this fixes it for you 🙏

@yetyetanotherusername
Copy link
Author

Can confirm the error when using close_unsupported_windows = true is fixed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants