diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Messages.zig | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 6233f7e5..9ba1bc93 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -535,10 +535,12 @@ pub fn answer(p: *Pardes, i: usize, key: u8) bool { /// detail not unrolled, that detail (UX D13); else on the message the /// notice row leads with: an error that names places lands them as a list in pane /// `id`'s walk (Pick's `list`, its word `✗ <cause>` in the trail), the -/// first landed on, n and N walking the rest, and the error goes (a -/// +Search under the pane where jumps do not walk, or for a 9P script: -/// Pick.asked); a question takes the keyboard in its pane's tag; anything -/// else, or nothing, opens the history. +/// first landed on, n and N walking the rest (a +Search under the pane +/// where jumps do not walk, or for a 9P script: Pick.asked), the error +/// kept: its mark and its words at the lines it names are where the walk +/// lands, until Esc, the next error or its pane's next run; a question +/// takes the keyboard in its pane's tag; anything else, or nothing, opens +/// the history. pub fn act(p: *Pardes, id: usize) void { const m = &p.messages; // On a line a message names, its detail not unrolled: unrolled (UX @@ -560,10 +562,6 @@ pub fn act(p: *Pardes, id: usize) void { errdefer rows.deinit(); for (lead.places[0..lead.places_len]) |*place| rows.writer.print("{s}:{d}:{d} {s}\n", .{ place.path.slice(), place.line, place.col, place.text.slice() }) catch |err| return reportError(p, .at(id), "Message", err); const cause = lead.src; - const lead_at = for (m.live[0..m.live_len], 0..) |*s, k| { - if (s == lead) break k; - } else return; - m.remove(lead_at); const content = rows.toOwnedSlice() catch |err| return reportError(p, .at(id), "Message", err); if (pardes.Pick.asked(p)) { defer p.gpa.free(content); @@ -1614,11 +1612,13 @@ test "SPC e on an error that names places lists them under the pane and lands on p.update(.{ .key = .{ .cp = ' ' } }); p.update(.{ .key = .{ .cp = 'e' } }); while (p.nextEffect()) |_| {} - try std.testing.expect(p.messages.headline() == null); + // The error kept, its lines marked, until Esc. + try std.testing.expect(p.messages.headline() == err); const here = p.paneBySerial(serial).?; const list = p.panes[p.panes[here].?.search_pane orelse return error.NoList].?; try std.testing.expect(std.mem.indexOf(u8, list.file.?.content, "/test.txt:4:1") != null); try std.testing.expectEqual(@as(i32, 1), p.panes[here].?.body.cur_row); + try std.testing.expectEqual(@as(usize, 1), p.messages.retire(&.{.@"error"})); // A question: its tag gets the keyboard. keep(p, .question, serial, "/test.txt", "changed on disk").asks = .disk; try std.testing.expect(p.executeBuiltinLine(here, "Message")); @@ -1657,7 +1657,7 @@ test "where jumps walk, SPC e lands an error's places as a list in the pane's wa for (p.panes) |slot| panes_before += @intFromBool(slot != null); for (" e") |c| p.update(.{ .key = .{ .cp = c } }); while (p.nextEffect()) |_| {} - try std.testing.expect(p.messages.headline() == null); + try std.testing.expect(p.messages.headline() == err); // Landed in this reading pane, no pane made: on the first place, the // list's word in its trail. var panes_now: usize = 0; @@ -1830,3 +1830,48 @@ test "a message too wide for the notice row gives way by its items, each cut sho causeWord(pane, &word); try std.testing.expect(std.mem.endsWith(u8, word.slice(), "\u{2026}")); } + +test "SPC e keeps the error it walks: the file it lands in, not open when the error was said, shows the error's mark in its box and its words after the place's line" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "report.zig", .data = "one\ntwo\nthree\nfour\n var s = 1;\nsix\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + p.settings.jumps = .walk; + _ = try p.setTestFile("main\n"); + p.messages.live_len = 0; + const err = keep(p, .@"error", 0, "@p9 zig build", "exit 2"); + err.places[0] = .{ .line = 5, .col = 9 }; + _ = err.places[0].path.print("{s}/report.zig", .{dir}); + err.places[0].text.set("local variable is never mutated"); + err.places_len = 1; + for (" e") |c| p.update(.{ .key = .{ .cp = c } }); + while (p.nextEffect()) |_| {} + p.sync(); + const id = p.view().active; + const pane = p.panes[id].?; + try std.testing.expect(std.mem.endsWith(u8, pane.file.?.path, "/report.zig")); + try std.testing.expectEqual(@as(i32, 4), pane.body.cur_row); + // The error lives on (Esc, the next error or its pane's next run take + // it): the line it names is marked where the walk landed. + try std.testing.expect(p.messages.headline() != null and p.messages.headline().?.kind == .@"error"); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[id]; + try std.testing.expectEqualStrings("\u{2717}", s.at(r.x + config.GUTTER - 1, p.tagTop(pane, r)).grapheme()); + var buf: [512]u8 = undefined; + const marked = for (0..s.rows) |y| { + var n: usize = 0; + for (0..s.cols) |x| { + const g = s.cells[y * s.cols + x].grapheme(); + if (n + g.len > buf.len) break; + @memcpy(buf[n..][0..g.len], g); + n += g.len; + } + if (std.mem.indexOf(u8, buf[0..n], "var s = 1;") != null) break buf[0..n]; + } else return error.LineNotShown; + try std.testing.expect(std.mem.indexOf(u8, marked, "var s = 1; \u{2717} local variable is never mutated") != null); +} |
