Neogit breaks when using Noice.nvim
Description
Everytime after confirming a commit on neogit, it spams an error. I noticed that it only happens when noice.nvim plugin is enabled. LazyGit works fine with noice.
Neovim version
NVIM v0.9.0 Build type: Release LuaJIT 2.1.0-beta3
Operating system and version
NixOS 23.11.20230523.d30
Steps to reproduce
- Enable noice.nvim and neogit
- Stage files and try to commit
- Confirm commit
Expected behavior
Message was succesfully commited after confirmation with no errors.
Actual behavior
Neogit spam an error after confirming the commit, it keeps showing up until I close neovim entirely!
Minimal config
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup({
{
"wbthomason/packer.nvim",
{
"TimUntersberger/neogit",
requires = {
{ "nvim-lua/plenary.nvim" },
{ "sindrets/diffview.nvim" },
},
config = function()
print("loaded neogit")
require("neogit").setup()
end,
},
},
{
"folke/noice.nvim",
event = "VeryLazy",
config = function()
require("noice").setup {
lsp = {
hover = {
enabled = false,
},
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true,
},
signature = {
enabled = false,
},
},
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
},
}
end,
dependencies = {
"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 neogit and dependencies.")
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
I also encountered the exact same issue when a confirmation dialogue popped up, though I haven't used noice in some time.
Seems to perhaps be an issue with vim.fn.confirm no longer blocking the editor as it is now async as it needs to display a floating window render it.
I am not sure how noice does it; the default vim behaviour of vimscript confirm() is to stop/freeze everything and render a special prompt in the echo area, and then resume the scripting engine from where it was, none the wiser of the time passed.
https://github.com/folke/noice.nvim/issues/388 https://github.com/folke/noice.nvim/issues/337 https://github.com/folke/noice.nvim/issues/232 https://github.com/neovim/neovim/issues/20416 (maybe)
Solution proposed: https://github.com/folke/noice.nvim/issues/232#issuecomment-1408183649
PR in neogit https://github.com/TimUntersberger/neogit/pull/441 with some opinionated and breaking changes. I will resurrect the discussion there and see what we can do.
Thank you for your help in bringing this up.
If its a problem of vim.fn.confirm being called from BufUnload (and causing buffer switching due to the nui popup), then could a potential solution be to simply "save" the contents of the buffer (and whatever is needed) and defer doing the actual work to after BufUnload? Like using vim.schedule or vim.defer_fn.
I've got some ideas for this - might be able to get to it soon.