Skip to content

Vim:E444: Cannot close last window #2191

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

Closed
noahxzhu opened this issue May 6, 2023 · 13 comments · Fixed by #2209
Closed

Vim:E444: Cannot close last window #2191

noahxzhu opened this issue May 6, 2023 · 13 comments · Fixed by #2209
Labels
awaiting feedback bug Something isn't working reproduced Issue confirmed

Comments

@noahxzhu
Copy link

noahxzhu commented May 6, 2023

Description

E5108: Error executing lua: ...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:205: Vim:E444: Cannot close last window
stack traceback:
[C]: in function 'nvim_win_close'
...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:205: in function 'close'
...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:214: in function 'close_this_tab_only'
...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:227: in function 'close'
...y/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:348: in function 'fn'
...ocal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/api.lua:139: in function 'edit'
...ocal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/api.lua:149: in function 'f'
...ocal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/api.lua:32: in function <...ocal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/api.lua:30>

Neovim version

NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

macOS 13.3.1 (a)

nvim-tree version

270c955

Minimal config

{
      sync_root_with_cwd = true,
      respect_buf_cwd = true,
      renderer = {
        group_empty = true,
      },
      update_focused_file = {
        enable = true,
        update_root = true,
      },
      view = {
        adaptive_size = true,
        -- width = 40,
        float = {
          enable = false,
          open_win_config = {
            relative = "editor",
            border = "rounded",
            width = 40,
            height = 100000,
            row = 0,
            col = 0,
          },
        },
      },
      diagnostics = {
        enable = true,
      },
      actions = {
        open_file = {
          resize_window = true,
          quit_on_open = true,
        },
      },
      git = {
        ignore = false,
      },
    },

Steps to reproduce

I enable "actions.open_file.quit_on_open"

reproduce steps:

  1. enter a directory
  2. new a file
  3. open that file

if I disable the "quit_on_open", no this issue there.

Expected behavior

No response

Actual behavior

CleanShot.2023-05-06.at.23.10.01.mp4
@noahxzhu noahxzhu added the bug Something isn't working label May 6, 2023
@alex-courtis
Copy link
Member

Unfortunately I cannot reproduce with "Clean Room" Replication, the file opens without any issue.

It appears that you have many other plugins and automations running that may interfere. Please produce a clean room replicator so that we can reproduce / fix this.

@noahxzhu
Copy link
Author

noahxzhu commented May 7, 2023

@alex-courtis Thank you for your reply, as investigated, it's related to the "noice" plugin

https://github.com/virezox/dotfiles/blob/9a1bbc911ed35433cd09126846b9c24920f53611/.config/nvim/lua/plugins/ui.lua#L184

@noahxzhu noahxzhu closed this as completed May 7, 2023
@noahxzhu noahxzhu reopened this May 7, 2023
@noahxzhu
Copy link
Author

noahxzhu commented May 7, 2023

@alex-courtis this is the minimal config to reproduce

.config/nvim/init.lua

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  {
    "nvim-tree/nvim-tree.lua",
    lazy = true,
    version = "*",
    cmd = {
      "NvimTreeToggle",
    },
    keys = {
      { "<leader>e", "<cmd>NvimTreeToggle<cr>", desc = "Explorer" },
    },
    init = function()
      if vim.fn.argc() == 1 then
        local stat = vim.loop.fs_stat(vim.fn.argv(0))
        if stat and stat.type == "directory" then
          require "nvim-tree"
        end
      end
    end,
    opts = {
      sync_root_with_cwd = true,
      respect_buf_cwd = true,
      renderer = {
        group_empty = true,
      },
      update_focused_file = {
        enable = true,
        update_root = true,
      },
      view = {
        adaptive_size = true,
        -- width = 40,
        float = {
          enable = false,
          open_win_config = {
            relative = "editor",
            border = "rounded",
            width = 40,
            height = 100000,
            row = 0,
            col = 0,
          },
        },
      },
      diagnostics = {
        enable = true,
      },
      actions = {
        open_file = {
          resize_window = true,
          quit_on_open = true,
        },
      },
      git = {
        ignore = false,
      },
    },
  },
  {
    "folke/noice.nvim",
    event = "VeryLazy",
    opts = {
      lsp = {
        -- override markdown rendering so that **cmp** and other plugins use **Treesitter**
        override = {
          ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
          ["vim.lsp.util.stylize_markdown"] = true,
          ["cmp.entry.get_documentation"] = true,
        },
      },
      -- you can enable a preset for easier configuration
      presets = {
        bottom_search = true, -- use a classic bottom cmdline for search
        command_palette = true, -- position the cmdline and popupmenu together
        long_message_to_split = true, -- long messages will be sent to a split
        inc_rename = false, -- enables an input dialog for inc-rename.nvim
        lsp_doc_border = false, -- add a border to hover docs and signature help
      },
    },
  },
  "MunifTanjim/nui.nvim",
  "rcarriga/nvim-notify",
})

@noahxzhu
Copy link
Author

noahxzhu commented May 7, 2023

Just found there's no issue if I close the notify messagebox before I enter the new created file. It looks like the winnr related.

@alex-courtis
Copy link
Member

I was not able to replicate with the above configuration:

  • needed to disable netrw
  • needed to set termguicolours
  • needed to manually :NvimTreeToggle
    Tree quit normally on opening a file.

That is not a clean room configuration - there are a lot of plugins there.

Please produce a Clean Room Replication without lazy or any of the other plugins, except for those absolutely needed to replicate the issue.

@noahxzhu
Copy link
Author

noahxzhu commented May 8, 2023

Ya, I see, it's plugin compatibility issue.

@noahxzhu
Copy link
Author

noahxzhu commented May 8, 2023

@alex-courtis

Minimal config

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
	require("packer").startup({
		{
			"wbthomason/packer.nvim",
			"nvim-tree/nvim-tree.lua",
			"nvim-tree/nvim-web-devicons",
			-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
			"folke/noice.nvim",
			"MunifTanjim/nui.nvim",
		},
		config = {
			package_root = package_root,
			compile_path = install_path .. "/plugin/packer_compiled.lua",
			display = { non_interactive = true },
		},
	})
end
if vim.fn.isdirectory(install_path) == 0 then
	print("Installing nvim-tree and dependencies.")
	vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
	require("nvim-tree").setup({
		actions = {
			open_file = {
				quit_on_open = true,
			},
		},
	})

	require("noice").setup()
end

reproduce steps:

  1. open a directory via "nvim -nu /tmp/nvt-min.lua ."
  2. toggle nvim-tree
  3. create a new file
  4. press enter on that file
CleanShot.2023-05-08.at.22.13.42.mp4

@alex-courtis
Copy link
Member

Reproduced with clean room config:

E5108: Error executing lua: ...vt-dev/site/pack/packer/start/dev/lua/nvim-tree/view.lua:205: Vim:E444: Cannot close last
window
stack traceback:
        [C]: in function 'nvim_win_close'
        ...vt-dev/site/pack/packer/start/dev/lua/nvim-tree/view.lua:205: in function 'close'
        ...vt-dev/site/pack/packer/start/dev/lua/nvim-tree/view.lua:214: in function 'close_this_tab_only'
        ...vt-dev/site/pack/packer/start/dev/lua/nvim-tree/view.lua:227: in function 'close'
        ...acker/start/dev/lua/nvim-tree/actions/node/open-file.lua:348: in function 'fn'
        ...nvt-dev/site/pack/packer/start/dev/lua/nvim-tree/api.lua:139: in function 'edit'
        ...nvt-dev/site/pack/packer/start/dev/lua/nvim-tree/api.lua:149: in function 'f'
        ...nvt-dev/site/pack/packer/start/dev/lua/nvim-tree/api.lua:32: in function <...nvt-dev/site/pack/packer/start/dev/lua/nvim-tree/api.lua:30>

@alex-courtis alex-courtis added reproduced Issue confirmed and removed awaiting feedback labels May 13, 2023
@alex-courtis
Copy link
Member

alex-courtis commented May 13, 2023

This is timing related - problem only occurs when opening the file whilst the noice info messages is shown.

Removing view._prevent_buffer_override() from the autocommand results in the same behaviour.

@alex-courtis
Copy link
Member

The issue appears to be that noice creates 2 new floating windows for the message.

@virezox I would be most grateful if you tested a fix:

cd /path/to/nvim-tree.lua
git pull
git checkout 2191-disregard-floating-windows-when-opening-window-on-edit

@noahxzhu
Copy link
Author

@alex-courtis Perfect, it was fixed as tested.

@sajjathossain
Copy link

@alex-courtis I'm getting this error and I don't use noice.

@gegoune
Copy link
Collaborator

gegoune commented Jul 17, 2023

Please open new issue following clean room replication. https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting#clean-room-replication

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

Successfully merging a pull request may close this issue.

4 participants