]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/test.lua
rofimoji: add superscripts_and_subscripts to utf char list
[dotfiles.git] / nvim / lua / plugins / test.lua
1 return {
2 {
3 "folke/which-key.nvim",
4 opts = {
5 defaults = { ["<leader>t"] = { name = "+test" }, },
6 },
7 },
8 {
9 "nvim-neotest/neotest",
10 opts = {
11 status = { virtual_text = true },
12 output = { open_on_run = true },
13 quickfix = {
14 open = function()
15 if require("lazyvim.util").has("trouble.nvim") then
16 require("trouble").open({ mode = "quickfix", focus = false })
17 else
18 vim.cmd("copen")
19 end
20 end,
21 },
22 },
23 config = function(_, opts)
24 local neotest_ns = vim.api.nvim_create_namespace("neotest")
25 vim.diagnostic.config({
26 virtual_text = {
27 format = function(diagnostic)
28 -- Replace newline and tab characters with space for more compact diagnostics
29 local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
30 return message
31 end,
32 },
33 }, neotest_ns)
34
35 if require("lazyvim.util").has("trouble.nvim") then
36 opts.consumers = opts.consumers or {}
37 -- Refresh and auto close trouble after running tests
38 ---@type neotest.Consumer
39 opts.consumers.trouble = function(client)
40 client.listeners.results = function(adapter_id, results, partial)
41 if partial then
42 return
43 end
44 local tree = assert(client:get_position(nil, { adapter = adapter_id }))
45
46 local failed = 0
47 for pos_id, result in pairs(results) do
48 if result.status == "failed" and tree:get_key(pos_id) then
49 failed = failed + 1
50 end
51 end
52 vim.schedule(function()
53 local trouble = require("trouble")
54 if trouble.is_open() then
55 trouble.refresh()
56 if failed == 0 then
57 trouble.close()
58 end
59 end
60 end)
61 end
62 return {}
63 end
64 end
65
66 if opts.adapters then
67 local adapters = {}
68 for name, config in pairs(opts.adapters or {}) do
69 if type(name) == "number" then
70 if type(config) == "string" then
71 config = require(config)
72 end
73 adapters[#adapters + 1] = config
74 elseif config ~= false then
75 local adapter = require(name)
76 if type(config) == "table" and not vim.tbl_isempty(config) then
77 local meta = getmetatable(adapter)
78 if adapter.setup then
79 adapter.setup(config)
80 elseif meta and meta.__call then
81 adapter(config)
82 else
83 error("Adapter " .. name .. " does not support setup")
84 end
85 end
86 adapters[#adapters + 1] = adapter
87 end
88 end
89 opts.adapters = adapters
90 end
91
92 require("neotest").setup(opts)
93 end,
94 -- stylua: ignore
95 keys = {
96 { "<leader>tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
97 { "<leader>tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Run All Test Files" },
98 { "<leader>tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
99 { "<leader>ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },
100 { "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" },
101 { "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" },
102 { "<leader>tS", function() require("neotest").run.stop() end, desc = "Stop" },
103 },
104 },
105 {
106 "mfussenegger/nvim-dap",
107 -- stylua: ignore
108 keys = {
109 { "<leader>td", function() require("neotest").run.run({strategy = "dap"}) end, desc = "Debug Nearest" },
110 },
111 },
112 }