summaryrefslogtreecommitdiff
path: root/dev/tui
diff options
context:
space:
mode:
Diffstat (limited to 'dev/tui')
-rw-r--r--dev/tui/tui.zig88
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);
}
}