diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-24 11:57:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-24 12:21:18 -0300 |
| commit | 8ac6db5662dd2db0f082e1651835f1db36e235f8 (patch) | |
| tree | ae8a8e928ca774b4347e4d19a8bf083c397e909b /src/host_io.zig | |
| parent | 51903dd947f90381d1a908c488a019289a1c8413 (diff) | |
| download | pardes-8ac6db5662dd2db0f082e1651835f1db36e235f8.tar.gz pardes-8ac6db5662dd2db0f082e1651835f1db36e235f8.zip | |
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
Diffstat (limited to 'src/host_io.zig')
| -rw-r--r-- | src/host_io.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/host_io.zig b/src/host_io.zig index b32fff55..f5d6f375 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -48,6 +48,9 @@ pub const Host = struct { open_link: ?*const fn (ctx: ?*anyopaque, url: []const u8) void = null, lsp: ?*const fn (ctx: ?*anyopaque, req: Lsp.Request) void = null, pipe: ?*const fn (ctx: ?*anyopaque, id: u32) void = null, + /// Start the streaming search of this generation on a worker + /// (pardes.Stream.start); absent, it runs on the loop. + search: ?*const fn (ctx: ?*anyopaque, gen: u32) void = null, }; }; @@ -129,6 +132,9 @@ pub const Inbox = struct { lsp: struct { id: u32, rows: ?[]u8 }, lsp_status: []u8, pipe: selection_pipe.Response, + /// A streaming search's rows (pardes.Stream), of whatever generation: + /// the core drops a stale one. + search: pardes.Stream.Batch, files_changed, fs_ready, @@ -141,6 +147,7 @@ pub const Inbox = struct { var response = response_value; response.deinit(gpa); }, + .search => |b| b.deinit(gpa), .eof, .files_changed, .fs_ready => {}, } } @@ -425,6 +432,34 @@ pub const Inbox = struct { q.push(.{ .pipe = response }); } + /// A streaming search's batch (pardes.Stream.start's sink). Never + /// dropped for want of room, as output is not: the worker waits for + /// room, a wait its cancel ends (false: it stops). + pub fn pushSearch(ctx: ?*anyopaque, batch: pardes.Stream.Batch) bool { + const q: *Inbox = @ptrCast(@alignCast(ctx.?)); + q.lock(); + while (!q.closed and q.len >= output_capacity) { + q.waiting += 1; + q.space.wait(q.io, &q.mutex) catch { + q.waiting -= 1; + q.unlock(); + batch.deinit(q.gpa); + return false; + }; + q.waiting -= 1; + } + if (q.closed) { + q.unlock(); + batch.deinit(q.gpa); + return false; + } + q.items[(q.head + q.len) % q.items.len] = .{ .search = batch }; + q.len += 1; + q.unlock(); + q.wake(); + return true; + } + /// A watched child exited (setExitWake): wake the loop, which takes it. pub fn wakeForExit(ctx: ?*anyopaque) void { const q: *Inbox = @ptrCast(@alignCast(ctx.?)); |
