From 89f51118eb241fdb5673e91eb09e5abe5c6a0bcb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 03:03:28 -0300 Subject: Pick, Query, Stream: Find and Grep search the work tree, the nearest directory at or above the asking pane's that holds a `.jj` or a `.git`, or the pane's directory outside one, and a leading directory narrows a Grep (the comparison video's finding, VIDEO2/STORY.md §3.1 and §9: from src/torque in V8 `SPC f f` listed its 67 files where Helix, LazyVim and Doom list 18,441, and `SPC f g` found 11 hits in src/torque alone; SPEC §5.1's "scoped to a directory if the query starts with one" found nothing; the coordinator's W8, the user asked, the default yes); THE CAUSE: Pick.open set every source's directory to the asking pane's (Pardes.paneDir), and Pick.filter sent a Grep's whole query to the disk engine as its pattern; THE FIX: Pick.workTree (Find and Grep only: Recent, Panes and Symbols as they were), a stat of `.jj` and `.git` per directory up from the pane's through the tape's kind site, once per picker opened; the rows' paths are from the root (Find's `src/torque/torque-parser.cc`), so Names' subsequence match over the whole path makes `torque/pars` narrow Find with no more code; Pick.grepScope: a query whose first word, then a blank, is a directory under the root (or absolute) searches that directory for the rest (`src/torque "UpperCamelCase"`); its rows' paths stay from the root (Query.take's `under`, the narrowed directory before each path; the query pane passes none), and the preview lights the pattern alone; no directory added to the head (the coordinator's rule: none was shown); RUN (TEST FIRST): Pick.zig "Find and Grep search the work tree (W8) ..." makes a tree with `.git` at its root and opens Find from src/deep/x.txt: its directory the root (on W7's tree src/deep), three rows, `sub/name` one, `sub/name.txt`; Grep `needle` two hits, `sub needle` one, `sub/name.txt:1 needle one`, its place the root's sub/name.txt; from `/held.txt` (no repository above /) the directory `/`; the tests whose Find or Grep pickers list a temporary directory make it a work tree of its own (Pick.testFile, and four tests in behaviour/addons.zig, addons_pdf.zig and other_files.zig): under the repository's .zig-cache it is in the pardes tree; MEASURED on a reflink copy of VIDEO2's V8 (18,441 files) with this change's Debug gui at 26 px, from src/torque/torque.cc, after the last key (V4's probe in brackets, the installed build): SPC f f 18,414 rows, the first at 0.10-0.11 s and all at 0.14-0.16 s [0.02 s, 67 files: src/torque alone]; `torque/pars` 7 rows at 0.09 s, torque-parser.cc among them [0 rows]; Grep `"UpperCamelCase"` 11 hits from the root at 0.26 s, its typing pause included [0.11 s, 11 hits, src/torque alone]; `src/torque "UpperCamelCase"` the same 11 at 0.15 s [nothing]; this harness on the installed build: 67 files at 0.05 s, the grep 0.11-0.13 s; keys typed through the frontend (the S kit's pty): a key written to 9P's kbdin runs the listing and the search on the loop for its write's answer (Pick.start and filter's `p.fs.serving` step), so a script's `SPC f g` over V8 holds the session for seconds (seen: the 9P client timed out), as before this change over a smaller directory; the find golden (test/snapshots/find.golden) re-recorded: from sub/ZQMARK-beta.txt `SPC f f` lists the root's five files, a band row more; replica.zig's may_wait lists `Find *` and `Grep *` stopping at `kind` (the root asked of the session's disk, as their listing and search are); gates: core-test 1129/1302 (173 skipped: +1), shell-test 1350/1353 (3 skipped: +1), pane-test 183/184, behaviour-test 285/285 and --replay 285/285, process-test 0 of 147 failed (3 skipped; find re-recorded), term-test 17/17, kitty-test 45/45, the gui unit-test 1958/1962 (4 skipped; its perf check's BaselineHarnessMismatch, every base's) on this change, W7 under it; no dump change; shots .scratch/walkui/W78/png v1-v3; no frame or perf gate (the user's rule of 2026-11-26); load 3.7 to 15.9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Query.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'core/Query.zig') diff --git a/core/Query.zig b/core/Query.zig index 2b2abebb..fff6065c 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -1269,7 +1269,7 @@ fn countGrepCurrent(q: *Query) void { /// picker (Pick.zig: the same fields): a Grep's lines (`path:line:col-end /// code`, relative to the pane's directory) kept as found, a listing's /// names added to what Find scores. -pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8) void { +pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8, under: []const u8) void { var lines = std.mem.splitScalar(u8, rows, '\n'); while (lines.next()) |ln| { if (ln.len == 0) continue; @@ -1286,13 +1286,14 @@ pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8) void { const name = if (ln[0] == '"') look.unquoted(&namebuf, t.path) else t.path; const found: Found = .{ .path = std.math.cast(u32, q.found_bytes.items.len) orelse return, - .path_len = std.math.cast(u16, name.len) orelse continue, + .path_len = std.math.cast(u16, under.len + name.len) orelse continue, .line = std.math.cast(u32, t.at.line) orelse continue, .col = std.math.cast(u32, t.at.col -| 1) orelse continue, .end = std.math.cast(u32, if (t.at.end_col > 0) t.at.end_col else t.at.col) orelse continue, - .code = std.math.cast(u32, q.found_bytes.items.len + name.len) orelse return, + .code = std.math.cast(u32, q.found_bytes.items.len + under.len + name.len) orelse return, .code_len = std.math.cast(u32, code.len) orelse continue, }; + q.found_bytes.appendSlice(p.gpa, under) catch return; q.found_bytes.appendSlice(p.gpa, name) catch return; q.found_bytes.appendSlice(p.gpa, code) catch return; q.found.append(p.gpa, found) catch return; @@ -2811,7 +2812,7 @@ test "Grep: a row whose numbers a Found cannot hold (a column past u32) is passe defer p.deinit(); var q: Query = .{ .owner = 0 }; defer q.deinit(p.gpa); - take(p, &q, .grep, "a:5000000000:b:3:1-4 hit\nok.txt:2:3-5 hit\nb:7:4294967297 hit\n"); + take(p, &q, .grep, "a:5000000000:b:3:1-4 hit\nok.txt:2:3-5 hit\nb:7:4294967297 hit\n", ""); // Taken or passed over, each: never cast (main: Query.zig:1267). try std.testing.expect(q.found.items.len <= 3); } -- cgit v1.3