summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Places.zig56
1 files changed, 50 insertions, 6 deletions
diff --git a/src/Places.zig b/src/Places.zig
index 818ca1d7..a60a0d65 100644
--- a/src/Places.zig
+++ b/src/Places.zig
@@ -182,6 +182,7 @@ pub fn firstFrom(hits: []const Hit, at: usize) usize {
pub fn search(set: *Places, p: *Pardes, pane: *Pane, provenance: Provenance, from: u32, pattern: []const u8, literal: bool, seek: ?usize, moves: bool) void {
const f = if (pane.file) |*file| file else return;
const gpa = p.gpa;
+ set.derive(gpa);
// The same question again (a key that left the pattern as it was):
// the places stand, the current one too.
if (set.started and set.re != null and set.literal == literal and std.mem.eql(u8, set.pattern, pattern)) {
@@ -198,14 +199,12 @@ pub fn search(set: *Places, p: *Pardes, pane: *Pane, provenance: Provenance, fro
if (std.ascii.isUpper(c)) break false;
} else true;
set.literal = literal;
- const arena = p.scratch.allocator();
- const folded = if (set.fold) std.ascii.allocLowerString(arena, pattern) catch return else pattern;
- set.re = if (literal) null else normal.SearchRegex.compile(gpa, folded) catch null;
+ set.derive(gpa);
if (set.re == null) {
+ // It does not compile: the characters it is.
set.literal = true;
- var escaped: std.ArrayList(u8) = .empty;
- normal.appendSearchLiteral(&escaped, arena, folded) catch return;
- set.re = normal.SearchRegex.compile(gpa, escaped.items) catch return;
+ set.derive(gpa);
+ if (set.re == null) return;
}
set.started = true;
set.revision = f.revision +% 1; // `fill` starts it over for the text as it is
@@ -215,6 +214,25 @@ pub fn search(set: *Places, p: *Pardes, pane: *Pane, provenance: Provenance, fro
set.fill(p, pane, 0, frame_steps);
}
+/// `re` made from the pattern: derived (Places.replica), so neither a dump
+/// nor a rollback copy holds it, and a set loaded with a pattern and none
+/// was a list's to `fill` (a client that joined found no places an edit
+/// made, 2026-10-30). A list's places have no pattern.
+fn derive(set: *Places, gpa: std.mem.Allocator) void {
+ if (set.re != null or set.pattern.len == 0) return;
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const folded = if (set.fold) std.ascii.allocLowerString(a, set.pattern) catch return else set.pattern;
+ if (!set.literal) {
+ set.re = normal.SearchRegex.compile(gpa, folded) catch null;
+ return;
+ }
+ var escaped: std.ArrayList(u8) = .empty;
+ normal.appendSearchLiteral(&escaped, a, folded) catch return;
+ set.re = normal.SearchRegex.compile(gpa, escaped.items) catch null;
+}
+
/// A list's places in this text, as it gives them (sorted here), in place
/// of whatever fed them before: a language server's references, say.
/// `current`: the one at or after this offset is current.
@@ -397,6 +415,7 @@ fn restart(set: *Places, p: *Pardes, f: *File.State) void {
pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) void {
const started_ns = nowNs();
if (!set.started) return;
+ set.derive(p.gpa);
const f = if (pane.file) |*file| file else return set.clear(p.gpa);
const gpa = p.gpa;
if (f.revision != set.revision or f.content.len != set.len) {
@@ -912,3 +931,28 @@ test "a lowered copy's pieces not searched yet are the same in every process: a
}
try std.testing.expectEqual(digests[0], digests[1]);
}
+
+test "a session's places loaded from its dump find what an edit makes as the session's do" {
+ // A client's core is the session's dump; `re` is derived, in no dump:
+ // made again from the pattern, else the loaded set took itself for a
+ // list's and found nothing an edit made (a soak's rejoin loop).
+ const gpa = std.testing.allocator;
+ const a = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer a.deinit();
+ const pane = try a.setTestFile("alpha beta\ngamma alpha\n");
+ typeKeys(a, "e*");
+ try std.testing.expectEqual(@as(usize, 2), pane.places.hits.items.len);
+ const bytes = try pardes.dump.dumpBytes(a);
+ defer gpa.free(bytes);
+ const b = try pardes.dump.load(gpa, a.opts, bytes, null);
+ defer b.deinit();
+ try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b));
+ for ([_]*Pardes{ a, b }) |p| {
+ const pn = p.panes[p.active].?;
+ const new = try gpa.dupe(u8, "alpha beta\ngamma alpha alpha\n");
+ File.setContentSpan(p, &pn.file.?, new, null);
+ pn.places.fill(p, pn, 0, frame_steps);
+ try std.testing.expectEqual(@as(usize, 3), pn.places.hits.items.len);
+ }
+ try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b));
+}