folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.3k stars 344 forks source link

bug: lazy window backdrop doesn't disappear when closing in plugin setup #1390

Closed aarondill closed 6 months ago

aarondill commented 6 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0-dev-2702+g0c0be09ea-dirty

Operating system/version

Arch Linux

Describe the bug

On startup, Lazy opens when plugins are missing. I have a plugin spec (for dashboard-nvim) which closes the window if it's open. It doesn't clear the backdrop when closing.

Steps To Reproduce

  1. nvim -nu repro.lua
  2. Clean nvim-treesitter (any plugin) (the repro does this for you)
  3. Open nvim
  4. Wait for it to install
  5. Notice darkened editor

Expected Behavior

Remove the backdrop on close

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/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", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "nvim-treesitter/nvim-treesitter" }, -- Any plugin works, just need something to cause lazy to open
  {
    "echasnovski/mini.animate", -- any plugin, just using for `event =`
    event = "VimEnter", -- This doesn't work as a normal autocmd. I don't know why.
    opts = function()
      if vim.o.filetype == "lazy" then
        vim.cmd.close()
      end
    end,
  },
}
require("lazy").setup(plugins, { install = { colorscheme = { "tokyonight-night" } } }) -- It's more obvious with tokyonight
require("lazy").clean({ plugins = { "nvim-treesitter" }, show = false }) -- Make repro easier by making this idempotent
folke commented 6 months ago

Should be fixed now.

It seems that Neovim does not execute WinClosed autocmds before VimEnter. Added an extra check on VimEnter to see if the window was already closed for cleanup.