diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 17:40:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 18:05:10 -0300 |
| commit | 1e8787e0b2eb3eaa4991a5160f6e5c35ba6f132e (patch) | |
| tree | 255534be4abebd88f1a85d306d0111a339d172b3 /core/Messages.zig | |
| parent | 6ef1941324aa578750d54567c1ed201ad36412b8 (diff) | |
| download | pardes-1e8787e0b2eb3eaa4991a5160f6e5c35ba6f132e.tar.gz pardes-1e8787e0b2eb3eaa4991a5160f6e5c35ba6f132e.zip | |
Messages: a place whose file changed since the run that named it draws no words at its line, and unrolls no detail there (UX DESIGN H, binding: with SPC e keeping the error, Y2's wpqvkssr, a line put in above it left the error's words on the line that had moved down to it, `) std.Io.Writer.Error!void { ✗ local variable is never mutated` until the rebuild; a mark on the wrong line is worse than none, until places follow edits); THE CAUSE: a message's places are a path, a line and a column said once (readPlaces, diskDiff), and messageGhosts and firstAt (the words, the detail, K and SPC e on the line, a click on the words) drew them on that line whatever the file's text became; no anchor carries them: Places' anchors are a pane's search places in its own offsets (Places.shift by File.splice), jj.edited carries the Changes layer's per-line values only; THE FIX: Place.stale, set for every live place naming a file by any edit of its text (File.edit's told edits with bytes in or out: a key, an undo, a paste, a language server's edit and a Get through File.load; not the Changes layer's lines going in or out, nor an empty splice); messageGhosts and firstAt pass a stale place by; the box's mark (Said.about) and the notice row keep it, and SPC e still walks it, until the next run's error names fresh places (commandDone's, never stale); bounded by the live messages' places (16 x 4) per edit; RUN (TEST FIRST): Messages.zig "a file changed since the run that named its places draws none of their words at its lines ..." says an error at line 4 of a file shown, its words drawn after `var s = 1;`, then puts a line in above through File.load (a code action's way, Ask.applyLspEdits) and asks the frame for the words on no row while the box's `✗` and the notice row's `/test.txt:4:9` stay; the next run's error at line 5 drawn there again; then `var` replaced by `const` on that line and the words on no row: fails on M12+Y2 (lnqvtpmx) at Messages.zig:1960 (the words still drawn, on the line moved down to 4), passes now; the probe (VIDEO's kit, this change's Debug build, tally): after SPC e the words on line 11, after zls's `organize @import` and a save none on line 11 or 12 with the box's ✗ and the notice row's `report.zig:11:9` kept, after the rebuild the words on line 12; a user hit it with any edit above an error walked to with SPC e before the next build; core-test 1112/1284 (172 skipped: +1), shell-test 1332/1335 (3 skipped: +1), process-test 0 of 147 failed (3 skipped, no golden moved), behaviour-test 280/280; the dump fuzz at 40,000 join seeds twice and 1,779 image seeds 11/11 (Place gained a field); the soak `replicas -- --clients 5 --rtt 30,80,207`: diverged 0, unequal 0, quiet checks 725/0 434/0 519/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak; load 1.7 to 5.1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 5a36e166..e05961b5 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -97,6 +97,10 @@ pub const Place = struct { line: u32 = 1, col: u32 = 1, text: Buf(128) = .{}, + /// Its file's text changed since it was named (`edited`): its line may + /// be another's now, so its words are not drawn at it (a mark on the + /// wrong line is worse than none) until a run names it again. + stale: bool = false, }; /// The questions the session asks in the background, and their answers. @@ -489,6 +493,16 @@ fn placeOf(row: []const u8) ?struct { path: []const u8, line: u32, col: u32, tex return null; } +/// An edit of the text of the file at `path` (File.edit): the places that +/// name it no longer know their lines (`Place.stale`); the box's mark and +/// the notice row keep them until the next run. Bounded by the live +/// messages' places. +pub fn edited(m: *Messages, path: []const u8) void { + for (m.live[0..m.live_len]) |*s| for (s.places[0..s.places_len]) |*place| { + if (std.mem.eql(u8, place.path.slice(), path)) place.stale = true; + }; +} + /// The question waiting on `pane`, an index into `live`; null for none. pub fn waiting(m: *const Messages, pane: *const Pane) ?usize { for (m.live[0..m.live_len], 0..) |*s, i| if (s.kind == .question and s.pane == pane.serial) return i; @@ -1099,11 +1113,12 @@ pub fn detailUnder(p: *const Pardes, pane: *Pane, active: bool, body_h: u16) ?st return null; } -/// The first live message naming line `line` (1-based) of `path`: the one -/// whose words are drawn after that line (body_layer messageGhosts). +/// The first live message naming line `line` (1-based) of `path`, its +/// place not stale: the one whose words are drawn after that line +/// (body_layer messageGhosts). fn firstAt(m: *const Messages, path: []const u8, line: u32) ?usize { for (m.live[0..m.live_len], 0..) |*s, i| for (s.places[0..s.places_len]) |*place| { - if (line > 0 and place.line == line and std.mem.eql(u8, place.path.slice(), path)) return i; + if (line > 0 and place.line == line and !place.stale and std.mem.eql(u8, place.path.slice(), path)) return i; }; return null; } @@ -1910,3 +1925,64 @@ test "SPC e lands on its place's column, where jumps walk and where they open a try std.testing.expectEqual(@as(i32, 8), landed.body.cur_col); } } + +test "a file changed since the run that named its places draws none of their words at its lines (UX DESIGN H): a line put in above draws them at neither line, the box's mark and the notice row kept; the next run's error draws at its new line, and an edit on that line quiets it at once" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("const std = @import(\"std\");\n\npub fn print() void {\n var s = 1;\n _ = s;\n}\n"); + const id = p.view().active; + p.messages.live_len = 0; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + var buf: [512]u8 = undefined; + // The row its words are drawn on, null for none. + const Shown = struct { + fn row(pp: *Pardes, arena: *std.heap.ArenaAllocator, out: *[512]u8) !?[]const u8 { + _ = arena.reset(.retain_capacity); + pp.sync(); + const s = try pp.render(arena.allocator()); + 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 > out.len) break; + @memcpy(out[n..][0..g.len], g); + n += g.len; + } + if (std.mem.indexOf(u8, out[0..n], "\u{2717} local variable is never mutated") != null) return out[0..n]; + } + return null; + } + }; + for (0..2) |run| { + // A run names line 4 (the first) or 5 (the next, after the line + // put in above): its pane's next run takes the last one's error + // away (exec.zig) before it says its own. + _ = p.messages.retire(&.{.@"error"}); + const err = keep(p, .@"error", 0, "@p2 zig build", "exit 2"); + err.places[0] = .{ .line = @intCast(4 + run), .col = 9 }; + err.places[0].path.set("/test.txt"); + err.places[0].text.set("local variable is never mutated"); + err.places_len = 1; + const drawn = try Shown.row(p, &frame, &buf) orelse return error.WordsNotDrawn; + try std.testing.expect(std.mem.indexOf(u8, drawn, "var s = 1; \u{2717}") != null); + if (run == 1) break; + // A language server's edit puts a line in above it (File.load, a + // code action's way): the words are at neither its line nor the + // line it went to. + const f = &pane.file.?; + panes.File.load(p, f, try std.mem.concat(p.gpa, u8, &.{ "const std = @import(\"std\");\nconst Counts = u32;\n", f.content["const std = @import(\"std\");\n".len..] })); + try std.testing.expect(try Shown.row(p, &frame, &buf) == null); + // Its box's mark and the notice row's place stay until the run. + 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 row_buf: [notice_row_cap]u8 = undefined; + try std.testing.expect(std.mem.indexOf(u8, noticeRow(p, 97, &row_buf).text, "/test.txt:4:9") != null); + } + // An edit on the line, the fix: quiet at once. + const f = &pane.file.?; + const var_at = std.mem.indexOf(u8, f.content, "var s") orelse return error.NoLine; + try std.testing.expect(panes.File.replace(p, f, var_at, "var".len, "const")); + try std.testing.expect(try Shown.row(p, &frame, &buf) == null); +} |
