diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Messages.zig | 10 | ||||
| -rw-r--r-- | core/panes.zig | 48 |
2 files changed, 54 insertions, 4 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 4dd39097..5a36e166 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -433,8 +433,9 @@ pub fn ink(chrome: *const pardes.colors.ChromeTheme, kind: Kind) [3]u8 { /// The places a compiler's report names put on `s`: each /// `path:line:col: error|warning|note: words` row (a relative path is -/// `dir`'s), its words there, and the rows after the first error, up to -/// the next place, its detail. How many it found; none without an error. +/// `dir`'s), its words there, each place once, and the rows after the +/// first error, up to the next place, its detail. How many it found; none +/// without an error. pub fn readPlaces(s: *Said, dir: []const u8, rows: []const []const u8) usize { var errors: usize = 0; var detailing = false; @@ -458,6 +459,11 @@ pub fn readPlaces(s: *Said, dir: []const u8, rows: []const []const u8) usize { const place = &s.places[s.places_len]; place.* = .{ .line = found.line, .col = found.col }; if (std.Io.Dir.path.isAbsolute(found.path)) place.path.set(found.path) else _ = place.path.print("{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), found.path }); + // A place named again (a note at its error's) is not a second one. + const named = for (s.places[0..s.places_len]) |*was| { + if (was.line == place.line and was.col == place.col and std.mem.eql(u8, was.path.slice(), place.path.slice())) break true; + } else false; + if (named) continue; place.text.set(if (std.mem.startsWith(u8, found.text, "error: ")) found.text["error: ".len..] else found.text); s.places_len += 1; } diff --git a/core/panes.zig b/core/panes.zig index 280fd3f9..4b9aa7a7 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1073,11 +1073,21 @@ pub const Pane = struct { const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16 // A failed run's last rows, read before its `exit N` goes under // them: a report's places are at its end, and its detail is the - // tool's lines, not the run's status (UX F2). + // tool's lines, not the run's status (UX F2). Its own: those after + // its `% line` (exec.echoCommand), not a run's before it in the + // pane, whose places are no longer where it said. const rows: ?[]const []const u8 = if (status == 0) null else if (pane.terminal) |state| read: { const grid = Term.grid(state); const first = grid.total -| 400; - break :read Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch null; + const last = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :read null; + const command = pane.command orelse break :read last; + var from = last.len; + while (from > 0) { + from -= 1; + const echo = std.mem.trimEnd(u8, last[from], " "); + if (echo.len > "% ".len and std.mem.startsWith(u8, echo, "% ") and std.mem.startsWith(u8, command, echo["% ".len..])) break :read last[from + 1 ..]; + } + break :read last; } else null; var said: pardes.Kind.Buf(32) = .{}; const lead = if (Term.grid(pane.terminal).cursor_x != 0) "\r\n" else ""; @@ -2002,3 +2012,37 @@ test "a command whose run fails naming places is an error of its pane, those pla while (p.nextEffect()) |_| {} try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error"); } + +test "a failed run's error names that run's places, each once: a rerun in the same pane does not read the run before it again, and a note at an error's place is not a second place" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{}); + defer p.deinit(); + while (p.nextEffect()) |_| {} + p.setCwd(.at(0), "/tmp/pardes-cmd"); + _ = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-cmd/pic.ppm", null); + const dst = exec.execute(p, 1, "zig build") orelse return error.NoCommandPane; + while (p.nextEffect()) |_| {} + // `zig build`'s report, ZIG_BUILD_ERROR_STYLE=minimal: the error, its + // source line and caret, a note at the same place; then the same + // error a line lower once a line went in above it. + for ([_]u32{ 11, 12 }) |line| { + var out: [512]u8 = undefined; + p.update(.{ .output = .{ .pane = .at(dst), .bytes = try std.fmt.bufPrint(&out, "report.zig:{d}:9: error: local variable is never mutated\r\n var s = if (c.words == 1) \"\" else \"s\";\r\n ^\r\nreport.zig:{d}:9: note: consider using 'const'\r\nerror: 1 compilation errors\r\n", .{ line, line }) } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } }); + const said = p.messages.headline() orelse return error.NothingSaid; + try std.testing.expectEqual(pardes.Messages.Kind.@"error", said.kind); + var names: [256]u8 = undefined; + var w: std.Io.Writer = .fixed(&names); + for (said.places[0..said.places_len]) |*place| try w.print("{s}:{d}:{d} ", .{ place.path.slice(), place.line, place.col }); + var want: [64]u8 = undefined; + try std.testing.expectEqualStrings(try std.fmt.bufPrint(&want, "/tmp/pardes-cmd/report.zig:{d}:9 ", .{line}), w.buffered()); + try std.testing.expectEqualStrings("local variable is never mutated", said.places[0].text.slice()); + try std.testing.expectEqual(@as(u8, 2), said.detail_len); + if (line == 12) break; + // Its next run, in the same pane: the rows above are the last run's. + p.update(.{ .eof = .{ .pane = .at(dst) } }); + try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "zig build")); + while (p.nextEffect()) |_| {} + } +} |
