diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 19:37:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 20:01:36 -0300 |
| commit | 9bd34ae2afdb05713f312e7e58dc3d516ea84ebe (patch) | |
| tree | 474095187ebf00950666de755d0ec759aaa7dc40 /src/Stream.zig | |
| parent | 257eec0ae161b28f69b6c6fa8aae03ecc1bf85f0 (diff) | |
| download | pardes-9bd34ae2afdb05713f312e7e58dc3d516ea84ebe.tar.gz pardes-9bd34ae2afdb05713f312e7e58dc3d516ea84ebe.zip | |
Query: a +Search's rows recoloured are made again (locations.cloneRows, Query.save's copy), never written in place: the rows are a blob (File.State location_rows), whose word a digest keeps by address and a replica's rollback copy pins, so a release session kept the word of their colours before a paint landed (recolor's @memcpy); an edit moved them into dropped_marks with the stale word, a replica that hashed them at another time diverged there (fixer 1's soak: `pane 5.file.dropped_marks`), and a client loading the session's dump hashed the colours it carried and loaded "as another session"; dropped_marks stays in the digest, as an undo back to its text reads it; Stream's test, which a Debug build fails before (`the 82-byte blob ... is not what its kept word was: written in place`)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/Stream.zig')
| -rw-r--r-- | src/Stream.zig | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/Stream.zig b/src/Stream.zig index 263a6628..69dc311f 100644 --- a/src/Stream.zig +++ b/src/Stream.zig @@ -1647,6 +1647,79 @@ test "zz grep rows timings: a Grep of about 2000 rows on the stress file, a work Stats.print("other frames", idle.items); } +test "Stream: a Grep's rows recoloured are made again, never written, and a dump of them dropped by an edit loads to its digest" { + if (comptime !filesystem.platform_has_fs) return; + if (!syntax.enabled or !syntax.readyApart("c.zig")) return; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + // Rows enough that a digest keeps a word for them (walk's blob_min). + var text: std.ArrayList(u8) = .empty; + defer text.deinit(testing.allocator); + for (0..80) |i| try text.print(testing.allocator, "pub const value_{d}: u32 = {d};\n", .{ i, i }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.zig", .data = text.items }); + var root_buf: [4096]u8 = undefined; + const root = root_buf[0..try tmp.dir.realPath(testing.io, &root_buf)]; + const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile(text.items); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try std.fs.path.join(p.gpa, &.{ root, "c.zig" }); + var shell: TestShell = .init(); + shell.attach(p); + defer { + p.stream.cancelTask(); + p.stream.cancelPaint(); + shell.q.deinit(); + } + panes.Query.open(p, 0, .grep, "value", false); + const qid = for (p.panes, 0..) |slot, i| { + if (slot) |qp| if (qp.query != null) break i; + } else return error.NoQueryPane; + const f = &p.panes[qid].?.file.?; + const coloured = struct { + fn count(rows: []const @import("locations.zig").Row) usize { + var n: usize = 0; + for (rows) |row| n += @intFromBool(row.kind == .match and row.location_end > 0 and std.mem.indexOfNone(u8, row.colors, &.{0}) != null); + return n; + } + }.count; + var arena = std.heap.ArenaAllocator.init(testing.allocator); + defer arena.deinit(); + const until = now() + 10 * std.time.ns_per_s; + // The rows, plain, digested (their word kept) before their colours land. + while (now() < until and f.location_rows.len < 80) { + p.advance(now()); + shell.pump(p); + p.update(.tick); + testing.io.sleep(.fromMilliseconds(2), .awake) catch {}; + } + try testing.expect(f.location_rows.len >= 80 and coloured(f.location_rows) == 0); + _ = pardes.walk.digest(Pardes, p); + const plain = f.location_rows.ptr; + while (now() < until and (coloured(f.location_rows) < 80 or p.stream.rows_paint != null)) { + p.advance(now()); + shell.pump(p); + p.update(.tick); + _ = arena.reset(.retain_capacity); + _ = try p.render(arena.allocator()); + testing.io.sleep(.fromMilliseconds(2), .awake) catch {}; + } + try testing.expectEqual(@as(usize, 80), coloured(f.location_rows)); + // Made again: a Debug build's digest finds no blob written in place + // (the plain rows' kept word is theirs), and the rows are new ones. + _ = pardes.walk.digest(Pardes, p); + try testing.expect(f.location_rows.ptr != plain); + // An edit drops them with the text they were for (dropped_marks): a + // join's load of the session is it, digest for digest. + panes.File.setContent(p, f, try p.gpa.dupe(u8, "value\n")); + try testing.expect(f.dropped_marks != null); + const bytes = try pardes.dump.dumpBytes(p); + defer p.gpa.free(bytes); + const q = try pardes.dump.load(testing.allocator, p.opts, bytes, null); + defer q.deinit(); + try testing.expectEqual(pardes.walk.digest(panes.File.State, f), pardes.walk.digest(panes.File.State, &q.panes[qid].?.file.?)); +} + test "Stream: a Grep's rows are coloured as their file's language colours them, the file painted on a worker, the match tint on top" { if (comptime !filesystem.platform_has_fs) return; if (!syntax.enabled or !syntax.readyApart("c.zig")) return; |
