2 { "nvim-neotest/neotest",
3 dependencies = { "nvim-neotest/nvim-nio" },
6 status = { virtual_text = true },
7 output = { open_on_run = true },
10 -- TODO: review if I'd prefer to just use quickfix here
12 require("trouble").open({ mode = "quickfix", focus = false })
16 config = function(_, opts)
17 local neotest_ns = vim.api.nvim_create_namespace("neotest")
18 vim.diagnostic.config({
20 format = function(diagnostic)
21 -- Replace newline and tab characters with space for more compact diagnostics
22 local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
28 opts.consumers = opts.consumers or {}
29 -- Refresh and auto close trouble after running tests
30 ---@type neotest.Consumer
31 opts.consumers.trouble = function(client)
32 client.listeners.results = function(adapter_id, results, partial)
36 local tree = assert(client:get_position(nil, { adapter = adapter_id }))
39 for pos_id, result in pairs(results) do
40 if result.status == "failed" and tree:get_key(pos_id) then
44 vim.schedule(function()
45 local trouble = require("trouble")
46 if trouble.is_open() then
57 -- NOTE: support setting up test adapters in lang
60 for name, config in pairs(opts.adapters or {}) do
61 if type(name) == "number" then
62 if type(config) == "string" then
63 config = require(config)
65 adapters[#adapters + 1] = config
66 elseif config ~= false then
67 local adapter = require(name)
68 if type(config) == "table" and not vim.tbl_isempty(config) then
69 local meta = getmetatable(adapter)
72 elseif adapter.adapter then
73 adapter.adapter(config)
74 adapter = adapter.adapter
75 elseif meta and meta.__call then
76 adapter = adapter(config)
78 error("Adapter " .. name .. " does not support setup")
81 adapters[#adapters + 1] = adapter
84 opts.adapters = adapters
87 require("neotest").setup(opts)
91 {"<leader>t", "", desc = "+test"},
92 { "<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
93 { "<leader>tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Run All Test Files" },
94 { "<leader>tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
95 { "<leader>tl", function() require("neotest").run.run_last() end, desc = "Run Last" },
96 { "<leader>ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },
97 { "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" },
98 { "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" },
99 { "<leader>tS", function() require("neotest").run.stop() end, desc = "Stop" },
100 { "<leader>tw", function() require("neotest").watch.toggle(vim.fn.expand("%")) end, desc = "Toggle Watch" },
104 "mfussenegger/nvim-dap",
107 { "<leader>td", function() require("neotest").run.run({strategy = "dap"}) end, desc = "Debug Nearest" },