nvim-neotest / neotest

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

Neotest watch toggle fails with LazyVim #460

Open rbhanot4739 opened 1 month ago

rbhanot4739 commented 1 month ago

NeoVim Version

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1725453128

Describe the bug I am running LazyVim with python and test extra and for some reason running the Neotest watch toggle and looking for neotest help pages breaks for me. When I run require("neotest").watch.toggle(vim.fn.expand("%")) via <leader>tw I get the following error trace

E5108: Error executing lua: ...bhanot/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:100: Async task failed without callback: The coroutine failed with this message: 
...e/nvim/lazy/neotest/lua/neotest/consumers/watch/init.lua:36: attempt to call field 'supports_method' (a table value)
stack traceback:
    ...e/nvim/lazy/neotest/lua/neotest/consumers/watch/init.lua: in function 'get_valid_client'
    ...e/nvim/lazy/neotest/lua/neotest/consumers/watch/init.lua:51: in function 'get_lsp_client'
    ...e/nvim/lazy/neotest/lua/neotest/consumers/watch/init.lua:110: in function 'watch'
    ...e/nvim/lazy/neotest/lua/neotest/consumers/watch/init.lua:160: in function 'func'
    ...bhanot/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:173: in function <...bhanot/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:172>
stack traceback:
    [C]: in function 'error'
    ...bhanot/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:100: in function 'close_task'
    ...bhanot/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:122: in function 'step'
    ...bhanot/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:150: in function 'toggle'
    ...im/lazy/LazyVim/lua/lazyvim/plugins/extras/test/core.lua:117: in function <...im/lazy/LazyVim/lua/lazyvim/plugins/extras/test/core.lua:117>

To Reproduce

  1. Load LazyVim with above config and open a python file.
  2. Press <leader>tw or run =require("neotest").watch.toggle(vim.fn.expand("%")) to toggle test watch.
nvim --clean -u minimal.lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out, "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({

  spec = {
    -- add LazyVim and import its plugins
    {
      "LazyVim/LazyVim",
      import = "lazyvim.plugins",
    },
    { import = "lazyvim.plugins.extras.test.core" },
    { import = "lazyvim.plugins.extras.dap.core" },
    { import = "lazyvim.plugins.extras.lang.python" },
    { import = "plugins.neotest" },
  },
})

Contents of lua/plugins/neotest.lua

return {
  "nvim-neotest/neotest",
  keys = {
    {
      "<leader>tT",
      function()
        require("neotest").run.run(LazyVim.root())
      end,
      desc = "Run All Test Files",
    },
  },

  opts = {
    adapters = {
      ["neotest-python"] = {
        dap = { justMyCode = true },
        pytest_discover_instances = true,
      },
    },
  },
}
fredrikaverpil commented 1 month ago

Please see https://github.com/nvim-neotest/neotest/pull/456

rbhanot4739 commented 1 month ago

Any ETA on when this would be merged ?

rcasia commented 1 month ago

This issue is solved as https://github.com/nvim-neotest/neotest/pull/456 is already merged.