mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 08:53:33 +02:00
refactor(neotest): better way to pass custom options for adapters
This commit is contained in:
parent
5559228300
commit
cd96e3d9e5
1 changed files with 21 additions and 9 deletions
|
@ -11,10 +11,16 @@ return {
|
||||||
{
|
{
|
||||||
"nvim-neotest/neotest",
|
"nvim-neotest/neotest",
|
||||||
opts = {
|
opts = {
|
||||||
adapter_config = {
|
-- Can be a list of adapters like what neotest expects,
|
||||||
-- ["adapter_name"] = {} -- set adapter config here
|
-- or a table of adapter names, mapped to adapter configs.
|
||||||
},
|
-- The adapter will then be automatically loaded with the config.
|
||||||
adapters = {},
|
adapters = {},
|
||||||
|
-- Example for loading neotest-go with a custom config
|
||||||
|
-- adapters = {
|
||||||
|
-- ["neotest-go"] = {
|
||||||
|
-- args = { "-tags=integration" },
|
||||||
|
-- },
|
||||||
|
-- },
|
||||||
},
|
},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
local neotest_ns = vim.api.nvim_create_namespace("neotest")
|
local neotest_ns = vim.api.nvim_create_namespace("neotest")
|
||||||
|
@ -28,16 +34,22 @@ return {
|
||||||
},
|
},
|
||||||
}, neotest_ns)
|
}, neotest_ns)
|
||||||
|
|
||||||
if opts.adapter_config then
|
local adapters = {}
|
||||||
for a, adapter in ipairs(opts.adapters or {}) do
|
if opts.adapters then
|
||||||
local name = adapter.name
|
for name, config in pairs(opts.adapters or {}) do
|
||||||
if opts.adapter_config[name] then
|
if type(name) == "number" then
|
||||||
opts.adapters[a] = adapter(opts.adapter_config[name])
|
adapters[#adapters + 1] = config
|
||||||
|
elseif config ~= false then
|
||||||
|
local adapter = require(name)
|
||||||
|
if type(config) == "table" and not vim.tbl_isempty(config) then
|
||||||
|
adapter = adapter(config)
|
||||||
|
end
|
||||||
|
adapters[#adapters + 1] = adapter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require("neotest").setup(opts)
|
require("neotest").setup({ adapters = adapters })
|
||||||
end,
|
end,
|
||||||
-- stylua: ignore
|
-- stylua: ignore
|
||||||
keys = {
|
keys = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue