summaryrefslogtreecommitdiff
path: root/dev/Inbox.zig
diff options
context:
space:
mode:
Diffstat (limited to 'dev/Inbox.zig')
-rw-r--r--dev/Inbox.zig44
1 files changed, 38 insertions, 6 deletions
diff --git a/dev/Inbox.zig b/dev/Inbox.zig
index aac1f7a1..234d89eb 100644
--- a/dev/Inbox.zig
+++ b/dev/Inbox.zig
@@ -63,6 +63,11 @@ gpa: std.mem.Allocator,
lsp_allocator: std.mem.Allocator,
/// The query in flight; the UI thread's alone (spawnLsp, teardown).
lsp_task: ?Lsp.Task = null,
+/// The `|` pipes' and the addons' jobs' and draws' workers in flight, each
+/// posting its answer here (`pushPipe`, `pushJob`); the loop's thread's
+/// alone: joined as their answers land (`land`), canceled at the end.
+pipe_tasks: selection_pipe.Tasks = .{},
+job_tasks: selection_pipe.Tasks = .{},
/// Wakes the host's loop after a push from another thread: an SDL
/// event, a macOS runtime callback. Null: nobody to wake (tests).
wake_fn: ?*const fn (?*anyopaque) void = null,
@@ -262,9 +267,11 @@ pub fn close(q: *Inbox) void {
}
pub fn deinit(q: *Inbox) void {
- // The query in flight ends first: what it still delivers is dropped.
+ // The workers in flight end first: what they still deliver is dropped.
if (q.lsp_task) |*t| t.future.cancel(q.io);
q.lsp_task = null;
+ q.pipe_tasks.cancelAll(q.io);
+ q.job_tasks.cancelAll(q.io);
q.close();
std.debug.assert(q.waiting == 0);
}
@@ -311,9 +318,10 @@ pub fn startLsp(q: *Inbox, core: *pardes.Pardes, e: Lsp.Request) void {
Lsp.start(q.io, q.lsp_allocator, core, &q.lsp_task, e, q, pushLspRows);
}
-/// A language server's answer or status line taken off the queue, to the
-/// core (whichever frontend took it).
-pub fn landLsp(q: *Inbox, core: *pardes.Pardes, m: Msg) void {
+/// A worker's answer taken off the queue, to the core (whichever frontend
+/// took it), its worker joined: a language server's answer or status line,
+/// a pipe's, a search's rows, an addon's job or draw, a handover's end.
+pub fn land(q: *Inbox, core: *pardes.Pardes, m: Msg) void {
switch (m) {
.lsp => |l| {
core.update(.{ .lsp_resp = .{ .id = l.id, .rows = l.rows } });
@@ -324,7 +332,30 @@ pub fn landLsp(q: *Inbox, core: *pardes.Pardes, m: Msg) void {
core.setStatus(.at(core.view().active), pardes.Messages.Message.stamp(&mbuf, "lsp", text));
q.lsp_allocator.free(text);
},
- else => unreachable,
+ .pipe => |response_value| {
+ var response = response_value;
+ core.update(.{ .pipe_resp = .{
+ .id = response.id,
+ .success = response.success,
+ .outputs = response.outputs,
+ .failure = response.failure,
+ } });
+ response.deinit(q.gpa);
+ q.pipe_tasks.finish(q.io, response_value.id);
+ },
+ .search => |b| {
+ core.update(.{ .search = b });
+ b.deinit(q.gpa);
+ },
+ .kind_job => |j| {
+ q.job_tasks.finish(q.io, j.id);
+ j.land(core);
+ },
+ .handed => |h| {
+ core.update(.{ .handed = .{ .seq = h.seq, .to = if (h.ok) h.words else "", .failure = if (h.ok) null else h.words } });
+ q.gpa.free(h.words);
+ },
+ .output, .eof, .files_changed, .fs_ready, .adopted => unreachable,
}
}
@@ -340,12 +371,13 @@ pub fn lspStatus(ctx: ?*anyopaque, text: []const u8) void {
q.push(.{ .lsp_status = copy });
}
-/// A `|` job's answer (selection_pipe.start's sink).
+/// An addon's job or draw done (KindJob.go's sink).
pub fn pushJob(ctx: ?*anyopaque, j: *KindJob) void {
const q: *Inbox = @ptrCast(@alignCast(ctx.?));
q.push(.{ .kind_job = j });
}
+/// A `|` pipe's answer (selection_pipe.start's sink).
pub fn pushPipe(ctx: ?*anyopaque, response: selection_pipe.Response) void {
const q: *Inbox = @ptrCast(@alignCast(ctx.?));
q.push(.{ .pipe = response });