NeogitOrg / neogit

An interactive and powerful Git interface for Neovim, inspired by Magit
MIT License
3.64k stars 218 forks source link

vim.wait must not be called in a lua loop callback #1324

Open Amleto opened 1 month ago

Amleto commented 1 month ago

Description

I get this error message normally after :w a buffer, but I'm not really sure on how to reproduce it consistently.

I was told vim.wait changed in nvim 0.10 so maybe you're more aware of potential fixes/causes.

Neovim version

V0.10 Release Luajit 2.1.1713484068

Operating system and version

Win11/wsl2/Ubuntu 20.04

Steps to reproduce

?

Expected behavior

No errors

Actual behavior

Error executing luv callback:
...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...nt_nvimjveJPB/usr/share/nvim/runtime/lua/vim/_system.lua:98: E5560: vim.wait must not be called in a lua loop callback
stack traceback:
        [C]: in function 'error'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'callback'
        ...are/nvim/lazy/plenary.nvim/lua/plenary/async/control.lua:101: in function 'returned_function'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:31: in function 'callback_or_next'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'step'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:48: in function 'execute'
        ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:118: in function 'fn'
        ...in/.local/share/nvim/lazy/neogit/lua/neogit/lib/util.lua:529: in function <...in/.local/share/nvim/lazy/neogit/lua/neogit/lib/util.lua:526

Minimal config

-- NOTE: See the end of this file if you are reporting an issue, etc. Ignore all the "scary" functions up top, those are
-- used for setup and other operations.
local M = {}

local base_root_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") .. "/.min"
function M.root(path)
  return base_root_path .. "/" .. (path or "")
end

function M.load_plugin(plugin_name, plugin_url)
  local package_root = M.root("plugins/")
  local install_destination = package_root .. plugin_name
  vim.opt.runtimepath:append(install_destination)

  if not vim.loop.fs_stat(package_root) then
    vim.fn.mkdir(package_root, "p")
  end

  if not vim.loop.fs_stat(install_destination) then
    print(string.format("> Downloading plugin '%s' to '%s'", plugin_name, install_destination))
    vim.fn.system({
      "git",
      "clone",
      "--depth=1",
      plugin_url,
      install_destination,
    })
    if vim.v.shell_error > 0 then
      error(string.format("> Failed to clone plugin: '%s' in '%s'!", plugin_name, install_destination),
        vim.log.levels.ERROR)
    end
  end
end

---@alias PluginName string The plugin name, will be used as part of the git clone destination
---@alias PluginUrl string The git url at which a plugin is located, can be a path. See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols for details
---@alias MinPlugins table<PluginName, PluginUrl>

---Do the initial setup. Downloads plugins, ensures the minimal init does not pollute the filesystem by keeping
---everything self contained to the CWD of the minimal init file. Run prior to running tests, reproducing issues, etc.
---@param plugins? table<PluginName, PluginUrl>
function M.setup(plugins)
  vim.opt.packpath = {}                      -- Empty the package path so we use only the plugins specified
  vim.opt.runtimepath:append(M.root(".min")) -- Ensure the runtime detects the root min dir

  -- Install required plugins
  if plugins ~= nil then
    for plugin_name, plugin_url in pairs(plugins) do
      M.load_plugin(plugin_name, plugin_url)
    end
  end

  vim.env.XDG_CONFIG_HOME = M.root("xdg/config")
  vim.env.XDG_DATA_HOME = M.root("xdg/data")
  vim.env.XDG_STATE_HOME = M.root("xdg/state")
  vim.env.XDG_CACHE_HOME = M.root("xdg/cache")

  -- NOTE: Cleanup the xdg cache on exit so new runs of the minimal init doesn't share any previous state, e.g. shada
  vim.api.nvim_create_autocmd("VimLeave", {
    callback = function()
      vim.fn.system({
        "rm",
        "-r",
        "-f",
        M.root("xdg")
      })
    end
  })
end

-- NOTE: If you have additional plugins you need to install to reproduce your issue, include them in the plugins
-- table within the setup call below.
M.setup({
  plenary = "https://github.com/nvim-lua/plenary.nvim.git",
  telescope = "https://github.com/nvim-telescope/telescope.nvim",
  diffview = "https://github.com/sindrets/diffview.nvim",
  neogit = "https://github.com/NeogitOrg/neogit"
})
-- WARN: Do all plugin setup, test runs, reproductions, etc. AFTER calling setup with a list of plugins!
-- Basically, do all that stuff AFTER this line.
require("neogit").setup({}) -- For instance, setup Neogit
CKolkey commented 1 month ago

What buffer are you trying to write to? vim.wait is only used in two places in the code base, and I'm not sure how writing would get there

Amleto commented 1 month ago

Just my own code files (in git repo of course)

CKolkey commented 1 month ago

Is there a neogit window/tab open while you're doing this?

Amleto commented 1 month ago

It normally happens in the workflow where I open the git status, expand the diff of a file, hit enter to go to the file, edit & save.

So neogit is not visible at all when the exception occurs

---- On Fri, 24 May 2024 15:29:44 +0100 @.*** wrote ----

Is there a neogit window/tab open while you're doing this?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

CKolkey commented 1 month ago

Is neogit opened as a tab, or split, or..?

Amleto commented 1 month ago

It's opened via require("neogit").open(). (Full window)

---- On Sat, 25 May 2024 21:43:51 +0100 @.*** wrote ----

Is neogit opened as a tab, or split, or..?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

d-r-jenkins commented 1 month ago

I see the same behaviour using <cmd>Neogit<CR> in a keybinding.

It seems to happen when I save a buffer after having opened Neogit from that buffer and leaving the Neogit window open for a while. I also see that a [No Name] buffer is opened each time I open Neogit and is not closed when I close Neogit, which might be related.

Neovim 0.10 The Neogit commit is 69e0f12 The setup is just require("neogit").setup()

I don't have time to make a minimal config currently, but I might be able to on the weekend if that would be useful.

CKolkey commented 1 month ago

it would be useful :)

I'm going to do my best to deal with this quickly, but personal-life stuff has increased recently, and I'll have a bit less time for this for a little while. Any help would be appreciated, and I don't mind giving pointers if there are questions :)

d-r-jenkins commented 1 month ago

Using commit 37823b4 does not have this issue, but I also think maybe something got updated in plenary, looking at this, and since I am not sure what version of plenary I was using when I had this issue then maybe this has fixed itself...

@Amleto can you sync to the most recent stable versions of Neogit and plenary and see if you still have this issue?

Amleto commented 1 month ago

I did that and have not seen the issue, but I also have not been in neogit as much over the last couple days.

I don't mind if you want to close now or leave it open for a bit.

Amleto commented 1 month ago

I did just see this again. I had just :w in a file, opened neogit status, expanded a hunk then discarded it (x). As soon as I hit q to exit neogit status the exception was thrown

d-r-jenkins commented 1 month ago

Can you share the commits of both neogit and plenary?

Amleto commented 1 month ago

Neogit is 4c5b826 Plenary is a3e3bc8