From 148e48dd9b8cd7e66aa1521daa49a64852b1650e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 02:28:09 -0300 Subject: syntax, Query, Pick, Names, Band, Stream, File, colors: the Symbols picker grouped by kind, a kind mark on each row (UX DESIGN N, binding; the user: "The lsp symbols should be more organized: types first then functions then fields and the rest (and some indicator to tell the kind)", "For the symbols picker"): the rows are the file's own parse's, as before, now from a symbol walk of their own (syntax.zig `SymbolWalk`, in the same walk of the tree as the sticky headers' declarations, which keep theirs: contextFromTree), by one kind table a grammar (`symbol_rules`: Zig, C, C++, Rust, Go, Python, JavaScript, Java, C#, Kotlin, Scala, Ruby, PHP, bash, Haskell, OCaml, Erlang, Elixir, Clojure, Fortran, Ada, Pascal, PowerShell; JSON, CSS, HTML, Markdown and Typst have no declarations to list), each node's kind as given or found where its grammar cannot say it (Zig's `const S = struct`, `error{...}`, `@This()`, `@Type(...)` a type and `@import(...)` a module, JavaScript's `const f = () => ...` a function, C's declaration a function where a declarator is one's and a const where `const` says so, a Python class's or Kotlin's binding a field in a type); fields and consts are listed now (the sticky headers' declarations had neither), a function's consts and vars never (its locals), each named in the types, functions and modules it is in (`Counts.lines`, `torque.Parser.Parse`; an anonymous struct's members in its owner's, a Rust `impl S`'s in `S`, no row of its own); a row is `t Counts = struct`: its kind's mark (t type, f function, m field, c const, v var, n module, · other), its qualified name, two blanks and what its name's line says after the name (its body's `{`, a trailing `,` or `;` dropped), its line the dim meta at the right end (Band's); the mark in the keyword's ink (colors.Roles.kind, the theme's keyword pushed to 4.5:1 on every tag ground and the selection, as the key ink is), the qualifier and the words after the name dim; with the field empty the rows are types, functions, fields, then the rest (consts, vars, modules, other as one group), each in the text's order; typed, they stay grouped and are scored within each group (Names: `Cand.group`, `before` orders by it, then by `better`), the cursor starts on the best match wherever its group puts it (Names.bestRow, Pick.toBest: after a key, when the parse lands, and following the best while the rest are scored), and the count says where it is; the name alone is matched (`u8` in a signature matches nothing); no header rows: every row is a symbol, ordinary text, and C-q keeps them in a +Search with the mark a word; the query pane's `Symbols` rows the same (Query.gather), its current the best; the parse's answer carries the symbols beside the declarations (Stream.Batch.symbols, an input every replica takes), ContextCache keeps both for the revision (derived, made again at a load), and every producer makes both (the worker, a sticky header's refresh, a load), so a text at a revision has the same symbols everywhere; syntax.zig's tests ran in no test program (core-test's filter `syntax context nested` matched nothing on the base): core/root.zig imports it now, and its 34 pass; RUN (TEST FIRST): syntax.zig "syntax symbols: a Zig file's types, functions, fields and the rest ...", "... C, C++, Rust, Go, Python and JavaScript by their kind tables ...", "... every kind table names nodes of its grammar ..." (23 tables), Pick.zig "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then the rest ... the mark in the keyword's ink, the qualifier and the rest dim", "Symbols (UX DESIGN N3): typed, the rows stay grouped ... the cursor starts on the best match ...; the name alone is matched, never the signature", "Symbols (UX DESIGN N): a C++ file's rows ...", "Symbols: every row is ordinary text ..."; on the base the rows were ` 2 pub const Counts = struct {` in the text's order, no mark, no field, the cursor on the first row; core-test -Dtest-filter=ymbols 18/18, core-test 1135/1308 (173 skipped); the stack's suites, the dump fuzz, the soak and the pictures are on the change after this one 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/Stream.zig | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'core/Stream.zig') diff --git a/core/Stream.zig b/core/Stream.zig index e9e7793b..50c43ae4 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -67,10 +67,11 @@ pub const Batch = struct { end: ?End = null, /// A parse's own time on the worker (`parse_ns`). took_ns: u64 = 0, - /// A parse's answer (`parseFor`): the declarations of pane `serial`'s - /// text at `revision`. + /// A parse's answer (`parseFor`): the declarations and symbols of pane + /// `serial`'s text at `revision`. parsed: ?struct { serial: u32, revision: u32 } = null, decls: []syntax.ContextDeclaration = &.{}, + symbols: []syntax.Symbol = &.{}, /// A paint's answer (`paintAhead`): the colours of pane `serial`'s text /// at `revision` from byte `start`, one syntax.Syn a byte. painted: ?struct { serial: u32, revision: u32, start: usize } = null, @@ -83,6 +84,7 @@ pub const Batch = struct { pub fn deinit(b: *const Batch, gpa: std.mem.Allocator) void { gpa.free(b.rows); gpa.free(b.decls); + gpa.free(b.symbols); gpa.free(b.styles); } }; @@ -480,9 +482,9 @@ pub fn parseFor(p: *Pardes, id: usize) void { fn parseWork(io: std.Io, job: *TextJob, ctx: ?*anyopaque, sink: Sink) void { const began = std.Io.Clock.awake.now(io); - const decls: []syntax.ContextDeclaration = syntax.declarationsApart(job.out, job.path, job.source, &job.stop) catch @constCast(&[_]syntax.ContextDeclaration{}); + const made: syntax.Context = syntax.contextApart(job.out, job.path, job.source, &job.stop) catch .{}; const took: u64 = @intCast(@max(0, began.durationTo(std.Io.Clock.awake.now(io)).nanoseconds)); - _ = sink(ctx, .{ .gen = job.gen, .decls = decls, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took }); + _ = sink(ctx, .{ .gen = job.gen, .decls = made.declarations, .symbols = made.symbols, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took }); } fn now() u64 { @@ -732,12 +734,15 @@ fn receiveParse(p: *Pardes, b: *const Batch, serial: u32, revision: u32) void { t.job.deinit(); }; s.parse_ns = b.took_ns; - if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and b.decls.len > 0) { - if (p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls)) |copy| { - f.context.replace(p.tree_sitter_gpa, copy, revision); - panes.Query.declsArrived(p, serial); - panes.Pick.declsArrived(p, serial); - } else |_| {} + if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and (b.decls.len > 0 or b.symbols.len > 0)) kept: { + const decls = p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls) catch break :kept; + const symbols = p.tree_sitter_gpa.dupe(syntax.Symbol, b.symbols) catch { + p.tree_sitter_gpa.free(decls); + break :kept; + }; + f.context.replace(p.tree_sitter_gpa, .{ .declarations = decls, .symbols = symbols }, revision); + panes.Query.declsArrived(p, serial); + panes.Pick.declsArrived(p, serial); }; p.needs_frame = true; // A `Churn` waiting on these declarations (jj.zig). -- cgit v1.3 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/Jump.zig | 2 + core/Pick.zig | 117 ++++++++++++++++++++++++++++++++++++++--- core/Query.zig | 9 ++-- core/Stream.zig | 2 +- core/replica.zig | 2 + test/behaviour/addons.zig | 8 +++ test/behaviour/addons_pdf.zig | 2 + test/behaviour/other_files.zig | 2 + test/snapshots/find.golden | 3 ++ 9 files changed, 136 insertions(+), 11 deletions(-) (limited to 'core/Stream.zig') diff --git a/core/Jump.zig b/core/Jump.zig index 3632a039..143aa9b5 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -472,6 +472,8 @@ test "Ctrl-o pops the walk one word at a time (UX L'1): after SPC f f words, Ent defer p.deinit(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); var text: [60 * 16]u8 = undefined; var w: std.Io.Writer = .fixed(&text); for (1..61) |n| try w.print("{s} {d}\n", .{ if (n % 12 == 4) "in_word" else "line", n }); diff --git a/core/Pick.zig b/core/Pick.zig index f13278af..cfef2baf 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -226,7 +226,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err); pk.word.set(if (word.len > 0) word else words.get(source).word); pk.keys.set(words.get(source).keys); - pk.dir.set(Pardes.paneDir(asker)); + // Find and Grep from the work tree's root (W8), as other finders search. + pk.dir.set(if (source == .find or source == .grep) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker)); pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err); hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err); if (p.paneBySerial(pk.landing)) |host| pk.cap = p.view().rects[host].h * 2 / 5; @@ -237,6 +238,35 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] if (source == .themes and query.len == 0 and p.custom_theme == null) p.view().tag_state.rows.at = @intCast(p.settings.theme); } +/// The work tree `dir` is in: the nearest directory at or above it that +/// holds a `.jj` or a `.git` (a git worktree's is a file); `dir` itself +/// when none does. Find and Grep search from it, their rows' paths +/// relative to it, wherever in the tree the asking pane is. +fn workTree(p: *Pardes, dir: []const u8) []const u8 { + var d = dir; + while (true) { + var buf: [4096]u8 = undefined; + for ([_][]const u8{ ".jj", ".git" }) |name| { + const marker = std.fmt.bufPrint(&buf, "{s}/{s}", .{ std.mem.trimEnd(u8, d, "/"), name }) catch return dir; + if (exec.kindOf(p.tape, marker) != null) return d; + } + d = std.Io.Dir.path.dirname(d) orelse return dir; + } +} + +/// Where a Grep's query `q` searches and for what (SPEC §5.1): a leading +/// directory, the root's or absolute, then a blank, narrows it to that +/// directory (`src/torque Macro`), the rest the pattern; else all of it +/// from the root. The directory joined in `buf`. +fn grepScope(p: *Pardes, pk: *const Pick, q: []const u8, buf: *[4096]u8) struct { dir: []const u8, pat: []const u8 } { + const root = pk.dir.slice(); + const sp = std.mem.indexOfScalar(u8, q, ' ') orelse return .{ .dir = root, .pat = q }; + const lead = q[0..sp]; + const dir = if (lead[0] == '/') lead else std.fmt.bufPrint(buf, "{s}/{s}", .{ std.mem.trimEnd(u8, root, "/"), lead }) catch return .{ .dir = root, .pat = q }; + if (exec.kindOf(p.tape, dir) != .directory) return .{ .dir = root, .pat = q }; + return .{ .dir = dir, .pat = std.mem.trimStart(u8, q[sp + 1 ..], " ") }; +} + /// A new picker in the ring, the oldest kept one dropped for it. fn make(p: *Pardes, source: Source) !*Pick { var slot: ?usize = null; @@ -456,8 +486,10 @@ pub fn filter(p: *Pardes, pk: *Pick) void { if (pk.source == .grep) { pk.found.clearRetainingCapacity(); pk.found_bytes.clearRetainingCapacity(); - if (q.len > 0) { - Stream.query(p, pk.id, .grep, q, pk.dir.slice(), if (p.fs.serving) .now else .typed) catch |err| return p.reportError(.at(p.view().active), "pick", err); + var buf: [4096]u8 = undefined; + const at = grepScope(p, pk, q, &buf); + if (at.pat.len > 0) { + Stream.query(p, pk.id, .grep, at.pat, at.dir, if (p.fs.serving) .now else .typed) catch |err| return p.reportError(.at(p.view().active), "pick", err); if (p.fs.serving) Stream.step(p); } else if (p.stream.target == pk.id) _ = p.stream.stop(); return; @@ -501,7 +533,12 @@ fn allPanes(p: *const Pardes, pk: *const Pick, out: *[pardes.MAX_PANES]usize) [] /// The disk engine's rows for picker `target` (Stream.receive). pub fn take(p: *Pardes, target: u32, kind: Stream.Kind, rows: []const u8) bool { const pk = byId(p, target) orelse return false; - Query.take(p, pk, kind, rows); + // A Grep narrowed to a directory (grepScope): its rows' paths from the + // root, as an unnarrowed one's are. + var buf: [4096]u8 = undefined; + const searched = p.stream.dir.items; + const under = if (kind == .grep and !std.mem.eql(u8, searched, pk.dir.slice())) std.fmt.bufPrint(&buf, "{s}/", .{relative(searched, pk.dir.slice())}) catch "" else ""; + Query.take(p, pk, kind, rows, under); // A listing's names, scored as they come. if (kind == .files) pk.names.rescore(p.gpa); return true; @@ -626,7 +663,8 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me var marks: std.ArrayList(u16) = .empty; var c = fd.col; while (c < fd.end and c >= lead and pre.len + 1 + c - lead < text.len) : (c += 1) try marks.append(arena, @intCast(pre.len + 1 + c - lead)); - const path = try std.Io.Dir.path.join(arena, &.{ dir, name }); + // (Under an absolute leading directory, grepScope's, an absolute path.) + const path = if (name.len > 0 and name[0] == '/') name else try std.Io.Dir.path.join(arena, &.{ dir, name }); return .{ .text = text, .pre = @intCast(pre.len), .marks = marks.items, .target = .{ .place = .{ .path = path, .at = .{ .line = fd.line, .col = fd.col + 1 } } } }; } var marks: [Names.max_query * 4]u16 = undefined; @@ -987,7 +1025,10 @@ fn preview(p: *Pardes, pk: *Pick) void { } look.focusPaneLine(p, id, at, .third); // A Grep's matches in the file lit, as its own pane would have them. - if (pk.source == .grep) pane.places.search(p, pane, .list, pk.id, std.mem.trim(u8, s.field.text(), " "), true, null, false); + if (pk.source == .grep) { + var buf: [4096]u8 = undefined; + pane.places.search(p, pane, .list, pk.id, grepScope(p, pk, std.mem.trim(u8, s.field.text(), " "), &buf).pat, true, null, false); + } } /// Landing pane `id`'s text `bytes` (taken) as `path`: its own text set @@ -2067,6 +2108,9 @@ pub fn execWord(p: *Pardes, txt: []const u8) bool { } fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 { + // The directory a work tree of its own, as a project is: Find and Grep + // search it, not the tree the test runs in. + tmp.dir.createDir(std.testing.io, ".git", .default_dir) catch |err| if (err != error.PathAlreadyExists) return err; try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = text }); var base_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; @@ -3351,3 +3395,64 @@ test "Ctrl-r in a picker unrolls its source's earlier queries (UX L2's last line p.update(.{ .key = .{ .cp = Key.escape } }); p.update(.{ .key = .{ .cp = Key.escape } }); } + +test "Find and Grep search the work tree (W8): from a pane deep in a repo Find lists the files from its root and `sub/name` narrows it, a leading directory narrows Grep, and outside a repo they search the pane's directory" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + p.settings.jumps = .walk; + p.stream.engine = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + for ([_][]const u8{ "src/deep", "sub", "other" }) |d| try tmp.dir.createDirPath(std.testing.io, d); + const deep = try testFile(p, &tmp, "src/deep/x.txt", "deep\n"); + defer p.gpa.free(deep); + for ([_][2][]const u8{ .{ "sub/name.txt", "needle one\n" }, .{ "other/name.txt", "needle two\n" } }) |f| p.gpa.free(try testFile(p, &tmp, f[0], f[1])); + const root = std.Io.Dir.path.dirname(std.Io.Dir.path.dirname(std.Io.Dir.path.dirname(deep).?).?).?; + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try p.gpa.dupe(u8, deep); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + // Find from src/deep: the root's files, by their paths from it. + open(p, asker, .find, "", "", ""); + var pk = live(p).?; + try std.testing.expectEqualStrings(root, pk.dir.slice()); + settle(p); + try std.testing.expectEqual(@as(usize, 3), count(p, pk)); + for ("sub/name") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + try std.testing.expectEqual(@as(usize, 1), count(p, pk)); + try std.testing.expectEqualStrings("sub/name.txt", (try rowAt(p, pk, a, 0)).text); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Grep: the whole tree, then `sub needle` in sub/ alone, its row's + // path from the root, landing on the file there. + open(p, asker, .grep, "", "", ""); + pk = live(p).?; + for ("needle") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + // (Its typing paused: the search starts.) + p.clock.now_ns = p.stream.due_ns.?; + settle(p); + try std.testing.expectEqual(@as(usize, 2), count(p, pk)); + p.update(.{ .key = .{ .cp = Key.escape } }); + open(p, asker, .grep, "", "", ""); + pk = live(p).?; + for ("sub needle") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + // (Its typing paused: the search starts.) + p.clock.now_ns = p.stream.due_ns.?; + settle(p); + try std.testing.expectEqual(@as(usize, 1), count(p, pk)); + const row = try rowAt(p, pk, a, 0); + try std.testing.expect(std.mem.startsWith(u8, row.text, "sub/name.txt:1 needle one")); + try std.testing.expectEqualStrings(try std.Io.Dir.path.join(a, &.{ root, "sub/name.txt" }), row.target.place.path); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Outside a repo (`/`, the test text's directory, holds no .jj nor + // .git): the pane's directory, as before. + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try p.gpa.dupe(u8, "/held.txt"); + open(p, asker, .find, "", "", ""); + try std.testing.expectEqualStrings("/", live(p).?.dir.slice()); + p.update(.{ .key = .{ .cp = Key.escape } }); +} 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); } diff --git a/core/Stream.zig b/core/Stream.zig index e9e7793b..93be5c1f 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -717,7 +717,7 @@ pub fn receive(p: *Pardes, b: *const Batch) void { const id = p.paneBySerial(s.target) orelse return; const q = p.panes[id].?.query orelse return; q.capped = s.state == .capped; - panes.Query.take(p, q, s.kind, b.rows); + panes.Query.take(p, q, s.kind, b.rows, ""); } /// A parse's answer: its task joined; the declarations kept as the pane's diff --git a/core/replica.zig b/core/replica.zig index 97cbaeee..d07ce9d3 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -7351,6 +7351,8 @@ const may_wait = [_]Wait{ .{ .what = "Save", .on = .any, .stop = "write_file", .why = "a save" }, // A program run, a shell opened or closed: the session's processes. .{ .what = "Exec *", .on = .any, .stop = "kind", .why = "a program run: its name asked of the disk first" }, + .{ .what = "Find *", .on = .any, .stop = "kind", .why = "the work tree it lists from, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the listing itself is the session's" }, + .{ .what = "Grep *", .on = .any, .stop = "kind", .why = "the work tree it searches, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the search itself is the session's" }, .{ .what = "Exec *", .on = .any, .stop = "tty_taken", .why = "a program run in a shell: whether one has it, the session's" }, .{ .what = "Term", .on = .any, .stop = "kind", .why = "a shell opened: its name asked of the disk first" }, .{ .what = "A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened" }, diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index 25b1e523..90f4e383 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -381,6 +381,8 @@ fn dirOf(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 { test "addons: a picker shows a file of an addon's kind through its kind in the pane it lands in, Esc puts that pane back as it was, and Enter lands as a Look does" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" }); var s = try Session.initFile(std.testing.allocator, "x\n"); @@ -421,6 +423,8 @@ test "addons: a picker shows a file of an addon's kind through its kind in the p test "addons: a picker's row of a file no kind takes and not text shows one line naming it, and the row before's file never stays in the body" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "other.txt", .data = "other text\n" }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" }); @@ -462,6 +466,8 @@ test "addons: a picker's row of a file no kind takes and not text shows one line test "addons: moving the cursor over pictures in a picker draws only the one it rests on, and a draw of one passed by is dropped whenever it comes back" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); const png = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\xc9\xfe\x92\xef\x00\x00\x00\x00IEND\xaeB`\x82"; try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic1.png", .data = png }); @@ -499,6 +505,8 @@ test "addons: moving the cursor over pictures in a picker draws only the one it test "addons: Enter on a picture in a picker opens its kind's pane, never its bytes as text in the reading pane (the user's report)" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" }); var s = try Session.initFile(std.testing.allocator, "x\n"); diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig index d773f4e2..eca39012 100644 --- a/test/behaviour/addons_pdf.zig +++ b/test/behaviour/addons_pdf.zig @@ -307,6 +307,8 @@ test "addons: a PDF under a picker's cursor shows through the pdf addon in the p try s.loadPdf(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); const pdf = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "docs/design.pdf", s.arena.allocator(), .limited(4 << 20)); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paper.pdf", .data = pdf }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index e6c104c3..8a9016bc 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -25,6 +25,8 @@ test "other-files: kbdin types at the pane with the keyboard and mousein clicks, test "other-files: kbdin's keys are the user's: SPC f f opens Find's picker in the pane's tag where jumps walk, not the +Search a script's Find opens" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" }); var s = try Session.initFile(std.testing.allocator, "x\n"); diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index 34333048..905c35e8 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -80,6 +80,7 @@ |5: │ │ |6: │ │ |7: │ │ +|8: │ │ |40: ⏎ lands here · its text is the preview · S-⏎ a new pane 1 message · SPC h m == snap cancel grid=120x41 cursor=7,3 |2: here.txt:1 › Find zqm 2/3 › /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Keep Save Term Collapse Follow Del @@ -88,6 +89,7 @@ |5: |6: |7: +|8: |40: ✓ /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Find 1 message · SPC h m == snap topbar grid=120x41 cursor=29,2 |2: ^ Find zqm 2/3 › ␣ f Find bod 0 @@ -96,4 +98,5 @@ |5: │ │ |6: │ │ |7: │ │ +|8: │ │ |40: ⏎ lands here · its text is the preview · S-⏎ a new pane 1 message · SPC h m -- cgit v1.3