Skip to content

Commit 430d222

Browse files
committed
Render summary when hovering on parent node
1 parent 8ba9988 commit 430d222

File tree

6 files changed

+121
-38
lines changed

6 files changed

+121
-38
lines changed

lua/clojure-test/ui/components/exception.lua

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,84 @@ local NuiText = require("nui.text")
55

66
local M = {}
77

8-
function M.render_exceptions_to_buf(buf, exception_chain)
8+
function M.render_exception_to_buf(buf, exception, start_line)
9+
start_line = start_line or 0
10+
911
vim.api.nvim_set_option_value("filetype", "clojure", {
1012
buf = buf,
1113
})
12-
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {})
14+
vim.api.nvim_buf_set_lines(buf, start_line, -1, false, {})
1315

1416
local lines = {}
1517

16-
for _, ex in ipairs(utils.reverse_table(exception_chain)) do
17-
local exception_title = NuiLine()
18-
exception_title:append(ex["class-name"], "Error")
19-
exception_title:append(": ", "Comment")
18+
local exception_title = NuiLine()
19+
exception_title:append(exception["class-name"], "Error")
20+
exception_title:append(": ", "Comment")
2021

21-
local title_lines = vim.split(ex.message, "\n")
22-
exception_title:append(title_lines[1], "TSParameter")
22+
local title_lines = vim.split(exception.message, "\n")
23+
exception_title:append(title_lines[1], "TSParameter")
2324

24-
table.insert(lines, exception_title)
25-
table.remove(title_lines, 1)
25+
table.insert(lines, exception_title)
26+
table.remove(title_lines, 1)
2627

27-
for _, content in ipairs(title_lines) do
28-
table.insert(lines, NuiLine({ NuiText(content, "TSParameter") }))
29-
end
28+
for _, content in ipairs(title_lines) do
29+
table.insert(lines, NuiLine({ NuiText(content, "TSParameter") }))
30+
end
3031

31-
local stack_trace = ex["stack-trace"]
32-
if stack_trace and stack_trace ~= vim.NIL then
33-
for _, frame in ipairs(stack_trace) do
34-
if frame.name and frame.name ~= "" then
35-
local namespace_and_names = vim.split(frame.name, "/")
36-
local names = table.concat(namespace_and_names, "/", 2)
37-
38-
local frame_line = NuiLine()
39-
frame_line:append(" ")
40-
frame_line:append(namespace_and_names[1], "TSNamespace")
41-
frame_line:append("/", "TSMethodCall")
42-
frame_line:append(names, "TsMethodCall")
43-
44-
if frame.line and frame.line ~= vim.NIL then
45-
frame_line:append(" @ ", "Comment")
46-
frame_line:append(tostring(frame.line), "TSNumber")
47-
end
48-
49-
table.insert(lines, frame_line)
32+
local stack_trace = exception["stack-trace"]
33+
if stack_trace and stack_trace ~= vim.NIL then
34+
for _, frame in ipairs(stack_trace) do
35+
if frame.name and frame.name ~= "" then
36+
local namespace_and_names = vim.split(frame.name, "/")
37+
local names = table.concat(namespace_and_names, "/", 2)
38+
39+
local frame_line = NuiLine()
40+
frame_line:append(" ")
41+
frame_line:append(namespace_and_names[1], "TSNamespace")
42+
frame_line:append("/", "TSMethodCall")
43+
frame_line:append(names, "TsMethodCall")
44+
45+
if frame.line and frame.line ~= vim.NIL then
46+
frame_line:append(" @ ", "Comment")
47+
frame_line:append(tostring(frame.line), "TSNumber")
5048
end
49+
50+
table.insert(lines, frame_line)
5151
end
5252
end
53+
end
5354

54-
if ex.properties and ex.properties ~= vim.NIL then
55-
table.insert(lines, NuiLine())
55+
if exception.properties and exception.properties ~= vim.NIL then
56+
table.insert(lines, NuiLine())
5657

57-
for _, content in ipairs(vim.split(ex.properties, "\n")) do
58-
table.insert(lines, NuiLine({ NuiText(content) }))
59-
end
58+
for _, content in ipairs(vim.split(exception.properties, "\n")) do
59+
table.insert(lines, NuiLine({ NuiText(content) }))
6060
end
6161
end
6262

6363
for i, line in ipairs(lines) do
64-
line:render(buf, -1, i)
64+
line:render(buf, -1, start_line + i)
6565
end
66+
67+
return #lines
68+
end
69+
70+
function M.render_exceptions_to_buf(buf, exception_chain, start_line)
71+
start_line = start_line or 0
72+
73+
vim.api.nvim_set_option_value("filetype", "clojure", {
74+
buf = buf,
75+
})
76+
vim.api.nvim_buf_set_lines(buf, start_line, -1, false, {})
77+
78+
local total_lines = 0
79+
80+
for _, ex in ipairs(utils.reverse_table(exception_chain)) do
81+
local lines = M.render_exception_to_buf(buf, ex, start_line + total_lines)
82+
total_lines = total_lines + lines
83+
end
84+
85+
return total_lines
6686
end
6787

6888
return M

lua/clojure-test/ui/components/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ return {
22
exception = require("clojure-test.ui.components.exception"),
33
tree = require("clojure-test.ui.components.tree"),
44
clojure = require("clojure-test.ui.components.clojure"),
5+
summary = require("clojure-test.ui.components.summary"),
56
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
local exception = require("clojure-test.ui.components.exception")
2+
3+
local NuiLine = require("nui.line")
4+
local NuiText = require("nui.text")
5+
6+
local M = {}
7+
8+
function M.render_summary(buf, report)
9+
vim.api.nvim_set_option_value("filetype", "clojure", {
10+
buf = buf,
11+
})
12+
13+
local offset = 0
14+
15+
local function render_line(items)
16+
NuiLine(items):render(buf, -1, offset + 1)
17+
offset = offset + 1
18+
end
19+
20+
local function render_content(content)
21+
local lines = vim.split(vim.trim(content), "\n")
22+
vim.api.nvim_buf_set_lines(buf, offset, -1, false, lines)
23+
offset = offset + #lines
24+
end
25+
26+
for _, assertion in ipairs(report.assertions) do
27+
if assertion.expected then
28+
render_line({ NuiText(";; Expected") })
29+
render_content(assertion.expected)
30+
end
31+
32+
render_line({ NuiText(";; Actual") })
33+
if assertion.actual then
34+
render_content(assertion.actual)
35+
end
36+
37+
if assertion.exceptions then
38+
local lines = exception.render_exception_to_buf(buf, assertion.exceptions[#assertion.exceptions], offset)
39+
offset = offset + lines
40+
end
41+
42+
render_line({})
43+
end
44+
end
45+
46+
return M

lua/clojure-test/ui/components/tree.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ local function exceptions_to_nodes(exceptions)
4848
}
4949

5050
local node = NuiTree.Node({
51+
type = "exception",
5152
line = line,
5253
exception = ex,
5354
})
@@ -62,6 +63,7 @@ local function assertion_to_node(test, assertion)
6263
local children = exceptions_to_nodes(assertion.exceptions or {})
6364

6465
local node = NuiTree.Node({
66+
type = "assertion",
6567
line = line,
6668
assertion = assertion,
6769
test = test,
@@ -83,6 +85,7 @@ local function report_to_node(report, is_expanded)
8385
end
8486

8587
local node = NuiTree.Node({
88+
type = "report",
8689
line = report_line,
8790
test = report.test,
8891
report = report,

lua/clojure-test/ui/layouts/float/init.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ local utils = require("clojure-test.utils")
66
local function handle_on_move(layout, event)
77
local node = event.node
88

9+
if node.type == "report" then
10+
vim.schedule(function()
11+
layout:render_single()
12+
components.summary.render_summary(layout.windows.right.bufnr, node.report)
13+
end)
14+
return
15+
end
16+
917
if node.assertion then
1018
if node.assertion.exceptions then
1119
vim.schedule(function()

tests/backend/mock.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function M.create()
6363
expected = "(= 1 1)",
6464
actual = "(= 1 1)",
6565
},
66+
{
67+
type = "pass",
68+
expected = "(= 2 2)",
69+
actual = "(= 2 2)",
70+
},
6671
},
6772
}
6873
end

0 commit comments

Comments
 (0)