From 280306ed779368d7e20e9678eca45e4b81e0ccbf Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 03:03:20 -0300 Subject: Pick, Kind, look, draw, mouse: a picker previews a file an addon's kind takes through that kind in the pane it lands in, a binary no kind takes as one line naming it, and Enter on such a row lands as a Look does, never the file's bytes as text (the user: "the file preview wasn't working for images (maybe pdfs too? Didn't test)", "It should be a generic logic for addons btw, and I saw the bytes rendered as ascii"; the coordinator's W7 under SPEC principle 2); REPRODUCED with the installed build (install74, the S kit, 26 px): SPC f f from a reading main.zig, the cursor on photo.png left main.zig in the body (the previous row's file), on paper.pdf showed `%PDF-1.7 %âãÏÓ 1 0 obj …` as text (a PDF has no NUL in its first 8000 bytes, so Pick.preview's binary guard let it through), and Enter on photo.png put `�PNG … IHDR …` in the reading pane: THE BYTES-AS-TEXT PATH the user saw: Pick.land → look.open → walk → Trail.step → Trail.show → File.open, which reads any path as a text (look.resolve sends a typed or clicked `photo.png` to Kind.openFile, but look.open, every jump's way, had no kind route); THE FIX: look.open routes a path a kind takes (`kinds.forPath`, the routing resolve uses) to openKind, lookAt's kind branch made a function (the pane of it focused, else opened and placed as a Look places it), so a picker's Enter, the Walk queue and a held pane's step land as a Look; Find's row of a kind's file is the file whole (a place in it is its kind's address: line 1 made the image refuse it); Pick.preview: a file a kind takes is shown by a slot of that kind over the landing pane's text (Kind.newSlot, split from Kind.open; Pick.showKind), which stays under it unseen until the next row or the roll-up closes the slot (putBack, restore: Esc exact, nothing left), no per-kind code; any other file with a NUL is one read-only line, `blob.bin · binary · 3.0 kB` (Pick.nameLine); until the kind draws (its paint places nothing yet) the body shows `photo.png · image · 24.8 kB` (draw.zig; Kind.draw says whether it painted); a refused one is that line with its kind's why; the kind does its own work as for its pane (the image decoded on a worker); only the row the cursor rests on at a frame opens (the preview's existing tick rule), and a draw of a row passed by is dropped when it lands (Kind.Slot.drawn_from: this process's draw count when the slot was made; Kind.deliver drops older answers, which went to the next slot of the same kind on the same pane); a previewed kind says, looks at, runs and lists nothing (Kind.Call.end returns before them while Pick.previewing) and takes no mouse (mouse.kindMouse); RUN (TEST FIRST): test/behaviour/addons.zig, four tests through 9P with the fake addon (addons/fake: no kind code in Pick) and the image addon, and addons_pdf.zig one with the pdf addon: a `.fake` file previews as the fake's paint (`count 7`) and not its bytes, Esc puts the screen and /index back, Enter opens the fake's pane with the reading pane's text kept; blob.bin's one line, never other.txt's text after it, a kind's paint after the binary's; three pictures, two rows down with no frame between: one draw held per rested row (2, not 3), and the rested picture shown after the passed one's answer came last; Enter on a picture opens the image pane, the reading pane `the notes`; a PDF's pages as pictures in the landing pane, none after Esc; Session.tick (a host frame) added, as previews wait for the frame after the key; on the base they fail (the bytes `1234567` shown, no line, no image pane, `%PDF` on the screen): core-test 1128/1301 (173 skipped; the kept_out list names Kind.Slot's drawn_from and size), shell-test 1349/1352 (3 skipped), pane-test 183/184, behaviour-test 285/285 (+5) and --replay 285/285, process-test 0 of 147 failed (3 skipped), term-test 17/17, kitty-test 45/45; the gui unit-test on the stack's top (W8); no dump change (the two Slot fields are local, out of the digest and the dump); the S kit with this change's Debug gui at 26 px: the PNG and 9p.pdf previewing in the landing pane, blob.bin's line, Enter on photo.png an `img` pane with main.zig kept (.scratch/walkui/W78/png a02-a05, before r03 r05); no frame or perf gate (the user's rule of 2026-11-26); load 3.7 to 10 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 --- test/behaviour/addons.zig | 146 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) (limited to 'test/behaviour/addons.zig') diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index ce3c7b02..25b1e523 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -371,3 +371,149 @@ test "addons: an image pane whose file changes on disk shows the new picture, un try std.testing.expectEqual(n, try s.focused()); try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,3,1]")); } + +/// A tmp directory's real path, kept in the session's arena. +fn dirOf(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 { + var buf: [4096]u8 = undefined; + return s.arena.allocator().dupe(u8, buf[0..try tmp.dir.realPath(std.testing.io, &buf)]); +} + +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(); + 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"); + defer s.deinit(); + try load(&s, fake.ok); + defer unload(&s, "fake"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + const body = s.at("/pane/{d}/body", .{pane}); + const a = s.arena.allocator(); + const screen = try a.dupe(u8, try s.screen()); + const index = try a.dupe(u8, try s.read("/index")); + // Its kind's paint in the reading pane's body (the fake counts the + // file's 7 bytes), not the pane's own text, nor the file's bytes. + try s.keys(" ffseven"); + s.tick(); + const shown = try s.screen(); + try std.testing.expect(has(shown, "count 7")); + try std.testing.expect(!has(shown, "the notes") and !has(shown, "1234567")); + // Esc: the pane exactly as it was, and no pane more or less. + try s.keys("\x1b"); + s.tick(); + // (The notice row says the Find ran: the session's, not the pane's.) + const after = try s.screen(); + try std.testing.expectEqualStrings(screen[0..std.mem.lastIndexOfScalar(u8, screen, '\n').?], after[0..std.mem.lastIndexOfScalar(u8, after, '\n').?]); + try s.expect(body, "the notes\n"); + try std.testing.expectEqualStrings(index, try s.read("/index")); + // Enter: the kind's pane where a Look puts it; the reading pane keeps + // its text. + try s.keys(" ffseven\n"); + s.tick(); + const opened = try paneOf(&s, "fake"); + try std.testing.expect(opened != pane); + try s.expect(body, "the notes\n"); + try std.testing.expect(has(try s.screen(), "count 7")); +} + +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(); + 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" }); + var blob: [3000]u8 = undefined; + for (&blob, 0..) |*b, i| b.* = @truncate(i *% 7); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "blob.bin", .data = &blob }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try load(&s, fake.ok); + defer unload(&s, "fake"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + try s.keys(" ffother"); + s.tick(); + try std.testing.expect(has(try s.screen(), "other text")); + // Onto the binary: its one line, never its bytes, nor other.txt. + try s.keys("\x08\x08\x08\x08\x08blob"); + s.tick(); + var shown = try s.screen(); + try std.testing.expect(has(shown, "blob.bin · binary · 3.0 kB")); + try std.testing.expect(!has(shown, "other text")); + // Onto a kind's file: its kind's paint, not the binary's line. + try s.keys("\x08\x08\x08\x08seven"); + s.tick(); + shown = try s.screen(); + try std.testing.expect(has(shown, "count 7")); + try std.testing.expect(!has(shown, "blob.bin · binary")); + // Back onto text, then Esc: the pane's own. + try s.keys("\x08\x08\x08\x08\x08other"); + s.tick(); + shown = try s.screen(); + try std.testing.expect(has(shown, "other text") and !has(shown, "count 7")); + try s.keys("\x1b"); + s.tick(); + try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n"); + try std.testing.expect(has(try s.screen(), "the notes")); +} + +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(); + 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 }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic2.png", .data = png }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic3.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + s.graphics(); + try load(&s, Session.image_addon); + defer unload(&s, "image"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + s.holdJobs(); + try s.keys(" ffpic"); + s.tick(); + // Until its picture is drawn, one line names it. + const first = try s.screen(); + try std.testing.expect(has(first, " · image · ")); + try std.testing.expectEqual(1, s.held.items.len); + // Two rows down with no frame between: only the row it rests on draws. + try s.keys("\u{F800}\u{F800}"); + s.tick(); + _ = try s.screen(); + try std.testing.expectEqual(2, s.held.items.len); + const rested = if (has(try s.screen(), "▶ pic3.ppm")) "\"src\":[0,0,2,1]" else "\"src\":[0,0,1,1]"; + const passed = if (std.mem.eql(u8, rested, "\"src\":[0,0,2,1]")) "\"src\":[0,0,1,1]" else "\"src\":[0,0,2,1]"; + // The rested one's answer first, the passed one's after: dropped. + std.mem.reverse(@TypeOf(s.held.items[0]), s.held.items); + s.releaseJobs(); + const screen = try s.read("/screen"); + try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{pane})) and has(screen, rested)); + try std.testing.expect(!has(screen, passed)); +} + +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(); + 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"); + defer s.deinit(); + s.graphics(); + try load(&s, Session.image_addon); + defer unload(&s, "image"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + try s.keys(" ffpic\n"); + s.tick(); + try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n"); + const image = try paneOf(&s, "image"); + try std.testing.expect(image != pane); + const screen = try s.read("/screen"); + try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{image})) and has(screen, "\"src\":[0,0,2,1]")); + try std.testing.expect(!has(try s.screen(), "1 P6")); +} -- 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 'test/behaviour/addons.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 From 849542a05f7be03f37a0e6444e0eb70fb4dbea0c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 06:14:26 -0300 Subject: ninep/ctl, Pick, Names: a key written to 9P's kbdin (and a mouse line to mousein) takes the keyboard's path: the write is answered once its keys are handled, and what they start runs on a worker as the keyboard's does, its rows after (agent W78's find, rqouyxqp's description: a scripted `SPC f g` over V8's 18,441 files held the session until the 9P client timed out; and W6's: kbdin's Symbols picker over a text of more than 64 KB listed nothing); THE CAUSE: writeKbdin and writeMousein ran their keys inside serveFs with `p.fs.serving` set, which these places read as "a script's write, answered with its result": Pick.start and filter (Find's listing and Grep's search stepped on the loop, `.now`), Query (a query pane's), Stream.step (runHere, not the worker), Stream.parseFor (no worker: a text over 64 KB never parsed), paintAhead and paintRows, builtins' search (a miss said to the write), look (a tty pane's click searched), edit_cmd (the write held for an Edit's filters), panes (a Save's question to /log) and lsp/Ask (the write waits for the server's answer); `fs.typed` made Pick.asked alone take the keys as the user's; THE FIX: writeKbdin and writeMousein run their keys with `serving` off and put it back after, so every one of those places takes the keyboard's path for typed keys and keeps the script's for a script's write; `fs.typed` has no reader and goes (FsState, its replica list); A CRASH IT UNCOVERED: with the parse on a worker, Pick.declsArrived scored the declarations that came by typing the picker's own query again, `names.typed(gpa, names.queryText())`, and Names.typed copied the query onto itself with @memcpy, `@memcpy arguments alias`, a panic in a safe build (the installed ReleaseSafe's): a keyboard's `SPC s s` whose query was typed before its file's parse landed (a big file) killed the session; Names.typed copies with copyForwards; ACCEPTED (the coordinator): a kbdin `gd` no longer waits for the server's answer, nor a kbdin `SPC f f` for its rows: a script reads them after, as a keyboard user sees them a frame later (docs/typ/reference.typ's kbdin says so; a script that wants the answer in its write writes the word to a pane's ctl, `Def`, `Find x`, which still waits); RUN (TEST FIRST): process/other_files.zig "kbdin's SPC f f over a work tree of 20,000 files is answered before the listing, which a worker runs as the keyboard's, its rows after" (a detached session, a tree of 200 directories of 100 files with a `.git`, `SPC f f zzlast` in one kbdin write timed, then /screen read until zzlast.txt's row shows): on T2 the write took 46-47 ms and the row was there at 62-63 ms (the listing ran in the write), now the write takes 3 ms and the row comes at 58-60 ms (three runs); "kbdin's SPC s s lists the declarations of a file over 64 KB, parsed on a worker as the keyboard's are" (4,001 two-line functions, 80 KB, `SPC s s zzlast`): on T2 nothing in 20 s, with the fix alone the session died at Pick.declsArrived (the probe, .scratch/walkui/T23/symprobe.sh: `panic: @memcpy arguments alias` at Names.zig typed), now its row in under a second; Names.zig "Names takes its own query typed again: ..." types a query, adds two names and types its own query again: panics before (`@memcpy arguments alias`), one hit now; behaviour tests that read a picker's rows in the write that typed its keys read them a frame later (Session.tick): other_files.zig's SPC f f, and addons.zig's two `SPC f f ...` then Enter, now the query, a tick, then Enter (Enter typed before the rows came picks none, for a keyboard too); a user hit the stall with any script driving a session's keys over a big tree, and the crash with `SPC s s` typed ahead of a big file's parse; NEW HOT PATHS: none (a write of keys saves and puts back one flag); GATES: core-test 1131/1305 (174 skipped: +1), shell-test 1353/1356 (3 skipped: +1), pane-test 183/184, behaviour-test 286/286 and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 149 failed (3 skipped: +2), term-test 17/17, kitty-test 45/45, the gui unit-test (Debug, this change over T2's mlvruznk) 1962/1966 (4 skipped: T2's lsp_client test and this change's Names test among the new; its perf check's BaselineHarnessMismatch, every base's); no dump change (`typed` was a field of the server's own, out of the digest: fs.zig's authority list) and no wire change (FsState is not on the tape), so no fuzz or soak; Stream.parseFor keeps its `!p.fs.serving` for a script's write, whose answer holds its rows (a script's `Symbols` word over a text past 64 KB still lists nothing: not this change's); no frame or perf gate (the user's rule of 2026-11-26); load 1.2 to 2.6 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Names.zig | 16 ++++++++++- core/Pick.zig | 8 +++--- core/fs.zig | 10 +++---- core/ninep/ctl.zig | 18 +++++++++---- docs/typ/reference.typ | 5 +++- test/behaviour/addons.zig | 11 +++++--- test/behaviour/other_files.zig | 4 ++- test/process/other_files.zig | 60 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 111 insertions(+), 21 deletions(-) (limited to 'test/behaviour/addons.zig') diff --git a/core/Names.zig b/core/Names.zig index d063bd17..01dbecf0 100644 --- a/core/Names.zig +++ b/core/Names.zig @@ -128,7 +128,9 @@ pub fn typed(n: *Names, gpa: std.mem.Allocator, text: []const u8) void { // only those are scored again (and then the ones not yet scored). const grew = n.query_len > 0 and std.mem.startsWith(u8, q, n.queryText()) and std.mem.indexOfScalar(u8, q[n.query_len..], ' ') == null; n.query_len = @intCast(q.len); - @memcpy(n.query_buf[0..q.len], q); + // Its own query typed again, to score names that came after it + // (Pick.declsArrived), is the buffer itself. + std.mem.copyForwards(u8, n.query_buf[0..q.len], q); n.reach = max_rows; if (grew) { const pending = n.pending.items[n.pending_at..]; @@ -435,3 +437,15 @@ test "Names keeps its best `reach` hits first in a full sort's order, the rest a n.reachTo(max_rows + 500); try std.testing.expectEqualSlices(Hit, all[0 .. max_rows + 500], n.hits.items[0 .. max_rows + 500]); } + +test "Names takes its own query typed again: names added after it (a Symbols picker's declarations from a worker, Pick.declsArrived) are scored against it" { + const gpa = std.testing.allocator; + var n: Names = .{}; + defer n.deinit(gpa); + n.typed(gpa, "zzlast"); + for ([_][]const u8{ "fn f0001() void {", "fn zzlastfn() void {" }) |cand| try n.add(gpa, cand, 0, cand.len, 0, 0); + n.typed(gpa, n.queryText()); + while (n.busy()) n.rescore(gpa); + try std.testing.expectEqualStrings("zzlast", n.queryText()); + try std.testing.expectEqual(@as(usize, 1), n.hits.items.len); +} diff --git a/core/Pick.zig b/core/Pick.zig index 9a9d0cde..5951f925 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -182,11 +182,11 @@ pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void { /// Whether a search a builtin asks for from pane `id` is a picker in the /// tag (SPEC §14.3 phase 4): in a session whose jumps walk, from the -/// keyboard or a click (kbdin's and mousein's too), never a script's word -/// (a 9P exec's: the query pane, whose rows it reads back, and whose `not -/// found` it hears). +/// keyboard or a click (kbdin's and mousein's too, which run as theirs: +/// ninep/ctl.zig writeKbdin), never a script's word (a 9P exec's: the query +/// pane, whose rows it reads back, and whose `not found` it hears). pub fn asked(p: *const Pardes) bool { - return p.settings.jumps == .walk and (!p.fs.serving or p.fs.typed); + return p.settings.jumps == .walk and !p.fs.serving; } /// Picker `id`, kept or live. diff --git a/core/fs.zig b/core/fs.zig index 594c89cf..c5eb432d 100644 --- a/core/fs.zig +++ b/core/fs.zig @@ -868,7 +868,7 @@ pub const Namespace = struct { .authority = .{ "socket_path", "tcp_address", "mounts", "node_name", "os_paths", "out", "listeners", "origin", "no_prompt", "session_write", "unlogged", "capturing", - "serving", "typed", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len", + "serving", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len", "said", "said_len", "said_at", "late_failure", "late_failure_len", "lsp_answer_at", "edit_started", "edit_hold", "edit_said", "lsp_result", "write_room", "write_waits", "log_full_hash", "pages", "closed_lines", "ran_at", "refilled", @@ -908,12 +908,10 @@ pub const Namespace = struct { /// which also refuses prompts, which a click may open). capturing: bool = false, /// A 9P request is being served (Pardes.serveFs): a prompt it opens is - /// a question for the log (`ask`), answered with `answer`. + /// a question for the log (`ask`), answered with `answer`. Not while + /// the keys or the mouse written to `kbdin` or `mousein` run: they are + /// the user's own (ninep/ctl.zig writeKbdin). serving: bool = false, - /// The request is keys or a mouse written to `kbdin` or `mousein`: - /// the user's own, so a builtin they reach routes as typed - /// (Pick.asked), though their write is served as any other. - typed: bool = false, refused: bool = false, failure: [256]u8 = undefined, failure_len: u16 = 0, diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index 2411b20f..17f58e7f 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -882,7 +882,10 @@ const e_no_pane = "no such pane"; /// rio's kbdin (windows/rio/xfid.c:515): each rune written is a key typed /// at the pane with the keyboard, the user's own, each done before the next -/// and all before the write is answered. Control runes are Ctrl and a +/// and all before the write is answered. They run as the keyboard's, not as +/// a script's write: what they start on a worker (a picker's listing or +/// search, a parse, a language server's answer) comes after the answer, as +/// a keyboard's comes a frame later. Control runes are Ctrl and a /// letter, but for Plan 9's keys (include/ALL/keyboard.h): \n or \r Enter, /// \t Tab, \b Backspace, 0x7f Delete, 0x1b Esc, and the arrows, Home, End, /// Page Up and Down, Insert and F1-F12 at its private-use runes. Its @@ -890,8 +893,11 @@ const e_no_pane = "no such pane"; /// or Ctrl to the key after them. pub fn writeKbdin(p: *Pardes, req: Req) Reply { const view = std.unicode.Utf8View.init(req.data) catch return tree.failText(req.tag, E.INVAL, "invalid UTF-8"); - p.fs.typed = true; - defer p.fs.typed = false; + // The keyboard's path, not a script's write's: nothing waits on the + // loop for a picker's source or an answer (Pick.asked, Stream.step). + const serving = p.fs.serving; + p.fs.serving = false; + defer p.fs.serving = serving; var it = view.iterator(); var mods: pardes.Key = .{ .cp = 0 }; while (it.nextCodepointSlice()) |rune| { @@ -946,8 +952,10 @@ fn kbdKey(rune: []const u8) pardes.Key { /// changed since the last line is pressed or released there, in that order /// of buttons; a move with one held drags, with none moves. pub fn writeMousein(p: *Pardes, req: Req) Reply { - p.fs.typed = true; - defer p.fs.typed = false; + // The mouse's path, as kbdin's keys take the keyboard's. + const serving = p.fs.serving; + p.fs.serving = false; + defer p.fs.serving = serving; var lines = std.mem.tokenizeScalar(u8, req.data, '\n'); while (lines.next()) |line| { var words = std.mem.tokenizeAny(u8, line, " \t\r"); diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index a08d3acc..449e6176 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -958,7 +958,10 @@ at 200, ending in `…`. Control characters become spaces. - #file("/kbdin") (write only), rio's: each rune written is a key typed at the pane with the keyboard, done before the write is answered, so a - script that writes keys then reads a file sees what they did. Control + script that writes keys then reads a file sees what they did. What they + start on a worker, as the keyboard's keys do, comes after the answer: a + picker's listing or search, a file's declarations, a language server's + answer; a script reads again until it is there. Control runes are Ctrl and a letter, but for Plan 9's keys (`keyboard.h`): `\n` or `\r` #key("Enter"), `\t` #key("Tab"), `\b` Backspace, `0x7f` Delete, `0x1b` #key("Esc"), and the diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index 90f4e383..0b0555c2 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -411,8 +411,10 @@ test "addons: a picker shows a file of an addon's kind through its kind in the p try s.expect(body, "the notes\n"); try std.testing.expectEqualStrings(index, try s.read("/index")); // Enter: the kind's pane where a Look puts it; the reading pane keeps - // its text. - try s.keys(" ffseven\n"); + // its text. (The listing is the next frame's, as for the keyboard.) + try s.keys(" ffseven"); + s.tick(); + try s.keys("\n"); s.tick(); const opened = try paneOf(&s, "fake"); try std.testing.expect(opened != pane); @@ -516,7 +518,10 @@ test "addons: Enter on a picture in a picker opens its kind's pane, never its by defer unload(&s, "image"); const dir = try dirOf(&s, &tmp); const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); - try s.keys(" ffpic\n"); + // The listing is the next frame's, as for the keyboard. + try s.keys(" ffpic"); + s.tick(); + try s.keys("\n"); s.tick(); try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n"); const image = try paneOf(&s, "image"); diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index 8a9016bc..95d4de6d 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -35,7 +35,9 @@ test "other-files: kbdin's keys are the user's: SPC f f opens Find's picker in t _ = try s.lookFile(s.at("{s}/a.txt", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]})); try s.keys(" ff"); try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Search") == null); - // Its rows under the tag of the pane typed at, the cursor on the first. + // Its rows under the tag of the pane typed at, the cursor on the first, + // the next frame, as the keyboard's: the listing is not the write's. + s.tick(); _ = try s.where("▶ a.txt"); _ = try s.where(" b.txt"); } diff --git a/test/process/other_files.zig b/test/process/other_files.zig index 69f65884..48ba06d0 100644 --- a/test/process/other_files.zig +++ b/test/process/other_files.zig @@ -8,6 +8,8 @@ pub const cases = .{ .{ "other-files: a held connection lists a directory, stats a file, writes and reads, is refused in words and removes a pane", heldConnection }, .{ "other-files: a file opened and closed is in /recent closed, and still is in the next session; Recent's row opens it again", recentSurvivesRestart }, .{ "other-files: two sessions share Recent: a file opened in one is in the other's /recent, a Del'd pane comes back from @p only where it was", recentShared }, + .{ "other-files: kbdin's SPC f f over a work tree of 20,000 files is answered before the listing, which a worker runs as the keyboard's, its rows after", findOnWorker }, + .{ "other-files: kbdin's SPC s s lists the declarations of a file over 64 KB, parsed on a worker as the keyboard's are", symbolsOnWorker }, }; extern "c" fn system(cmd: [*:0]const u8) c_int; @@ -185,3 +187,61 @@ fn recentShared(gpa: std.mem.Allocator, exe: [:0]const u8) !void { } try std.testing.expect(stateExists(root)); } + +/// A kbdin `SPC f f` over a work tree of 20,000 files: the keys handled and +/// the write answered, the listing run on a worker as the keyboard's is, +/// its rows on the screen after. (Before, the listing ran on the loop in the +/// write: over V8's 18,441 files a script's `SPC f g` held the session past +/// its client's timeout.) +fn findOnWorker(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var d = try process.Detached.start(gpa, exe, "kbdfind", .{}); + defer d.deinit(); + const f = &d.files; + const eh = @import("../e2e_harness.zig"); + var buf: [4096]u8 = undefined; + const tree = f.at("{s}/tree", .{d.root()}); + for ([_][]const u8{ "", "/.git" }) |sub| _ = std.c.mkdir(try std.fmt.bufPrintSentinel(&buf, "{s}{s}", .{ tree, sub }, 0), 0o755); + for (0..200) |dir| { + _ = std.c.mkdir(try std.fmt.bufPrintSentinel(&buf, "{s}/d{d:0>3}", .{ tree, dir }, 0), 0o755); + for (0..100) |i| try eh.writeFile(try std.fmt.bufPrintSentinel(&buf, "{s}/d{d:0>3}/f{d:0>3}.txt", .{ tree, dir, i }, 0), ""); + } + try eh.writeFile(try std.fmt.bufPrintSentinel(&buf, "{s}/zzlast.txt", .{tree}, 0), "last\n"); + try eh.writeFile(try std.fmt.bufPrintSentinel(&buf, "{s}/notes.txt", .{tree}, 0), "notes\n"); + try f.write("/look", f.at("{s}/notes.txt\n", .{tree})); + const t0 = process.nowMs(); + try f.keys(" ffzzlast"); + const answered = process.nowMs() - t0; + const listed = while (true) { + if (has(try f.screen(), "zzlast.txt")) break process.nowMs() - t0; + if (process.nowMs() - t0 > 30_000) return error.RowsNeverCame; + process.nap(5); + }; + try process.check(answered * 3 < listed, "kbdin's SPC f f answered after {d} ms, its row there after {d} ms: the listing ran in the write", .{ answered, listed }); + try f.keys("\x1b"); +} + +/// kbdin's `SPC s s` over a file of more than 64 KB: its declarations +/// parsed on a worker, as the keyboard's are, and listed. (Before, the +/// keys ran as a script's write, whose parse has no worker and leaves a +/// text this big unparsed: the picker listed nothing.) +fn symbolsOnWorker(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var d = try process.Detached.start(gpa, exe, "kbdsym", .{}); + defer d.deinit(); + const f = &d.files; + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + // Two lines each: a declaration on one line is none (syntax.contextSpan). + for (0..4000) |i| try text.print(gpa, "fn f{d:0>4}() void {{\n}}\n", .{i}); + try text.appendSlice(gpa, "fn zzlastfn() void {\n}\n"); + try process.check(text.items.len > 64 << 10, "{d} bytes", .{text.items.len}); + var buf: [4096]u8 = undefined; + try @import("../e2e_harness.zig").writeFile(try std.fmt.bufPrintSentinel(&buf, "{s}/big.zig", .{d.root()}, 0), text.items); + try f.write("/look", f.at("{s}/big.zig\n", .{d.root()})); + try f.keys(" sszzlast"); + const t0 = process.nowMs(); + while (!has(try f.screen(), "zzlastfn")) { + if (process.nowMs() - t0 > 20_000) return process.check(false, "kbdin's SPC s s over big.zig listed nothing", .{}); + process.nap(10); + } + try f.keys("\x1b"); +} -- cgit v1.3