nvim-neotest / neotest

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

Lazy load adapters #428

Open rokbot opened 5 months ago

rokbot commented 5 months ago

Question / Proposal:

Is there a way to lazy load the adapters based on the file type?

The problem is that all the adapters are loaded even when they are no required for the current neotest session.

The current implementation is:

require("neotest").setup({
    adapters = {
        require "neotest-python",
        require "neotest-go"
    }
}) 

I tried:

local neotest = require "neotest"

if vim.bo.ft == "python" then
  neotest.setup { adapters = require "neotest-python" }
elseif vim.bo.ft == "go" then
  neotest.setup { adapters = require "neotest-go" }
end

but does not work plus it has their own problems like there should be only one setup, thinking about the after/ftplugin directory but i feel it won't work either so i suppose, maybe can be implemented internally in neotest , probably create some table that can be passed to setup as an alternative to the adapters table to be able to lazy load by ft, something like adapters_by_ft that should look like this:

require("neotest").setup({
    adapters_by_ft = {
        python = require "neotest-python",
        go = require "neotest-go"
    }
}) 

I think it would be nice, maybe i will try to implement this by myself, and if it works submit a PR.

codymikol commented 4 months ago

I think it would be cool to have a mason like installer for them in addition to lazy loading them on demand

rsareth commented 2 months ago

It would be great to load the adapters according to the filetype. I am trying to get rid of my IDEs and to switch to Neovim for almost everything. But without neotest, it isn't interesting to get rid of my IDEs right now.

brablc commented 3 weeks ago

I reported #466. It may be related - I too see both adapters to get loaded in random order and causing problems.