nvim-neotest / neotest

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

[BUG] attempt to yield across C-call boundary #167

Closed wookayin closed 1 year ago

wookayin commented 1 year ago

NeoVim Version NVIM v0.9.0-dev-2887+g234b8c5f3 NVIM v0.8.1 and v0.7.0

Describe the bug When opening a neotest window or running neotest, an attempt to yield across C-call boundary error happens sometimes.

E5108: Error executing lua .../.vim/plugged/neotest/lua/neotest/lib/file/init.lua:183: attempt to yield across C-call boundary
stack traceback:
        [C]: in function 'fs_realpath'
        .../.vim/plugged/neotest/lua/neotest/lib/file/init.lua:183: in function 'real'
        .../.vim/plugged/neotest/lua/neotest/adapters/init.lua:40: in function 'f'
        .../.vim/plugged/neotest/lua/neotest/lib/func_util/init.lua:10: in function 'map'
        .../.vim/plugged/neotest/lua/neotest/adapters/init.lua:36: in function 'adapters_matching_open_bufs'
        .../.vim/plugged/neotest/lua/neotest/client/init.lua:463: in function '_update_adapters'
        .../.vim/plugged/neotest/lua/neotest/client/init.lua:436: in function '_start'
        .../.vim/plugged/neotest/lua/neotest/client/init.lua:156: in function 'ensure_started'
        .../.vim/plugged/neotest/lua/neotest/client/init.lua:166: in function 'get_position'
        .../.vim/plugged/neotest/lua/neotest/client/init.lua:118: in function <.../.vim/plugged/neotest/lua/neotest/client/init.lua:117>
        .../.vim/plugged/neotest/lua/neotest/consumers/run.lua:32: in function 'get_tree_from_args'
        $HOME/.config/nvim/lua/config/testing.lua:134: in function 'open'
        [string ":lua"]:1: in main chunk

where my config/testing.lua is

    local pos = neotest.run.get_tree_from_args(args)      -- args is usually {}

To Reproduce Please provide a minimal init.lua to reproduce which can be run as the following:

nvim --clean -u minimal.lua

You can edit the following example file to include your adapters and other required setup.

-- ignore default config and plugins
vim.opt.runtimepath:remove(vim.fn.expand("~/.config/nvim"))
vim.opt.packpath:remove(vim.fn.expand("~/.local/share/nvim/site"))
vim.opt.termguicolors = true

-- append test directory
local test_dir = "/tmp/nvim-config"
vim.opt.runtimepath:append(vim.fn.expand(test_dir))
vim.opt.packpath:append(vim.fn.expand(test_dir))

-- install packer
local install_path = test_dir .. "/pack/packer/start/packer.nvim"
local install_plugins = false

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.cmd("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
  vim.cmd("packadd packer.nvim")
  install_plugins = true
end

local packer = require("packer")

packer.init({
  package_root = test_dir .. "/pack",
  compile_path = test_dir .. "/plugin/packer_compiled.lua",
})

packer.startup(function(use)
  use("wbthomason/packer.nvim")

  use({
    "nvim-neotest/neotest",
    requires = {
      "vim-test/vim-test",
      "nvim-lua/plenary.nvim",
      "nvim-treesitter/nvim-treesitter",
      "antoinemadec/FixCursorHold.nvim",
    },
    config = function()
      require("neotest").setup({
        adapters = {},
      })
    end,
  })

  if install_plugins then
    packer.sync()
  end
end)

vim.cmd([[
command! NeotestSummary lua require("neotest").summary.toggle()
command! NeotestFile lua require("neotest").run.run(vim.fn.expand("%"))
command! Neotest lua require("neotest").run.run(vim.fn.getcwd())
command! NeotestNearest lua require("neotest").run.run()
command! NeotestDebug lua require("neotest").run.run({ strategy = "dap" })
command! NeotestAttach lua require("neotest").run.attach()
command! NeotestOutput lua require("neotest").output.open()
]])

Steps to reproduce the behavior:

  1. Open any python file
  2. :lua require"neotest".run.get_tree_from_args({})
  3. See error

Expected behavior No errors. This function used to work well before updating neotest.

Logs No relevant logs

Additional context N/A

wookayin commented 1 year ago

Looking at the source code, neotest.run.get_tree_from_args is usually wrapped with async.run as the function async.uv.fs_realpath works asynchronously. Wrapping the function call in my config properly with neotest.async solves the issue, but not sure why it was not throwing previously.

rcarriga commented 1 year ago

The get_tree_from_args function is not a public facing function. It is an async function so it must be wrapped with async.run. The fact that it worked before is just coincidental.

wookayin commented 1 year ago

I see. Thanks. I found that this is a private function, but I don't think I had other choices to implement #50. Closing as we know why this error was happening.