X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/eca3163fa25f5d6a4d1aa77d447473141d1a5b79..HEAD:/nvim/lua/plugins/test.lua?ds=sidebyside diff --git a/nvim/lua/plugins/test.lua b/nvim/lua/plugins/test.lua index 49d6dd6..9ed3fc4 100644 --- a/nvim/lua/plugins/test.lua +++ b/nvim/lua/plugins/test.lua @@ -1,16 +1,15 @@ return { - { - "nvim-neotest/neotest", + { "nvim-neotest/neotest", + dependencies = { "nvim-neotest/nvim-nio" }, opts = { + adapters = {}, status = { virtual_text = true }, output = { open_on_run = true }, quickfix = { open = function() - if require("lazyvim.util").has("trouble.nvim") then - require("trouble").open({ mode = "quickfix", focus = false }) - else - vim.cmd("copen") - end + -- TODO: review if I'd prefer to just use quickfix here + -- vim.cmd("copen") + require("trouble").open({ mode = "quickfix", focus = false }) end, }, }, @@ -26,37 +25,36 @@ return { }, }, neotest_ns) - if require("lazyvim.util").has("trouble.nvim") then - opts.consumers = opts.consumers or {} - -- Refresh and auto close trouble after running tests - ---@type neotest.Consumer - opts.consumers.trouble = function(client) - client.listeners.results = function(adapter_id, results, partial) - if partial then - return - end - local tree = assert(client:get_position(nil, { adapter = adapter_id })) + opts.consumers = opts.consumers or {} + -- Refresh and auto close trouble after running tests + ---@type neotest.Consumer + opts.consumers.trouble = function(client) + client.listeners.results = function(adapter_id, results, partial) + if partial then + return + end + local tree = assert(client:get_position(nil, { adapter = adapter_id })) - local failed = 0 - for pos_id, result in pairs(results) do - if result.status == "failed" and tree:get_key(pos_id) then - failed = failed + 1 - end + local failed = 0 + for pos_id, result in pairs(results) do + if result.status == "failed" and tree:get_key(pos_id) then + failed = failed + 1 end - vim.schedule(function() - local trouble = require("trouble") - if trouble.is_open() then - trouble.refresh() - if failed == 0 then - trouble.close() - end - end - end) end - return {} + vim.schedule(function() + local trouble = require("trouble") + if trouble.is_open() then + trouble.refresh() + if failed == 0 then + trouble.close() + end + end + end) end + return {} end + -- NOTE: support setting up test adapters in lang if opts.adapters then local adapters = {} for name, config in pairs(opts.adapters or {}) do @@ -71,8 +69,11 @@ return { local meta = getmetatable(adapter) if adapter.setup then adapter.setup(config) + elseif adapter.adapter then + adapter.adapter(config) + adapter = adapter.adapter elseif meta and meta.__call then - adapter(config) + adapter = adapter(config) else error("Adapter " .. name .. " does not support setup") end @@ -87,13 +88,16 @@ return { end, -- stylua: ignore keys = { + {"t", "", desc = "+test"}, { "tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" }, { "tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Run All Test Files" }, { "tr", function() require("neotest").run.run() end, desc = "Run Nearest" }, + { "tl", function() require("neotest").run.run_last() end, desc = "Run Last" }, { "ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" }, { "to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" }, { "tO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" }, { "tS", function() require("neotest").run.stop() end, desc = "Stop" }, + { "tw", function() require("neotest").watch.toggle(vim.fn.expand("%")) end, desc = "Toggle Watch" }, }, }, {