From 8ac6db5662dd2db0f082e1651835f1db36e235f8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 11:57:35 -0300 Subject: Search converge 4/6: the disk engine, Grep and Find's listing on a worker (rg when there, else a sorted walk), generation-numbered batches, a debounce, a 2000-line cap and More, and the declarations parse off the loop --- src/tty/tty.zig | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/tty/tty.zig') diff --git a/src/tty/tty.zig b/src/tty/tty.zig index 8f5f102a..572a6f2a 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -94,6 +94,8 @@ pub const Command = struct { lsp_done: struct { id: u32, rows: ?[]u8 }, lsp_status: []u8, pipe_done: selection_pipe.Response, + /// A streaming search's rows (pardes.Stream). + search_rows: pardes.Stream.Batch, files_changed, fs_ready, } = .nop; @@ -1354,6 +1356,8 @@ fn localSession( sh.lsp_task = null; } sh.pipe_tasks.cancelAll(io); + // Its worker may be waiting on the loop's queue for room. + core.stream.cancelTask(); file_watch.stop(sh.inotify_fd); if (sh.watch_task) |*t| { t.cancel(io) catch {}; @@ -1372,6 +1376,7 @@ fn localSession( var response = response_value; response.deinit(gpa); }, + .search_rows => |b| b.deinit(gpa), else => {}, }; } @@ -1557,6 +1562,7 @@ const Shell = struct { .open_link = openLink, .lsp = lsp, .pipe = pipe, + .search = search, }; fn clockNow(ctx: ?*anyopaque) u64 { @@ -1719,6 +1725,10 @@ const Shell = struct { response.deinit(s.gpa); s.pipe_tasks.finish(s.io, response_value.id); }, + .search_rows => |b| { + core.update(.{ .search = b }); + b.deinit(s.gpa); + }, } return false; } @@ -2027,6 +2037,22 @@ const Shell = struct { selection_pipe.start(s.io, s.gpa, s.core, &s.pipe_tasks, id, s, deliverPipe); } + fn search(ctx: ?*anyopaque, gen: u32) void { + const s = of(ctx); + if (s.threads_ok) return pardes.Stream.start(s.io, s.gpa, s.core, gen, s, deliverSearch); + pardes.Stream.runHere(s.core, gen); + } + + /// The loop's queue waits for room (a wait the worker's cancel ends). + fn deliverSearch(ctx: ?*anyopaque, batch: pardes.Stream.Batch) bool { + const s = of(ctx); + s.loop.postEvent(.{ .search_rows = batch }) catch { + batch.deinit(s.gpa); + return false; + }; + return true; + } + fn deliverPipe(ctx: ?*anyopaque, response: selection_pipe.Response) void { const s = of(ctx); var owned = response; @@ -2876,7 +2902,7 @@ const Attach = struct { fn apply(a: *Attach, event: @TypeOf(Command.value)) ?AttachEnd { switch (event) { - .nop, .wake, .fs_ready, .lsp_done, .lsp_status, .pipe_done, .pty_read, .pty_eof, .files_changed => {}, + .nop, .wake, .fs_ready, .lsp_done, .lsp_status, .pipe_done, .search_rows, .pty_read, .pty_eof, .files_changed => {}, .quit => return .none, .focus_in => return a.send(.{ .focus = true }), .focus_out => { -- cgit v1.3