nvim-neotest / neotest

An extensible framework for interacting with tests within NeoVim.
MIT License
2.22k stars 107 forks source link

vimL function must not be called in a lua loop callback #19

Closed kristijanhusak closed 2 years ago

kristijanhusak commented 2 years ago

Hi,

I tried setting this up this plugin for lua testing, but I'm not able to make it work. I'm gettings this error:

Error executing luv callback:                                                                                                                                                                                                         
...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:14: The coroutine failed with this message: ...nux64/share/nvim/runtime/lua/vim/treesitter/language.lua:17: E5560: vimL function must not be called in a lua loop callback
stack traceback:
        [C]: in function 'error'
        ...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:14: in function 'callback_or_next'
        ...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:40: in function <...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:39>

Here's how I produce it:

Use this minimal.lua:

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",
      "nvim-lua/plenary.nvim",
      "nvim-treesitter/nvim-treesitter",
      "antoinemadec/FixCursorHold.nvim",
      "rcarriga/neotest",
      "rcarriga/neotest-plenary",
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
    },
  })
end

_G.load_config = function(is_initial)
  if is_initial then
    vim.cmd([[runtime plugin/nvim-treesitter.lua]])
    vim.cmd([[TSUpdateSync lua]])
  end

  require("neotest").setup({
    adapters = {
      require("neotest-plenary"),
    },
  })
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
  load_plugins()
  require("packer").sync()
  vim.cmd([[autocmd User PackerCompileDone ++once lua load_config(true)]])
else
  load_plugins()
  load_config()
end

Screenshot:

screenshot

System info:

rcarriga commented 2 years ago

Thanks for the report, this was due to a recent change. Should be working in latest master, let me know if not :smile:

kristijanhusak commented 2 years ago

Working great now, thanks!

stevearc commented 2 years ago

Ack! Apologies. This didn't come up in my testing for some reason.

rcarriga commented 2 years ago

Actually just saw this was happening silently when I tested which is why it ran so fast... It just wasn't running :laughing: Didn't spot it because I just saw the files being found. Still runs about twice as fast though after this fix so still massive win!

stevearc commented 2 years ago

The fastest code is the code that doesn't run 😆