summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig84
1 files changed, 17 insertions, 67 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 9cd37b6b..a31c6548 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1135,8 +1135,8 @@ test "GUI completion survives a full output queue" {
const PtyTests = struct {
fn waitBlocked(queue: *Queue) !void {
- const until = shellClock() + 2_000;
- while (shellClock() < until) {
+ const until = std.Io.Clock.awake.now(std.testing.io).toMilliseconds() + 2_000;
+ while (std.Io.Clock.awake.now(std.testing.io).toMilliseconds() < until) {
queue.lock();
const waiting = queue.waiting;
queue.unlock();
@@ -1254,8 +1254,8 @@ test "GUI PTY reader delivers a real shell tail before EOF and joins on close" {
var bytes: std.ArrayList(u8) = .empty;
defer bytes.deinit(gpa);
var eof = false;
- const until = shellClock() + 2_000;
- while (!eof and shellClock() < until) {
+ const until = std.Io.Clock.awake.now(std.testing.io).toMilliseconds() + 2_000;
+ while (!eof and std.Io.Clock.awake.now(std.testing.io).toMilliseconds() < until) {
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
for (batch.slice()) |msg| switch (msg) {
@@ -1538,37 +1538,19 @@ fn watchThread(fd: c_int, stop: c_int, q: *Queue) void {
}
}
-fn lspThread(io: std.Io, lsp_allocator: std.mem.Allocator, job: *host_io.Lsp.Job, q: *Queue) anyerror!void {
- host_io.Lsp.work(io, lsp_allocator, job, q, pushLspRows);
-}
-
fn pushLspRows(ctx: ?*anyopaque, id: u32, rows: ?[]u8) void {
const q: *Queue = @ptrCast(@alignCast(ctx orelse return));
q.push(.{ .lsp = .{ .id = id, .rows = rows } });
}
fn spawnLsp(core: *pardes.Pardes, io: std.Io, q: *Queue, e: host_io.Lsp.Request) void {
- const lsp_allocator = q.lsp_allocator;
q.lock();
q.lsp_id = e.id;
q.discardLsp();
q.unlock();
- // Its waits are cancelation points: this join is short, and what it
- // still delivers carries an id the queue now rejects.
- if (q.lsp_task) |*old| {
- old.future.cancel(io) catch {};
- q.lsp_task = null;
- }
- const job = host_io.Lsp.snapshot(lsp_allocator, core, e) catch |err| {
- core.update(.{ .lsp_resp = .{ .id = e.id, .rows = null } });
- return core.reportError(e.pane, "lsp", err);
- };
- const future = io.concurrent(lspThread, .{ io, lsp_allocator, job, q }) catch |err| {
- job.free(lsp_allocator);
- core.update(.{ .lsp_resp = .{ .id = e.id, .rows = null } });
- return core.reportError(e.pane, "lsp", err);
- };
- q.lsp_task = .{ .id = e.id, .future = future };
+ // The old query's waits are cancelation points: its join is short, and
+ // what it still delivers carries an id the queue now rejects.
+ host_io.Lsp.start(io, q.lsp_allocator, core, &q.lsp_task, e, q, pushLspRows);
}
test "GUI LSP query answers, and a newer one cancels it" {
@@ -1584,7 +1566,7 @@ test "GUI LSP query answers, and a newer one cancels it" {
spawnLsp(core, io, &queue, .{ .id = core.lsp_wait.?.id, .kind = .status, .pane = @intCast(core.active), .offset = 0, .arg = "" });
}
const last = core.lsp_wait.?.id;
- try queue.lsp_task.?.future.await(io);
+ queue.lsp_task.?.future.await(io);
queue.lsp_task = null;
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
@@ -1595,37 +1577,11 @@ test "GUI LSP query answers, and a newer one cancels it" {
try std.testing.expect(core.lsp_wait == null);
}
-fn pipeThread(io: std.Io, gpa: std.mem.Allocator, job: *selection_pipe.Job, q: *Queue) anyerror!void {
- defer job.deinit(gpa);
- const response = selection_pipe.runJob(gpa, io, job);
+fn pushPipe(ctx: ?*anyopaque, response: selection_pipe.Response) void {
+ const q: *Queue = @ptrCast(@alignCast(ctx.?));
q.push(.{ .pipe = response });
}
-fn spawnPipe(
- core: *pardes.Pardes,
- io: std.Io,
- gpa: std.mem.Allocator,
- q: *Queue,
- tasks: *PipeTasks,
- id: u32,
-) void {
- if (tasks.len == tasks.items.len) {
- core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return;
- }
- const view = core.pipe.pipeRequest(id) orelse return;
- const job = selection_pipe.Job.copy(gpa, view) catch |err| {
- core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return core.reportError(core.active, "pipe", err);
- };
- const future = io.concurrent(pipeThread, .{ io, gpa, job, q }) catch |err| {
- job.deinit(gpa);
- core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return core.reportError(core.active, "pipe", err);
- };
- std.debug.assert(tasks.add(.{ .id = id, .future = future }));
-}
-
test "GUI worker setup failures finish matching LSP and pipe requests" {
const gpa = std.testing.allocator;
var failing_vtable = std.testing.io.vtable.*;
@@ -1677,7 +1633,7 @@ test "GUI worker setup failures finish matching LSP and pipe requests" {
core.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } });
core.update(.{ .key = .{ .cp = pardes.Key.enter } });
const pipe_id = core.pipe.wait.?.id;
- spawnPipe(core, failing_io, failing.allocator(), &queue, &tasks, pipe_id);
+ selection_pipe.start(failing_io, failing.allocator(), core, &tasks, pipe_id, &queue, pushPipe);
try std.testing.expect(core.pipe.wait == null);
try std.testing.expectEqualStrings("abc", pane.file.?.content);
try std.testing.expect(queue.lsp_task == null);
@@ -2543,7 +2499,7 @@ fn localSession(
.sdl_wake = true,
};
defer {
- if (queue.lsp_task) |*task| task.future.cancel(io) catch {};
+ if (queue.lsp_task) |*task| task.future.cancel(io);
queue.deinit();
}
var pipe_tasks: PipeTasks = .{};
@@ -2914,7 +2870,7 @@ fn runGrid(init: std.process.Init, opts_in: pardes.Options) !void {
.sdl_wake = false,
};
defer {
- if (queue.lsp_task) |*task| task.future.cancel(io) catch {};
+ if (queue.lsp_task) |*task| task.future.cancel(io);
queue.deinit();
}
var pipe_tasks: PipeTasks = .{};
@@ -3377,7 +3333,7 @@ const Input = struct {
const client = in.client orelse return;
if (in.lost != null) return;
client.send(.{ .event = ev }) catch |err| switch (err) {
- error.Overlong, error.NoSpace => {},
+ error.Overlong, error.WriteFailed => {},
else => in.lost = err,
};
}
@@ -4051,7 +4007,7 @@ const Shell = struct {
test_hz: u64 = 60,
fn reap(s: *Shell) void {
- const now = shellClock();
+ const now = std.Io.Clock.awake.now(s.queue.io).toMilliseconds();
for (&s.retired_shells) |*child| host_io.reapRetired(&child.pid, &child.kill_at, now);
for (s.ptys) |*slot| if (slot.*) |*pt| if (pt.fd < 0) {
host_io.reapRetired(&pt.pid, &pt.kill_at, now);
@@ -4075,7 +4031,7 @@ const Shell = struct {
}
_ = libc.close(pt.fd);
pt.fd = -1;
- const now = shellClock();
+ const now = std.Io.Clock.awake.now(s.queue.io).toMilliseconds();
host_io.reapRetired(&pt.pid, &pt.kill_at, now);
if (pt.pid == 0) {
s.ptys[pane] = null;
@@ -4809,7 +4765,7 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void {
fn pipe(ctx: ?*anyopaque, id: u32) void {
const s = shellOf(ctx);
- if (s.threads_ok) return spawnPipe(s.core, s.io, s.gpa, s.queue, s.pipe_tasks, id);
+ if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, s.pipe_tasks, id, s.queue, pushPipe);
s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
s.core.reportError(s.core.active, "pipe", error.WorkersUnavailable);
}
@@ -4822,12 +4778,6 @@ fn pollCwds(core: *pardes.Pardes, ptys: *[pardes.MAX_PANES]?Pty) void {
};
}
-fn shellClock() i64 {
- var ts: libc.timespec = undefined;
- if (libc.clock_gettime(.MONOTONIC, &ts) != 0) return 0;
- return @as(i64, ts.sec) * std.time.ms_per_s + @divTrunc(ts.nsec, std.time.ns_per_ms);
-}
-
fn accumulateWheelDelta(pending: f32, raw_y: f32) f32 {
if (!std.math.isFinite(raw_y)) return pending;
const next = pending - raw_y;