echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.99k stars 184 forks source link

Error on confirming edit in mini.files when cwd isn't trimmed #1240

Open doomgutt opened 1 week ago

doomgutt commented 1 week ago

Contributing guidelines

Module(s)

mini.files

Description

The issue happens when i'm trying to confirm an edit to a file/folder that is deep in the folder hierarchy - most prominently during re-naming and moving location of files and folders. Creation and deletion seems to work fine.

Specifically for me the issue starts to occur at about five folders deep: root/one/two/three/four/five/. I don't know if the error occurs due to index depth issues or because the root folder gets hidden due to screen size limitation.

Thanks for your attention.

Neovim version

0.10.1

Steps to reproduce

  1. Create a directory ~5-6 layers deep from root: root/one/two/three/four/five/six
  2. Create some files with mini.files in the deepest directory and try renaming them, the error should occur.

Alternatively, if it's a screen size problem - make enough directories for the root to not be visible.

Here are the relevant setup files:

init.lua


-- Clone 'mini.nvim' manually in a way that it gets managed by 'mini.deps'
local path_package = vim.fn.stdpath('data') .. '/site/'
local mini_path = path_package .. 'pack/deps/start/mini.nvim'
if not vim.loop.fs_stat(mini_path) then
    vim.cmd('echo "Installing `mini.nvim`" | redraw')
    local clone_cmd = { 'git', 'clone', '--filter=blob:none', 'https://github.com/echasnovski/mini.nvim', mini_path }
    vim.fn.system(clone_cmd)
    vim.cmd('packadd mini.nvim | helptags ALL')
    vim.cmd('echo "Installed `mini.nvim`" | redraw')
end

-- Set up 'mini.deps' (customize to your liking)
require('mini.deps').setup({
    path = {
        package = path_package
    }
})

-- Use 'mini.deps'. `now()` and `later()` are helpers for a safe two-stage
-- startup and are optional.
local add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later

-- || SETTINGS || =============================================================
now(function()
    vim.g.mapleader = " "
    vim.g.maplocalleader = " "
    vim.opt.isfname:append '@-@'
    vim.opt.relativenumber = true
    vim.opt.scrolloff = 8
    vim.opt.tabstop = 4
    vim.opt.softtabstop = 4
    vim.opt.shiftwidth = 4
    vim.opt.signcolumn = "yes"
    vim.opt.colorcolumn = "80"
    vim.opt.swapfile = false
    vim.opt.undofile = true
    vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
    vim.opt.listchars = { tab = "  ", trail = " ", nbsp = " " }
end)

now(function() require("plugins.mini-files") end) <-------- MINI FILES -------

-- keymaps
later(function()
    vim.keymap.set("n", "-", MiniFiles.open, { desc = "Open MiniFiles" })
end)

plugins/min-files.lua

require('mini.files').setup({
    -- Customization of shown content
    content = {
      -- Predicate for which file system entries to show
      filter = nil,
      -- What prefix to show to the left of file system entry
      prefix = nil,
      -- In which order to show file system entries
      sort = nil,
    },

    -- Module mappings created only inside explorer.
    -- Use `''` (empty string) to not create one.
    mappings = {
      close       = 'q',
      go_in       = 'l',
      go_in_plus  = 'L',
      go_out      = 'h',
      go_out_plus = 'H',
      reset       = '<BS>',
      reveal_cwd  = '@',
      show_help   = 'g?',
      synchronize = '=',
      trim_left   = '<',
      trim_right  = '>',
    },

    -- General options
    options = {
      -- Whether to delete permanently or move into module-specific trash
      permanent_delete = true,
      -- Whether to use for editing directories
      use_as_default_explorer = true,
    },

    -- Customization of explorer windows
    windows = {
      -- Maximum number of windows to show side by side
      max_number = math.huge,
      -- Whether to show preview of file/directory under cursor
      preview = true,
      -- Width of focused window
      width_focus = 50,
      -- Width of non-focused window
      width_nofocus = 15,
      -- Width of preview window
      width_preview = 80,
    },
})

Expected behavior

Normal file/directory renaming functionality

Actual behavior

The error specifically is:

                                                                                                                                                                                                3,17-15       All
CONFIRM FILE SYSTEM ACTIONS

~/projects/dotfiles/nvim/nvim-mini/one/two/three/four/five
  RENAME │ bingo => asdfs.ts

E5108: Error executing lua: ...e/nvim/site/pack/deps/start/mini.nvim/lua/mini/files.lua:1482: Invalid window id: 1064
stack traceback:
        [C]: in function 'nvim_win_get_buf'
        ...e/nvim/site/pack/deps/start/mini.nvim/lua/mini/files.lua:1482: in function 'explorer_refresh'
        ...e/nvim/site/pack/deps/start/mini.nvim/lua/mini/files.lua:820: in function <...e/nvim/site/pack/deps/start/mini.nvim/lua/mini/files.lua:812>
Press ENTER or type command to continue

which seems to happen in the same function as the error in these issues: #477 #606 .

echasnovski commented 1 week ago

Thanks for the issue!

Indeed, I can reproduce. This seems to happen when the current branch is too deep to fit all windows including preview. I'll look into it after the next 'mini.nvim' release.