summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 04:54:39 -0300
committerGabriel Schneider <[email protected]>2026-11-26 06:12:14 -0300
commit02b64ff90ae2f82fb83a604f6d4ded3459a84620 (patch)
tree066e398aac05727d7b64d3413fdbe92f6c204fcc /dev
parent5dab435d7262b87d2cf40d6a27cea9c2d981c2e8 (diff)
downloadpardes-02b64ff90ae2f82fb83a604f6d4ded3459a84620.tar.gz
pardes-02b64ff90ae2f82fb83a604f6d4ded3459a84620.zip
Lsp, lsp_client, File, dump: a file of a language a server speaks, opened in a pane (a Look, a landing, a walk step, the boot's file, a restored session's), starts that server and tells it of the file on a worker of its own, so the file's first question finds it ready (agent V4's find for the comparison video, VIDEO2/STORY.md §4.1 and §10.2: pardes's first `gd` cost about 2.5 s where Helix's, LazyVim's and Doom's cost 0.05 s; the user was asked, the default yes); THE CAUSE: dev/lsp/lsp_client.zig spawned a server on the first query that needed it (its header's lifecycle), and that query paid the spawn, the handshake and the server's first parse of the file; THE FIX: an effect `lsp_open`, emitted beside the file's watch by File.open (look.open, Trail's step, the boot document) and dump.revivePane (a restored or upgraded session), performed through a Host entry `lsp_open` (tui, gui and macOS: Inbox.openLsp; not held for `threads_ok`: the boot's file and a restored session's are opened before the loop's threads start); dev/Lsp.zig `open` asks nothing for a file no spec speaks for (lsp.speaks, on the loop), else copies the pane's file (`snapshot`) and hands it to a worker of its own (`Opener`, one at a time: a file opened while one is under way is let go and told at its first query, syncDoc; one done is awaited, at once, before the next), which calls lsp_client.open: a spec disabled asks nothing, a binary not found disables the spec without a word (its first query says `language server for .py not found`, not every file opened), else `ensure` (the server started as a query starts it, `starting` and `ready` narrated as before, one per spec) and `syncDoc` (didOpen); nothing in the query log; not through Lsp.start (its cancel and join of the query in flight waits out a protected handshake, up to init_ms = 8 s, on the loop) nor `work` (the queries' one fixed region, memory.takeLspQuery); a picker's preview (Pick.preview, no pane) and a 9P `ctl get` (ninep/ctl.zig getFile, no File.open) start none; Lspinfo says `not started yet (a file of its opened starts it)`; docs/typ/setup.typ and reference.typ say when a server starts; THE HARNESSES (the coordinator's ruling: no test starts a server of this machine's): PARDES_LSP_OPEN=off starts none and is the process harnesses' default (test/process.zig's child environment, test/tty.zig, and test/fs.py, selfmount.py and daemon.py's base_env), so the `lsp` tty cases' zls is started by their first query as before; a test binary (builtin.is_test) starts none unless it says `on`, as the behaviour harness's language sessions do (Session.initLanguage, every spec the mock or off, `.lsp_open` drained as a host performs it, awaited); RUN (TEST FIRST): behaviour/language_servers.zig "a file of a server's language opened in a pane starts that server and tells it of the file, with no query asked; a picker's preview of one starts none, a second file no second server, and a server not installed is found silently" previews a.zig in Find's picker (Lspinfo: zls `not started yet`), opens it (zls `ready`, `docs 1`, the query count unchanged), opens b.zig (`docs 2`: the same server), and opens c.py and d.py with PARDES_LSP_PY naming no binary (pyright `disabled`, no query, nothing on the screen): fails on the base at language_servers.zig:367 (zls not started by the open), passes now; lsp_client.zig "a file opened whose server is not installed disables it without a word ..." opens two .py files with a status sink set: the spec disabled, no word posted, a query then `not found`; MEASURED (.scratch/walkui/T23/measure-v8.sh: VIDEO's probe.py, the screen polled every 50 ms, this change's Debug tui, a reflink copy of VIDEO2's V8 tree with clangd and its 27-file compile database, torque-parser.cc opened, `743ggfI` then `gd` 4 s after the start, until utils.h's `bool IsUpperCamelCase` shows): with PARDES_LSP_OPEN=off (the base's way) 1.97, 1.98, 1.97 s; started at the open 0.05, 0.05, 0.05 s; on VIDEO's tally with zls (measure.sh) both ways 0.05-0.10 s (zls starts and answers within one poll there); a user hit it on the first question of every file of a session's languages, about 2 s with clangd over a real project; NEW HOT PATHS: none per key or frame; per file opened, one effect more and on the loop lsp.speaks (the spec table's extensions); for a file a spec speaks for, a copy of its text (the snapshot a query makes) and a worker started; GATES: core-test 1130/1304 (174 skipped: +1), shell-test 1352/1355 (3 skipped: +1), pane-test 183/184, behaviour-test 286/286 (+1) and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 147 failed (3 skipped), term-test 17/17, kitty-test 45/45; the wire's semantics move (a Host entry, tape.shape); no dump change (effects are local, not dumped); the soak `replicas -- --clients 5 --rtt 30,80,207` dies on the base too (5dab435d7262, run here: `allocator leaks detected` at seed 0 rtt 80, MuPDF's allocations of documents a picker previewed, Pick.showKind), so run without the pdf addon (its binary, `--addon` image and life): diverged 0, unequal 0, quiet checks 468/0 251/0 657/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak (a first run had one key stop at `spawn` at seed 3 rtt 80, exec.zig's rerun of a command pane, which emits a spawn with no `open a terminal` stop; the base's run and a second run had none); the gui unit-test run once, on T3's change over this one (its description); no frame or perf gate (the user's rule of 2026-11-26); load 1.1 to 9.1
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'dev')
-rw-r--r--dev/Host.zig3
-rw-r--r--dev/Inbox.zig11
-rw-r--r--dev/Lsp.zig40
-rw-r--r--dev/gui/gui.zig8
-rw-r--r--dev/lsp/lsp_client.zig88
-rw-r--r--dev/tui/tui.zig8
6 files changed, 151 insertions, 7 deletions
diff --git a/dev/Host.zig b/dev/Host.zig
index 52205518..0a175754 100644
--- a/dev/Host.zig
+++ b/dev/Host.zig
@@ -54,6 +54,9 @@ pub const VTable = struct {
/// startDetached. Null once it runs, else why not.
start: ?*const fn (ctx: ?*anyopaque, line: []const u8, why: []u8) ?[]const u8 = null,
lsp: ?*const fn (ctx: ?*anyopaque, req: Lsp.Request) void = null,
+ /// Start the language server of the file `pane` opened, and tell it of
+ /// the file, on a worker (Lsp.open).
+ lsp_open: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
pipe: ?*const fn (ctx: ?*anyopaque, id: u32) void = null,
/// Start the streaming search of this generation on a worker
/// (pardes.Stream.start); absent, it runs on the loop.
diff --git a/dev/Inbox.zig b/dev/Inbox.zig
index bc7c7e8a..a0b9494d 100644
--- a/dev/Inbox.zig
+++ b/dev/Inbox.zig
@@ -67,6 +67,9 @@ 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 server start a file's opening asked for (openLsp); the UI
+/// thread's alone.
+lsp_opener: Lsp.Opener = .{},
/// 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.
@@ -290,6 +293,8 @@ pub fn deinit(q: *Inbox) void {
// 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;
+ if (q.lsp_opener.future) |*f| f.cancel(q.io);
+ q.lsp_opener.future = null;
q.pipe_tasks.cancelAll(q.io);
q.job_tasks.cancelAll(q.io);
q.close();
@@ -343,6 +348,12 @@ 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);
}
+/// The language server of the file `pane` opened started, on a worker of
+/// its own (Lsp.open).
+pub fn openLsp(q: *Inbox, core: *const pardes.Pardes, pane: pardes.Pane.Id) void {
+ Lsp.open(q.io, q.lsp_allocator, core, &q.lsp_opener, pane);
+}
+
/// 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.
diff --git a/dev/Lsp.zig b/dev/Lsp.zig
index b799c9f6..d7638c83 100644
--- a/dev/Lsp.zig
+++ b/dev/Lsp.zig
@@ -138,6 +138,46 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, task: *?T
task.* = .{ .id = req.id, .future = future };
}
+/// The server start a file's opening asks for (`open`), one at a time:
+/// `busy` while its worker runs.
+pub const Opener = struct {
+ future: ?std.Io.Future(void) = null,
+ busy: std.atomic.Value(bool) = .init(false),
+};
+
+/// Pane `pane`'s file just opened: the server of its language started and
+/// told of it (lsp_client.open) on a worker of its own, so its first query
+/// finds both done (that query paid a spawn and a handshake, 2.5 s of zls's
+/// over the comparison video's project). Not through `start`, whose cancel
+/// of the query in flight waits out a handshake on the loop, nor `work`,
+/// whose fixed region is the queries'. One at a time: a file opened while
+/// one is under way is let go, and told at its first query (syncDoc); one
+/// done is awaited (at once) before the next.
+pub fn open(io: std.Io, gpa: std.mem.Allocator, core: *const pardes.Pardes, opener: *Opener, pane: pardes.Pane.Id) void {
+ if (opener.busy.load(.acquire)) return;
+ if (opener.future) |*f| f.await(io);
+ opener.future = null;
+ const p = core.panes[pane.index()] orelse return;
+ const f = p.file orelse return;
+ if (!pardes.lsp.speaks(f.path)) return;
+ const job = snapshot(gpa, core, .{ .id = 0, .kind = .definition, .pane = pane, .offset = 0, .arg = "" }) catch return;
+ opener.busy.store(true, .release);
+ opener.future = io.concurrent(tell, .{ io, gpa, job, &opener.busy }) catch {
+ opener.busy.store(false, .release);
+ return job.free(gpa);
+ };
+}
+
+fn tell(io: std.Io, gpa: std.mem.Allocator, job: *Job, busy: *std.atomic.Value(bool)) void {
+ defer busy.store(false, .release);
+ defer job.free(gpa);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ // A server that failed to start says so itself (`ensure`); one not
+ // started for want of memory is started by the file's first query.
+ pardes.lsp.open(io, arena.allocator(), .{ .kind = job.kind, .path = job.path, .source = job.source, .offset = 0, .root = job.root }) catch {};
+}
+
pub fn work(io: std.Io, gpa: std.mem.Allocator, job: *Job, ctx: ?*anyopaque, deliver: Deliver) void {
defer job.free(gpa);
// The query's memory is the fixed region memory.zig reserved at
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index a478db03..7a87c110 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -2648,6 +2648,7 @@ const Shell = struct {
.open_link = openLink,
.start = host_io.startDetached,
.lsp = lsp,
+ .lsp_open = lspOpen,
.pipe = pipe,
.search = search,
.hand_over = handOver,
@@ -3223,6 +3224,13 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void {
s.core.reportError(req.pane, "lsp", error.WorkersUnavailable);
}
+/// Not held for `threads_ok`: the boot's file and a restored session's are
+/// opened before `start`.
+fn lspOpen(ctx: ?*anyopaque, pane: pardes.Pane.Id) void {
+ const s = shellOf(ctx);
+ s.queue.openLsp(s.core, pane);
+}
+
fn pipe(ctx: ?*anyopaque, id: u32) void {
const s = shellOf(ctx);
if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, &s.queue.pipe_tasks, id, s.queue, Queue.pushPipe);
diff --git a/dev/lsp/lsp_client.zig b/dev/lsp/lsp_client.zig
index a53ff57f..be5069ae 100644
--- a/dev/lsp/lsp_client.zig
+++ b/dev/lsp/lsp_client.zig
@@ -6,9 +6,10 @@
//!
//! THE PROCESS LIFECYCLE IS THE DESIGN. `lsp.query` is a synchronous call on a
//! worker thread, and a language server costs tens of milliseconds to start
-//! and MINUTES to index a large workspace. So a server is spawned lazily on
-//! the first query that needs it, kept for the life of the editor, and each
-//! spec gets at most one — `conns[i]` guards itself with an `Io.Mutex`
+//! and MINUTES to index a large workspace. So a server is spawned when a
+//! file of its language opens in a pane (`open`, on a worker of its own) or
+//! by the first query that needs it, kept for the life of the editor, and
+//! each spec gets at most one — `conns[i]` guards itself with an `Io.Mutex`
//! because a canceled query can still be inside `run` when the next arrives.
//! Every wait is an `Io` cancelation point: a shell cancels the worker of a
//! query it no longer wants, and the worker stops there.
@@ -40,7 +41,8 @@
//! (ignoring SIGPIPE process-wide would be inherited by every pty shell we
//! fork and would change what `yes | head` does in a pane),
//! - a binary missing from PATH costs one cached probe, disables the spec
-//! for the session, and says so ONCE on the message row.
+//! for the session, and says so ONCE on the message row (a query's; a
+//! file opened says nothing).
//!
//! Position encoding is negotiated to utf-8 and the SERVER'S ANSWER is
//! believed, not our request; the utf-16 conversion is implemented in both
@@ -478,8 +480,8 @@ fn status(io: std.Io, path: []const u8, out: *std.Io.Writer) !void {
const thier = c.caps.type_hier;
c.mu.unlock(io);
const env_v = if (libc.getenv(s.env)) |v| std.mem.span(v) else null;
- // Never spawned is not off: the first query of its files starts it.
- try out.print(" {s:<28} {s}", .{ s.name, if (state == .off) "not started yet (its first query starts it)" else @tagName(state) });
+ // Never spawned is not off: a file of its opened starts it.
+ try out.print(" {s:<28} {s}", .{ s.name, if (state == .off) "not started yet (a file of its opened starts it)" else @tagName(state) });
if (state == .ready or state == .starting) {
try out.print(" root {s} {s}", .{ root, @tagName(enc) });
if (pull) try out.print(" pull-diags", .{});
@@ -757,6 +759,36 @@ pub fn query(io: std.Io, arena: std.mem.Allocator, asked: lsp.Req, out: *std.Io.
try out.writeAll(scratch.buffered());
}
+/// A file opened in a pane (dev/Lsp.zig open): the server of its language
+/// started as its first query would start it (`ensure`, which says
+/// `starting` and `ready` on the message row) and told of the file
+/// (didOpen), so that query finds both done. A server not installed is
+/// disabled without a word: the file's first query says it is not found,
+/// not every file opened. Nothing in the query log: none was asked.
+/// PARDES_LSP_OPEN=off starts none (the process harnesses' default), and a
+/// test binary starts none unless it says `on` (the behaviour harness's
+/// language sessions, their servers the mock): no test starts a server of
+/// this machine's by opening a file.
+pub fn open(io: std.Io, arena: std.mem.Allocator, req: lsp.Req) Err!void {
+ const said = if (libc.getenv("PARDES_LSP_OPEN")) |v| std.mem.span(v) else "";
+ if (std.mem.eql(u8, said, "off") or (builtin.is_test and !std.mem.eql(u8, said, "on"))) return;
+ const si = specFor(req.path) orelse return;
+ const c = &conns[si];
+ try c.mu.lock(io);
+ defer c.mu.unlock(io);
+ if (c.state == .disabled) return;
+ var exe_buf: [4096:0]u8 = undefined;
+ if (!c.alive() and binOf(&specs[si], &exe_buf) == null) {
+ c.state = .disabled;
+ return;
+ }
+ var tr: Trace = .{};
+ _ = try ensure(c, io, si, arena, req, &tr);
+ var uri: std.ArrayList(u8) = .empty;
+ try uriOf(&uri, arena, req.path);
+ try syncDoc(c, io, si, arena, uri.items, req.source);
+}
+
fn traceOut(tr: *const Trace, req: lsp.Req, out: *std.Io.Writer, rows: usize, us: u64) std.Io.Writer.Error!void {
if (req.kind != .explain) return;
try out.print("lsp explain — the {s} query at byte {d} of {s}\n\n", .{
@@ -3162,11 +3194,53 @@ test "a language with no server to start says so, not that it did not answer" {
try std.testing.expectEqualStrings("@none language server for .py not found\n", out.buffered());
}
+test "a file opened whose server is not installed disables it without a word, at every file's open; a query of it then says it is not found" {
+ const host_io = @import("../host_io.zig");
+ const io = std.testing.io;
+ const si = specFor("/x/a.py") orelse return;
+ const c = &conns[si];
+ const was_state = c.state;
+ defer c.state = was_state;
+ // A test binary's files start servers only where it says so.
+ const names = [_][*:0]const u8{ "PARDES_LSP_PY", "PARDES_LSP_OPEN" };
+ var was_buf: [names.len][4096:0]u8 = undefined;
+ var was: [names.len]?[:0]const u8 = undefined;
+ for (names, &was, &was_buf) |name, *w, *b| w.* = if (libc.getenv(name)) |v| try std.fmt.bufPrintSentinel(b, "{s}", .{std.mem.span(v)}, 0) else null;
+ defer for (names, was) |name, w| {
+ _ = if (w) |v| host_io.Shell.setenv(name, v.ptr, 1) else host_io.testUnsetenv(name);
+ };
+ _ = host_io.Shell.setenv("PARDES_LSP_PY", "/nonexistent/pyright-langserver", 1);
+ _ = host_io.Shell.setenv("PARDES_LSP_OPEN", "on", 1);
+ const Said = struct {
+ var n: usize = 0;
+ fn post(_: ?*anyopaque, _: []const u8) void {
+ n += 1;
+ }
+ };
+ Said.n = 0;
+ // A word said before is never said twice in a row (`post`): forgotten.
+ sink_last_len[si] = 0;
+ setStatusSink(null, Said.post);
+ defer setStatusSink(null, null);
+ c.state = .off;
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ for ([_][]const u8{ "/x/a.py", "/x/b.py" }) |path| {
+ try open(io, arena.allocator(), .{ .kind = .definition, .path = path, .source = "", .offset = 0, .root = "/x" });
+ try std.testing.expectEqual(State.disabled, c.state);
+ }
+ try std.testing.expectEqual(@as(usize, 0), Said.n);
+ var buf: [256]u8 = undefined;
+ var out: std.Io.Writer = .fixed(&buf);
+ try query(io, arena.allocator(), .{ .kind = .hover, .path = "/x/a.py", .source = "", .offset = 0 }, &out);
+ try std.testing.expectEqualStrings("@none language server for .py not found\n", out.buffered());
+}
+
test "Lspinfo before any query says a server is not started yet, not off" {
var out: std.Io.Writer.Allocating = .init(std.testing.allocator);
defer out.deinit();
try status(std.testing.io, "/x/notes.txt", &out.writer);
- try std.testing.expect(std.mem.indexOf(u8, out.written(), "not started yet (its first query starts it)") != null);
+ try std.testing.expect(std.mem.indexOf(u8, out.written(), "not started yet (a file of its opened starts it)") != null);
}
test "a server that failed a moment ago is said to have failed, and when it is tried again, not to be missing" {
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index aa1f8849..f7b9cae8 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -1328,6 +1328,7 @@ const Shell = struct {
.open_link = openLink,
.start = host_io.startDetached,
.lsp = lsp,
+ .lsp_open = lspOpen,
.pipe = pipe,
.search = search,
.job = job,
@@ -2047,6 +2048,13 @@ const Shell = struct {
s.core.reportError(req.pane, "lsp", error.WorkersUnavailable);
}
+ /// Not held for `threads_ok`: the boot's file and a restored
+ /// session's are opened before `start`.
+ fn lspOpen(ctx: ?*anyopaque, pane: pardes.Pane.Id) void {
+ const s = of(ctx);
+ s.ptys.queue.openLsp(s.core, pane);
+ }
+
fn pipe(ctx: ?*anyopaque, id: u32) void {
const s = of(ctx);
if (!s.threads_ok) {