diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 02:35:56 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 03:20:29 -0300 |
| commit | 680cfe1fa5a15be3770d310153258ba9ded13dd8 (patch) | |
| tree | 65838b7b6c24f73016037640bc6c7d56aaa792ee /dev/tui | |
| parent | 3eb6c09bc97c2e60a17e1663108f4b22e3d1308c (diff) | |
| download | pardes-680cfe1fa5a15be3770d310153258ba9ded13dd8.tar.gz pardes-680cfe1fa5a15be3770d310153258ba9ded13dd8.zip | |
dev, runtime: the language servers' client once, through the session's one queue: both frontends start a query with Inbox.startLsp (its task and its id in the Inbox, an older answer turned away at the push and an older one still queued discarded) and land an answer or a status line with Inbox.landLsp; the session loop sets the language client's status sink on its queue from before the first effects and unsets it before the queue goes, a Restore turns the old core's answer away (discardCompletions, the window's way) and the queue's end cancels the query in flight; the terminal's own copy is deleted (its lsp_task, deliverLspRows posting lsp_done to vaxis's queue, a post that BLOCKED the language worker while that queue was full, lspStatusSink, the lsp_done and lsp_status messages and arms, the cancels in close and restoring) and with it its test of a stale answer at apply (the Inbox's rejection is pinned by gui.zig's worker-setup test); what a user sees: a window now shows an LSP status said during the session's first effects (its sink was set only after them), nothing else; the loop's frontend calls stay nine (close and restoring shrank); tui core-test 857/1007 (150 skipped), shell-test 1046/1049 (-1, the deleted test), term 17/17, pane 183/184, kitty 45/45, behaviour-test and --replay 275/275, process-test 0 of 144 failed (hscroll once in the run, passed on its retry), soaks --clients 5 and --bytes --clients 5 diverged 0, unequal 0, quiet checks 651/0 673/0 779/0 and 920/0 723/0 755/0, unlisted 0, corpus scene 22 of 22, no leak; gui unit-test 1643/1647 with only the perf check's BaselineHarnessMismatch; daemon.py plain, --far, --games, --window-clients, --upgrade both ways pass (load 11-16)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/tui')
| -rw-r--r-- | dev/tui/tui.zig | 88 |
1 files changed, 9 insertions, 79 deletions
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); } } |
