diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Inbox.zig | 20 | ||||
| -rw-r--r-- | dev/gui/gui.zig | 14 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 88 |
3 files changed, 30 insertions, 92 deletions
diff --git a/dev/Inbox.zig b/dev/Inbox.zig index ed3a9835..1dd30adf 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -264,6 +264,9 @@ pub fn close(q: *Inbox) void { } pub fn deinit(q: *Inbox) void { + // The query in flight ends first: what it still delivers is dropped. + if (q.lsp_task) |*t| t.future.cancel(q.io); + q.lsp_task = null; q.close(); std.debug.assert(q.waiting == 0); } @@ -310,6 +313,23 @@ 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 { + switch (m) { + .lsp => |l| { + core.update(.{ .lsp_resp = .{ .id = l.id, .rows = l.rows } }); + if (l.rows) |rows| q.lsp_allocator.free(rows); + }, + .lsp_status => |text| { + var mbuf: [256]u8 = undefined; + core.setStatus(.at(core.view().active), pardes.Messages.Message.stamp(&mbuf, "lsp", text)); + q.lsp_allocator.free(text); + }, + else => unreachable, + } +} + fn pushLspRows(ctx: ?*anyopaque, id: u32, rows: ?[]u8) void { const q: *Inbox = @ptrCast(@alignCast(ctx orelse return)); q.push(.{ .lsp = .{ .id = id, .rows = rows } }); diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 59e0516a..df3d2f2b 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -1047,11 +1047,9 @@ const Own = struct { const io = l.io; o.shell.fs = null; host_io.setExitWake(null, null); - pardes.lsp.setStatusSink(null, null); pardes.Kind.drawer = null; o.shell.job_tasks.cancelAll(io); o.pipe_tasks.cancelAll(io); - if (l.inbox.lsp_task) |*task| task.future.cancel(io); // Its worker may be waiting on the queue for room. l.core.stream.cancelTask(); o.g.hit_core = null; @@ -1066,7 +1064,6 @@ const Own = struct { if (o.test_mode) setStdinRaw() catch {}; o.shell.threads_ok = true; - pardes.lsp.setStatusSink(&l.inbox, Queue.lspStatus); host_io.setExitWake(&l.inbox, Queue.wakeForExit); if (o.detached) { o.shell.closeTheWindow(); @@ -1087,7 +1084,6 @@ const Own = struct { pub fn restoring(o: *Own, nc: *pardes.Pardes) void { o.pipe_tasks.cancelAll(o.shell.io); - o.shell.queue.discardCompletions(); // One view, the window's (host_io.restoreCore). o.shell.gview = 0; o.g.cells.clearImages(); @@ -2601,15 +2597,7 @@ const Shell = struct { for (msgs.slice()) |m| switch (m) { .output => |o| s.ptys.output(s.core, o), .eof => |e| s.ptys.eof(s.core, e), - .lsp => |l| { - s.core.update(.{ .lsp_resp = .{ .id = l.id, .rows = l.rows } }); - if (l.rows) |rows| s.lsp_allocator.free(rows); - }, - .lsp_status => |text| { - var mbuf: [256]u8 = undefined; - s.core.setStatus(.at(s.core.view().active), message.stamp(&mbuf, "lsp", text)); - s.lsp_allocator.free(text); - }, + .lsp, .lsp_status => s.queue.landLsp(s.core, m), .pipe => |response_value| { var response = response_value; s.core.update(.{ .pipe_resp = .{ diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index b20c15a0..1c59a8be 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -123,8 +123,6 @@ const Msg = union(enum) { paste: []const u8, paste_start, paste_end, - 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, @@ -969,7 +967,6 @@ const Own = struct { l.inbox.wake_ctx = sh; l.peers.wake_ctx = o.loop; l.peers.wake = wakeForReplica; - pardes.lsp.setStatusSink(sh, lspStatusSink); host_io.setExitWake(o.loop, wakeForExit); const host = sh.host(); l.core.host = host; @@ -991,19 +988,12 @@ const Own = struct { stopInput(io, &o.screen.thread); pardes.Kind.drawer = null; host_io.setExitWake(null, null); - pardes.lsp.setStatusSink(null, null); - if (sh.lsp_task) |*t| { - t.future.cancel(io); - sh.lsp_task = null; - } sh.pipe_tasks.cancelAll(io); sh.job_tasks.cancelAll(io); // Its worker may be waiting on the loop's queue for room. sh.core.stream.cancelTask(); while (loop.tryEvent() catch null) |ev| switch (ev) { .paste => |b| gpa.free(@constCast(b)), - .lsp_done => |d| if (d.rows) |rows| sh.lsp_gpa.free(rows), - .lsp_status => |text| sh.lsp_gpa.free(text), .pipe_done => |response_value| { var response = response_value; response.deinit(gpa); @@ -1057,10 +1047,6 @@ const Own = struct { pub fn restoring(o: *Own, nc: *pardes.Pardes) void { const sh = &o.sh; const io = sh.io; - if (sh.lsp_task) |*task| { - task.future.cancel(io); - sh.lsp_task = null; - } sh.pipe_tasks.cancelAll(io); // One view, the terminal's (host_io.restoreCore). const live = o.screen; @@ -1149,7 +1135,6 @@ const Shell = struct { batch: host_io.Inbox.Batch = .{}, batch_at: usize = 0, queue_woken: std.atomic.Value(bool) = .init(false), - lsp_task: ?host_io.Lsp.Task = null, pipe_tasks: PipeTasks = .{}, job_tasks: PipeTasks = .{}, threads_ok: bool = false, @@ -1710,19 +1695,6 @@ const Shell = struct { s.paste_buf.clearRetainingCapacity(); }, .fs_ready => {}, - .lsp_done => |d| { - core.update(.{ .lsp_resp = .{ .id = d.id, .rows = d.rows } }); - if (d.rows) |rows| s.lsp_gpa.free(rows); - if (s.lsp_task) |*t| if (t.id == d.id) { - t.future.await(s.io); - s.lsp_task = null; - }; - }, - .lsp_status => |text| { - var mbuf: [256]u8 = undefined; - core.setStatus(.at(core.view().active), message.stamp(&mbuf, "lsp", text)); - s.lsp_gpa.free(text); - }, .pipe_done => |response_value| { var response = response_value; core.update(.{ .pipe_resp = .{ @@ -1980,6 +1952,7 @@ const Shell = struct { }, .eof => |e| s.ptys.eof(s.core, e), .files_changed => s.check_files = true, + .lsp, .lsp_status => s.ptys.queue.landLsp(s.core, m), else => m.deinit(s.gpa, s.lsp_gpa), } } @@ -2024,16 +1997,9 @@ const Shell = struct { fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { const s = of(ctx); - if (!s.threads_ok) { - s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); - } - host_io.Lsp.start(s.io, s.lsp_gpa, s.core, &s.lsp_task, req, s, deliverLspRows); - } - - fn deliverLspRows(ctx: ?*anyopaque, id: u32, rows: ?[]u8) void { - const s = of(ctx); - s.loop.postEvent(.{ .lsp_done = .{ .id = id, .rows = rows } }) catch if (rows) |owned| s.lsp_gpa.free(owned); + if (s.threads_ok) return s.ptys.queue.startLsp(s.core, req); + s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); + s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } fn pipe(ctx: ?*anyopaque, id: u32) void { @@ -2089,13 +2055,6 @@ const Shell = struct { } }; -fn lspStatusSink(ctx: ?*anyopaque, text: []const u8) void { - const s: *Shell = @ptrCast(@alignCast(ctx orelse return)); - const copy = s.lsp_gpa.dupe(u8, text) catch return; - const posted = s.loop.tryPostEvent(.{ .lsp_status = copy }) catch false; - if (!posted) s.lsp_gpa.free(copy); -} - fn keepSignal(_: posix.SIG) callconv(.c) void {} /// A replica client's (`runClient`): a hangup is its end, whoever sent it. @@ -2773,38 +2732,6 @@ test "on a terminal with no kitty graphics a program's 64x64 image over 8x4 cell try std.testing.expectEqual(@as(usize, 32), painted); } -test "TTY queued results reject an old LSP request ID" { - const gpa = std.testing.allocator; - const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); - defer core.deinit(); - var no_peers: replica.Peers = .{}; - var shell: Shell = .{ - .io = std.testing.io, - .gpa = gpa, - .lsp_gpa = gpa, - .core = core, - .frames = core.frames, - .loop = undefined, - .frame = undefined, - .paste_buf = undefined, - .watches = undefined, - .peers = &no_peers, - .ptys = undefined, - }; - core.lspRequest(0, .status, ""); - const old_id = core.lsp_ask.wait.?.id; - core.lspRequest(0, .status, ""); - const current_id = core.lsp_ask.wait.?.id; - shell.lsp_task = .{ .id = current_id, .future = .{ .any_future = null, .result = {} } }; - _ = shell.apply(.{ .lsp_done = .{ .id = old_id, .rows = try gpa.dupe(u8, "stale result\n") } }); - try std.testing.expect(shell.lsp_task != null); - try std.testing.expectEqual(current_id, shell.lsp_task.?.id); - try std.testing.expectEqual(current_id, core.lsp_ask.wait.?.id); - _ = shell.apply(.{ .lsp_done = .{ .id = current_id, .rows = try gpa.dupe(u8, "") } }); - try std.testing.expect(shell.lsp_task == null); - try std.testing.expect(core.lsp_ask.wait == null); -} - test "TTY worker setup failures finish matching LSP and pipe requests" { const gpa = std.testing.allocator; var failing_vtable = std.testing.io.vtable.*; @@ -2818,6 +2745,9 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { .fail_index = if (failure == 0) 0 else std.math.maxInt(usize), }); var no_peers: replica.Peers = .{}; + var queue: host_io.Inbox = .{ .io = failing_io, .gpa = gpa, .lsp_allocator = failing.allocator() }; + defer queue.deinit(); + var ptys: host_io.Ptys = .{ .queue = &queue, .prompt_rcs = undefined }; var shell: Shell = .{ .io = failing_io, .gpa = failing.allocator(), @@ -2830,7 +2760,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { .watches = undefined, .threads_ok = true, .peers = &no_peers, - .ptys = undefined, + .ptys = &ptys, }; core.lspRequest(core.view().active, .status, ""); const req: host_io.Lsp.Request = .{ @@ -2853,7 +2783,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { Shell.pipe(&shell, pipe_id); try std.testing.expect(core.pipe.wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); - try std.testing.expect(shell.lsp_task == null); + try std.testing.expect(queue.lsp_task == null); try std.testing.expectEqual(@as(usize, 0), shell.pipe_tasks.len); } } |
