nvim-neotest / neotest-plenary

MIT License
32 stars 11 forks source link

[Bug] This module errors if neotest is lazy loaded #3

Closed akinsho closed 1 year ago

akinsho commented 1 year ago

For some reason I'm yet to determine trying to lazy load neotest causes just this adapter to break, saying that neotest.async cannot be found. On checking if neotest.async is loaded, it is available in neovim and other adapters for other languages work without issue. Only this adapter seems not to work.

In this case, I am lazy loading neotest using

    use({
      'nvim-neotest/neotest',
      setup = conf('neotest').setup,
      config = conf('neotest').config,
      module = 'neotest',
      requires = {
        { 'rcarriga/neotest-plenary', module = 'neotest-plenary' },
        { 'sidlatau/neotest-dart', module = 'neotest-dart' },
        { dev('personal/neotest-go'), module = 'neotest-go' },
      },
    })

I had a look at the _G._run_tests function this plugin uses but can't follow why it doesn't pick up neotest async

akinsho commented 1 year ago

Sorry closed it since I thought this was still user error but, I don't think so. I think there is something odd about how things are being loaded that makes this plugin hard to lazy load

rcarriga commented 1 year ago

Can you try adding neotest.async to the modules that cause neotest to load?

akinsho commented 1 year ago

@rcarriga I've tried adding it using module as well as packers module_pattern tbh using module means that the pattern used to search all required modules will be ^neotest which should match neotest.async but tried ^neotest%.async as a pattern and I still get the error

akinsho commented 1 year ago

Not sure if you use packer but are you able to test lazy loading it with module and seeing if that works for you?

rcarriga commented 1 year ago

Yeah I don't seem to have the same issue

    use({
      maybe_local("neotest"),
      config = "require('config.neotest').post()",
      keys = "<leader>n",
      requires = {
        { "akinsho/neotest-go", module = "neotest-go" },
        { maybe_local("neotest-python"), module = "neotest-python" },
        { maybe_local("neotest-plenary"), module = "neotest-plenary" },
        { maybe_local("neotest-vim-test"), module = "neotest-vim-test" },
        { "rouge8/neotest-rust", module = "neotest-rust" },
      },
    })

Everything loads fine for me :thinking:

rcarriga commented 1 year ago

What does your config look like? Are you loading neotest-plenary before loading neotest? Another random idea is to add require("neotest") to the top of neotest-plenary's init.lua before it requires the async module

rcarriga commented 1 year ago

Ah never mind, I didn't run the tests. I see now you were talking an error in the output. So this runs a neovim sub-process which doesn't use your init.lua and so neotest must be loaded by being in a package. I've added a packadd neotest call to load it if it's an optional package, so you should now see it working

akinsho commented 1 year ago

That fixes the issue for me thanks 👍🏿, yeah sorry I should have clarified that the issue was in the output of the tests when you run them