diff options
Diffstat (limited to 'core/panes.zig')
| -rw-r--r-- | core/panes.zig | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/panes.zig b/core/panes.zig index ea0ff86d..479d4702 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1042,6 +1042,23 @@ pub const Pane = struct { pane.feedOutput(p, said.print("{s}exit {s}\r\n", .{ lead, code })); pane.noteRun(p, "exit", code); p.needs_frame = true; + // A failed run whose report names places (a compiler's + // `path:line:col: error: ...`): an error of this pane, the places + // its words, the rows after its first its detail (SPEC ยง10.2). Its + // last rows only: a report's places are at its end. + if (status != 0) if (pane.terminal) |state| report: { + const grid = Term.grid(state); + const first = grid.total -| 400; + const rows = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :report; + var found: pardes.Messages.Said = .{}; + if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), rows) == 0) break :report; + var words: pardes.Kind.Buf(32) = .{}; + const kept = pardes.Messages.say(p, .@"error", id, words.print("exit {s}", .{code})); + kept.places = found.places; + kept.places_len = found.places_len; + kept.detail = found.detail; + kept.detail_len = found.detail_len; + }; } }; @@ -1902,3 +1919,35 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(pane.prompt == .none and pane.input.own == null); } + +test "a command whose run fails naming places is an error of its pane, those places its words, and the pane's next run takes it away" { + 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()) |_| {} + const pane = p.panes[dst].?; + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "core/pick.zig:25:12: error: expected 2 argument(s), found 3\r\n const best = rank(q, name, 3);\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 1 } }); + const said = p.messages.headline() orelse return error.NothingSaid; + try std.testing.expectEqual(pardes.Messages.Kind.@"error", said.kind); + try std.testing.expectEqualStrings("exit 1", said.text.slice()); + try std.testing.expect(std.mem.endsWith(u8, said.src.slice(), " zig build")); + try std.testing.expectEqual(@as(u8, 1), said.places_len); + try std.testing.expectEqualStrings("/tmp/pardes-cmd/core/pick.zig", said.places[0].path.slice()); + try std.testing.expectEqualStrings(" const best = rank(q, name, 3);", said.detail[0].slice()); + var frame = std.heap.ArenaAllocator.init(gpa); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[dst]; + try std.testing.expectEqualStrings("\u{2717}", s.at(r.x + config.GUTTER - 1, p.tagTop(pane, r)).grapheme()); + // Its next run: the last run's error goes. + p.update(.{ .eof = .{ .pane = .at(dst) } }); + try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "zig build")); + while (p.nextEffect()) |_| {} + try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error"); +} |
