nvim-neotest / neotest

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

Lazy load adapters #428

Open rokbot opened 1 week ago

rokbot commented 1 week 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 2 days ago

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