nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7k stars 605 forks source link

Vim:E444: Cannot close last window #2191

Closed noahxzhu closed 1 year ago

noahxzhu commented 1 year ago

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

https://user-images.githubusercontent.com/8643866/236633300-7f64f541-1f52-4a8b-9f81-2e9618914d3c.mp4

alex-courtis commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

I was not able to replicate with the above configuration:

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 commented 1 year ago

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

noahxzhu commented 1 year ago

@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

https://user-images.githubusercontent.com/8643866/236850996-e4524483-86e4-4679-9516-292f4ea0f79c.mp4

alex-courtis commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

sajjathossain commented 1 year ago

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

gegoune commented 1 year ago

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