|
1 | 1 | local lib = require("neotest.lib") |
| 2 | +local types = require("neotest.types") |
2 | 3 | local logger = require("neotest.logging") |
3 | 4 | local config = require("neotest.config") |
4 | 5 | local Canvas = require("neotest.consumers.summary.canvas") |
|
52 | 53 |
|
53 | 54 | local all_expanded = {} |
54 | 55 |
|
| 56 | +---@param canvas neotest.summary.Canvas |
| 57 | +---@param adapter_id string |
| 58 | +function Summary:_write_header(canvas, adapter_id, tree) |
| 59 | + canvas:write( |
| 60 | + vim.split(adapter_id, ":", { trimempty = true })[1] .. " ", |
| 61 | + { group = config.highlights.adapter_name } |
| 62 | + ) |
| 63 | + |
| 64 | + if config.summary.count then |
| 65 | + local status_counts = { |
| 66 | + test = 0, |
| 67 | + running = 0, |
| 68 | + passed = 0, |
| 69 | + failed = 0, |
| 70 | + skipped = 0, |
| 71 | + } |
| 72 | + local results = self.client:get_results(adapter_id) |
| 73 | + |
| 74 | + for _, pos in tree:iter() do |
| 75 | + if pos.type == "test" then |
| 76 | + status_counts.test = status_counts.test + 1 |
| 77 | + |
| 78 | + local result = results[pos.id] |
| 79 | + |
| 80 | + if self.client:is_running(pos.id, { adapter = adapter_id }) then |
| 81 | + status_counts.running = status_counts.running + 1 |
| 82 | + elseif result and status_counts[result.status] ~= nil then |
| 83 | + status_counts[result.status] = status_counts[result.status] + 1 |
| 84 | + end |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + for _, status in ipairs({ "test", "passed", "failed", "running", "skipped" }) do |
| 89 | + canvas:write( |
| 90 | + config.icons[status] .. " " .. tostring(status_counts[status]) .. " ", |
| 91 | + { group = config.highlights[status] or config.highlights.namespace } |
| 92 | + ) |
| 93 | + end |
| 94 | + end |
| 95 | + canvas:write("\n") |
| 96 | + |
| 97 | + local cwd = vim.loop.cwd() |
| 98 | + if tree:data().path ~= cwd then |
| 99 | + local root_dir = nio.fn.fnamemodify(tree:data().path, ":.") |
| 100 | + canvas:write(root_dir .. "\n", { group = config.highlights.dir }) |
| 101 | + end |
| 102 | +end |
| 103 | + |
55 | 104 | function Summary:render(expanded) |
56 | 105 | if not self.win:is_open() then |
57 | 106 | return |
@@ -85,28 +134,10 @@ function Summary:run() |
85 | 134 | self.render_ready.wait() |
86 | 135 | self.render_ready.clear() |
87 | 136 | local canvas = Canvas.new(config.summary) |
88 | | - local cwd = vim.loop.cwd() |
89 | 137 | if self._starting then |
90 | 138 | for _, adapter_id in ipairs(self.client:get_adapters()) do |
91 | 139 | local tree = assert(self.client:get_position(nil, { adapter = adapter_id })) |
92 | | - local count = 0 |
93 | | - if config.summary.count then |
94 | | - for _, pos in tree:iter() do |
95 | | - if pos.type == "test" then |
96 | | - count = count + 1 |
97 | | - end |
98 | | - end |
99 | | - end |
100 | | - canvas:write( |
101 | | - vim.split(adapter_id, ":", { trimempty = true })[1] |
102 | | - .. (count == 0 and "" or string.format(" %d Tests Found", count)) |
103 | | - .. "\n", |
104 | | - { group = config.highlights.adapter_name } |
105 | | - ) |
106 | | - if tree:data().path ~= cwd then |
107 | | - local root_dir = nio.fn.fnamemodify(tree:data().path, ":.") |
108 | | - canvas:write(root_dir .. "\n", { group = config.highlights.dir }) |
109 | | - end |
| 140 | + self:_write_header(canvas, adapter_id, tree) |
110 | 141 | self.components[adapter_id] = self.components[adapter_id] |
111 | 142 | or SummaryComponent(self.client, adapter_id) |
112 | 143 | if config.summary.animated then |
@@ -136,7 +167,7 @@ function Summary:run() |
136 | 167 | if not rendered then |
137 | 168 | logger.error("Couldn't render buffer", err) |
138 | 169 | end |
139 | | - nio.api.nvim_exec("redraw", false) |
| 170 | + nio.api.nvim_exec2("redraw", {}) |
140 | 171 | nio.sleep(100) |
141 | 172 | end |
142 | 173 | end, function(msg) |
|
0 commit comments