folke / lazy.nvim

šŸ’¤ A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.6k stars 353 forks source link

Buffer not cleared out when pressing `q` with startify installed #81

Closed seblj closed 1 year ago

seblj commented 1 year ago

Describe the bug If I have startify installed and use the keymap q mapped by lazy.nvim to quit the popup window. If I then press q that startify has mapped to quit, it can't quit because of the buffer from lazy.nvim

Which version of Neovim are you using? v0.9.0-dev-521+g1c4794944

To Reproduce Make sure to read https://github.com/folke/lazy.nvim/wiki/Minimal-%60init.lua%60-to-Reproduce-an-Issue

Steps to reproduce the behavior:

  1. Use the config with nvim -u repro.lua
  2. Open lazy popup with Lazy
  3. Quit it with q
  4. Try to quit startify with q

Expected Behavior I expect it to quit neovim when pressing q in startify buffer.

Screenshots

https://user-images.githubusercontent.com/5160701/208999455-8c59175e-78ce-41bc-904d-c35334bf724a.mov

You can see from the screenshot that the second time I open neovim and not open a lazy popup window, it is possible to close with q like normal. But when I open a lazy popup window, it is not possible

repro.lua ```lua 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", "--single-branch", "https://github.com/folke/lazy.nvim.git", lazypath, }) end vim.opt.runtimepath:prepend(lazypath) -- install plugins local plugins = { -- do not remove the colorscheme! "folke/tokyonight.nvim", "mhinz/vim-startify", -- add any other pugins here } require("lazy").setup(plugins, { root = root .. "/plugins", }) -- add anything else here vim.opt.termguicolors = true -- do not remove the colorscheme! vim.cmd([[colorscheme tokyonight]]) ```

Log Please include any related errors from the Noice log file. (open with :Lazy log)

Lazy log
```

   lazy.nvim (H)   Install (I)   Update (U)   Sync (S)   Clean (X)   Check (C)   Log (L)   Restore (R)   Profile (P)   Debug (D)   Help (?)  

  Total: 4 plugins

  Breaking Changes (1)
    ā— lazy.nvim 2.78ms ļ„”  init.lua
        fd1fbef feat(checker): defer checker to after VeryLazy to make sure nvim-notify and others are loaded (33 minutes ago)
        58f0876 fix: removed spell again from site. not needed. can download in config/spell (2 hours ago)
        94d0125 fix(rtp): keep site in rtp (2 hours ago)
        6dbcdce chore(build): auto-generate vimdoc (2 hours ago)
        1fb10b9 docs: 'cmd' repeat twice (#75) (2 hours ago)
        472a091 chore(main): release 5.2.0 (#55) (3 hours ago)
        f0e1b85 feat: make hover easy to override (3 hours ago)
        2ab6518 fix(keys): feedkeys should include pending keys. Fixes #71 (3 hours ago)
        d34a02d ci: Update issue templates (3 hours ago)
        2fd78fb fix(help): sort tags files for readmes so tags work properly. Fixes #67 (3 hours ago)
        eab449b build: added .repro and debug to .gitignore (3 hours ago)
        b7c489b fix(loader): lua modules can be links instead of files. Fixes #66 (5 hours ago)
        7a57ea2 chore(build): auto-generate vimdoc (6 hours ago)
        c228908 fix(health): don't show warning on `module=false` (6 hours ago)
        b68f94b ci: Update issue templates (6 hours ago)
        bbebb67 ci: Update issue templates (6 hours ago)
        95fc814 chore(build): auto-generate vimdoc (6 hours ago)
        876f7bd feat(loader): allow to add extra paths to rtp reset. Fixes #64 (6 hours ago)
        a345649 fix(cache): if we can't load from the cache modpath, find path again instead of erroring right away (7 hours ago)
        bbace14 fix(git): only mark a plugin as dirty if an update changed the commit HEAD. Fixes #62 (7 hours ago)
        a939243 fix(checker): allow git checks only for non-pinned plugins (#61) (7 hours ago)
        57bea32 chore(build): auto-generate vimdoc (7 hours ago)
        ff24f49 fix(loader): source rtp `/plugin` files after loading start plugins. Fixes (7 hours ago)
        b802729 chore(build): auto-generate vimdoc (10 hours ago)
        9dfefac docs: fixed indentation of auto-generated code blocks (10 hours ago)
        71b2e2f docs: lazy works on all OSs now (10 hours ago)
        232232d fix(ui): install command can have plugins as a parameter (10 hours ago)
        4ca3039 feat(loader): warn when mapleader is changed after init (11 hours ago)
        540847b fix: strip `/` from dirs. Fixes #60 (11 hours ago)
        86eaa11 fix(git): dereference tag refs. Fixes #54 (11 hours ago)
        e95da35 feat(util): utility method to get sync process output (11 hours ago)
        3c3a711 chore(build): auto-generate vimdoc (13 hours ago)
        44f80a7 feat(plugin): allow plugin files only without a main plugin module. Fixes #53 (13 hours ago)
        f5734f5 chore(build): auto-generate vimdoc (13 hours ago)
        3814883 fix(ui): set current win only when its valid (13 hours ago)
        3a7b8c8 chore(main): release 5.1.0 (#30) (22 hours ago)
        3606d62 fix: add after directories to rtp to make after/ftplugin and others work. Fixes #47 (22 hours ago)
        b193f96 fix(spec): only process a spec once (22 hours ago)
        7be46bc style: removed unused requires (23 hours ago)
        897d6df fix: add filetype to window buffer. (#41) (24 hours ago)
        14300b3 chore(build): auto-generate vimdoc (24 hours ago)
        78e9d6c docs: add a note about mapleader (24 hours ago)
        06ac8bd perf(ui): clear existing extmarks before rendering (25 hours ago)
        ffcd0ab fix(loader): source filetype.lua before plugins. Fixes #35 (25 hours ago)
        9d12cdc fix(git): don't run git log for submodules. Fixes #33 (26 hours ago)
        06ffcf5 chore(build): auto-generate vimdoc (26 hours ago)
        7fb0652 docs: added docs on update checker (26 hours ago)
        1f86cb3 chore(build): auto-generate vimdoc (26 hours ago)
        3cffb2a docs: added change detection to the readme (26 hours ago)
        6c767a6 feat: added options to configure change detection. Fixes #32 (26 hours ago)
        cd162f3 chore(build): auto-generate vimdoc (26 hours ago)
        941df31 feat(ui): make the windoww size configurable. Fixes #34 (26 hours ago)
        5298441 fix: use nvim_feekeys instead of nvim_input for keys handler. Fixes #28 (27 hours ago)
        2927b05 docs: added lincense (28 hours ago)
        4d78203 chore(main): release 5.0.1 (#17) (29 hours ago)
        1371a14 fix(build): use the shell to execute build commands (29 hours ago)
        ffabe91 fix(cache): if mod is loaded already in the loader, then return that (29 hours ago)
        316503f fix: dont autoload cached modules when module=false (30 hours ago)
        992c679 fix: always set Config.me regardless of reset rtp (30 hours ago)
        df6c986 fix: add neovim libs to rtp for treesitter parsers etc (31 hours ago)
        49b69b7 chore(build): auto-generate vimdoc (31 hours ago)
        e9d3a73 fix: default logs are now since 3 days ago to be in line with the docs (31 hours ago)
        4234322 chore(build): auto-generate vimdoc (32 hours ago)
        6e32759 fix: deepcopy lazyspec before processing (32 hours ago)
        ec0f8d0 docs: added config.dev.path to the example (32 hours ago)
        6404d42 fix: move re-sourcing check to the top (32 hours ago)
        ddf36d7 fix: checker should not error on non-existing dirs (32 hours ago)
        50ba619 test: fix tests (32 hours ago)
        f78d8bf fix: show error when merging, but continue (32 hours ago)
        b8a0055 chore(build): auto-generate vimdoc (33 hours ago)
        1754056 fix: use jobstart instead of system to open urls (33 hours ago)
        5ecc988 docs: use https to bootstrap lazy (33 hours ago)
        ae644a6 fix: only run updated checker for installed plugins. Fixes #16 (34 hours ago)
        7225b05 chore(build): auto-generate vimdoc (34 hours ago)
        17fd57a docs: added docs for statusline and count (34 hours ago)
        48a596e chore(build): auto-generate vimdoc (35 hours ago)
        dfe8a65 docs: removed extra performance section (35 hours ago)
        1fa2d87 docs: moved my dots to structuring plugins (35 hours ago)
        9916318 chore(build): auto-generate vimdoc (35 hours ago)
        abe026a docs: added section on performance (35 hours ago)
        82aea47 chore(build): auto-generate vimdoc (35 hours ago)
        72d66cd docs: updated lua stuff (35 hours ago)
        ca43018 chore(build): auto-generate vimdoc (35 hours ago)
        36cb7ea docs: migration guide (35 hours ago)
        2f59ead chore(main): release 5.0.0 (#12) (35 hours ago)
        dbcf675 chore(build): auto-generate vimdoc (35 hours ago)
        b906ad9 docs: added windows to supported platforms (35 hours ago)
        cb87aa3 ci: run tests on linux only for nw (2 days ago)
        75a36f3 chore(build): auto-generate vimdoc (2 days ago)
        af87108 fix(util): fixed double slashes (2 days ago)
        62c1542 fix(cache): normalize paths (2 days ago)
        bb1c2f4 feat: added support for Windows (2 days ago)
        198963f feat: utility method to normalize a path (2 days ago)
        a189883 fix: check for installed plugins with plain find (2 days ago)
        833b387 chore(build): auto-generate vimdoc (2 days ago)
        ff89319 docs: removed dots from features (2 days ago)
        b7bf18a style: spelling (2 days ago)
        66dad89 chore(build): auto-generate vimdoc (2 days ago)
        0c0b8b7 docs: todo (2 days ago)
        92fd0d4 docs: updated installation and structuring plugins (2 days ago)
        1baa92f docs: added docs on `` and `` (2 days ago)
        d827d8a docs: collapse semver examples (2 days ago)
        1e16363 chore(build): auto-generate vimdoc (2 days ago)
        980cfa9 docs: added config example when not using a Nerd Font (2 days ago)
        713dcb6 build: added markdownlint config (2 days ago)
        706fe6f chore(build): auto-generate vimdoc (2 days ago)
        5ed9855 feat: added completion for all lazy commands (2 days ago)
        b462787 docs: added optional plugins to docs for commands and methods (2 days ago)
        f29f3d2 chore(build): auto-generate vimdoc (2 days ago)
        1efa710 feat: added `module=false` to skip auto-loading of plugins on `require` (2 days ago)
        55d194c chore(build): auto-generate vimdoc (2 days ago)
        bac34cc docs: added section on uninstalling (2 days ago)
        c065ca2 chore(build): auto-generate vimdoc (2 days ago)
        2dd6230 feat: added `:Lazy load foobar.nvim` to load a plugin (2 days ago)
        8a0da3b config: move lazy cache to state/nvim/lazy/cache (2 days ago)
        7eb6034 chore(build): auto-generate vimdoc (2 days ago)
        6567580 chore: todo (2 days ago)
        6f00cde docs: typos (2 days ago)
        faac2dd perf(cache): cache loadfile and no find modpaths without package.loaders (2 days ago)
        32f2b71 fix(cache): do a fast check to see if a cached modpath is still valid. find it again otherwise (2 days ago)
        1fe43f3 fix(ui): focus Lazy window when auto-installing plugins in `VimEnter` (2 days ago)
        d4aee27 feat!: removed the LazyUpdate etc commands. sub-commands only from now on (3 days ago)

  Log (1)
    ā— tokyonight.nvim 0.1ms ī«“ start
        8b55a47 fix: revert last change (22 hours ago)
        ce92e5b chore(docs): auto generate vimdoc (23 hours ago)
        1356b20 fix: always clear before setting colorscheme (23 hours ago)

  Clean (1)
    ā—‹ lazy.nvim

  Loaded (1)
    ā— vim-startify 0.35ms ī«“ start
```
max397574 commented 1 year ago

I think this isn't a problem with the mapping I just checked and the mapping is exactly the same as it was before opening the buffer

perhaps some autocommands get deleted if you leave and reenter the buffer or sth like that

folke commented 1 year ago

This is indeed not a problem with lazy. I assume startify simply doesnt exit Neovim when another buffer or window has been created in the meantime

seblj commented 1 year ago

This is indeed not a problem with lazy. I assume startify simply doesnt exit Neovim when another buffer or window has been created in the meantime

The startify mapping works perfectly fine if I use :q<CR>, :close<CR> or anything like that on the lazy buffer, so I think it's a bit fast to say that it's definitely not a problem with lazy and the close() function that it is mapped to.

folke commented 1 year ago

As I said, startify checks if any other buffers are present: https://github.com/mhinz/vim-startify/blob/81e36c352a8deea54df5ec1e2f4348685569bed2/autoload/startify.vim#L1008

When you close the Lazy window, a new buffer (3) gets created, by something. I can assure you it's not Lazy that's doing that.

Because there's then 2 buffers left, startify wont close Neovim. as I mentioned before

seblj commented 1 year ago

As I said, startify checks if any other buffers are present: https://github.com/mhinz/vim-startify/blob/81e36c352a8deea54df5ec1e2f4348685569bed2/autoload/startify.vim#L1008

When you close the Lazy window, a new buffer (3) gets created, by something. I can assure you it's not Lazy that's doing that.

Because there's then 2 buffers left, startify wont close Neovim. as I mentioned before

I tried to look into this a bit more, and I think I found the issue. I don't know why it happens, but I assume it has something to do with vim.api.nvim_win_close(). It states in the docs that The buffer will become hidden, even if 'hidden' is not set..

If I change the order of the functions to close the window, and then delete the buffer if it is valid, the issue not there anymore. I think there is something weird happening if the buffer is deleted before the window is closed.

diff --git a/lua/lazy/view/init.lua b/lua/lazy/view/init.lua
index b2fcbb9..e82f644 100644
--- a/lua/lazy/view/init.lua
+++ b/lua/lazy/view/init.lua
@@ -102,12 +102,12 @@ function M.show(mode)
     M._buf = nil
     vim.diagnostic.reset(Config.ns, buf)
     vim.schedule(function()
-      if vim.api.nvim_buf_is_valid(buf) then
-        vim.api.nvim_buf_delete(buf, { force = true })
-      end
       if vim.api.nvim_win_is_valid(win) then
         vim.api.nvim_win_close(win, true)
       end
+      if vim.api.nvim_buf_is_valid(buf) then
+        vim.api.nvim_buf_delete(buf, { force = true })
+      end
     end)
   end

Would you be willing to accept a PR with that change @folke ?