2 { "nvim-neotest/neotest",
3 dependencies = { "nvim-neotest/nvim-nio" },
6 status = { virtual_text = true },
7 output = { open_on_run = true },
8 quickfix = { enabled = true },
10 config = function(_, opts)
11 local neotest_ns = vim.api.nvim_create_namespace("neotest")
12 vim.diagnostic.config({
14 format = function(diagnostic)
15 -- Replace newline and tab characters with space for more compact diagnostics
16 local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
22 opts.consumers = opts.consumers or {}
23 -- Refresh and auto close trouble after running tests
24 ---@type neotest.Consumer
25 opts.consumers.trouble = function(client)
26 client.listeners.results = function(adapter_id, results, partial)
30 local tree = assert(client:get_position(nil, { adapter = adapter_id }))
33 for pos_id, result in pairs(results) do
34 if result.status == "failed" and tree:get_key(pos_id) then
38 vim.schedule(function()
39 local trouble = require("trouble")
40 if trouble.is_open() then
51 -- NOTE: support setting up test adapters in lang
54 for name, config in pairs(opts.adapters or {}) do
55 if type(name) == "number" then
56 if type(config) == "string" then
57 config = require(config)
59 adapters[#adapters + 1] = config
60 elseif config ~= false then
61 local adapter = require(name)
62 if type(config) == "table" and not vim.tbl_isempty(config) then
63 local meta = getmetatable(adapter)
66 elseif adapter.adapter then
67 adapter.adapter(config)
68 adapter = adapter.adapter
69 elseif meta and meta.__call then
70 adapter = adapter(config)
72 error("Adapter " .. name .. " does not support setup")
75 adapters[#adapters + 1] = adapter
78 opts.adapters = adapters
81 require("neotest").setup(opts)
85 {"<leader>t", "", desc = "+test"},
86 { "<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
87 { "<leader>tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Run All Test Files" },
88 { "<leader>tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
89 { "<leader>tl", function() require("neotest").run.run_last() end, desc = "Run Last" },
90 { "<leader>ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },
91 { "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" },
92 { "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" },
93 { "<leader>tS", function() require("neotest").run.stop() end, desc = "Stop" },
94 { "<leader>tw", function() require("neotest").watch.toggle(vim.fn.expand("%")) end, desc = "Toggle Watch" },
98 "mfussenegger/nvim-dap",
101 { "<leader>td", function() require("neotest").run.run({strategy = "dap"}) end, desc = "Debug Nearest" },