From f2b02c455f2bcdfb905a015eefbb630a28b4b12e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 12 Nov 2026 10:56:42 -0300 Subject: addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py. Commit patches open as `+Diff-` and reuse only their own commit's pane, so another paged patch no longer replaces one already open. The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home. The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so. The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request. --- src/lsp/lsp_client.zig | 66 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 13 deletions(-) (limited to 'src/lsp') diff --git a/src/lsp/lsp_client.zig b/src/lsp/lsp_client.zig index cad75c57..097bddf2 100644 --- a/src/lsp/lsp_client.zig +++ b/src/lsp/lsp_client.zig @@ -774,16 +774,21 @@ fn answer(io: std.Io, arena: std.mem.Allocator, si: usize, req: lsp.Req, out: *s const g = try ensure(c, io, si, arena, req, tr); const before = out.end; try attempt(c, io, si, arena, req, out, tr, g); - // A server still loading its workspace answers at once, with nothing - // (rust-analyzer before its index): that is no answer. Wait until it says - // it is loaded, the message row saying so, and ask again. + // An empty answer can beat the startup progress notification onto the wire. const answered = out.buffered()[before..]; - if (c.loading and c.gen == g and (answered.len == 0 or std.mem.startsWith(u8, answered, "@none "))) { - tr.note("{s} is still loading: waiting for it, then asking again", .{specs[si].name}); - post(si, .always, "{s} is still loading the workspace; the answer comes when it is done\u{2026}", .{specs[si].name}); - while (c.loading and c.gen == g and c.alive()) _ = try timedWait(c, io, nowMs() + 500); - out.end = before; - try attempt(c, io, si, arena, req, out, tr, g); + if (c.gen == g and (answered.len == 0 or std.mem.startsWith(u8, answered, "@none "))) { + const startup_deadline = c.ready_at_ms + 250; + const starting = nowMs() < startup_deadline; + while (starting and !c.loading and c.progress == 0 and c.gen == g and c.alive()) { + if (!try timedWait(c, io, startup_deadline)) break; + } + if (starting or c.loading or c.progress > 0) { + tr.note("{s} is still loading: waiting for it, then asking again", .{specs[si].name}); + post(si, .always, "{s} is still loading the workspace; the answer comes when it is done\u{2026}", .{specs[si].name}); + while ((c.loading or c.progress > 0) and c.gen == g and c.alive()) _ = try timedWait(c, io, nowMs() + 500); + out.end = before; + try attempt(c, io, si, arena, req, out, tr, g); + } } } @@ -1866,19 +1871,29 @@ fn rootOf(dir: []const u8, markers: []const []const u8) []const u8 { } /// The spec's binary: the env override when set, else `bin`, PATH-searched -/// unless it names a path. +/// unless it names a path, then the standard per-user bin directory. fn binOf(spec: *const Spec, buf: *[4096:0]u8) ?[:0]const u8 { const name = if (libc.getenv(spec.env)) |v| std.mem.span(v) else spec.bin; + const path = if (libc.getenv("PATH")) |p| std.mem.span(p) else "/usr/local/bin:/usr/bin:/bin"; + const home = if (libc.getenv("HOME")) |p| std.mem.span(p) else ""; + return findBin(name, path, home, buf); +} + +fn findBin(name: []const u8, path: []const u8, home: []const u8, buf: *[4096:0]u8) ?[:0]const u8 { if (name.len == 0) return null; if (std.mem.indexOfScalar(u8, name, '/') != null) { const z = std.fmt.bufPrintSentinel(buf, "{s}", .{name}, 0) catch return null; - return if (libc.access(z.ptr, libc.X_OK) == 0) z else null; + return if (libc.access(z.ptr, libc.X_OK) == 0 and !@import("../host_io.zig").Shell.isDirectory(z.ptr)) z else null; } - const path = if (libc.getenv("PATH")) |p| std.mem.span(p) else "/usr/local/bin:/usr/bin:/bin"; var it = std.mem.tokenizeScalar(u8, path, ':'); while (it.next()) |dir| { const cand = std.fmt.bufPrintSentinel(buf, "{s}/{s}", .{ dir, name }, 0) catch continue; - if (libc.access(cand.ptr, libc.X_OK) == 0) return cand; + if (libc.access(cand.ptr, libc.X_OK) == 0 and !@import("../host_io.zig").Shell.isDirectory(cand.ptr)) return cand; + } + // Desktop launchers often omit ~/.local/bin even when shells include it. + if (std.fs.path.isAbsolute(home)) { + const cand = std.fmt.bufPrintSentinel(buf, "{s}/.local/bin/{s}", .{ home, name }, 0) catch return null; + if (libc.access(cand.ptr, libc.X_OK) == 0 and !@import("../host_io.zig").Shell.isDirectory(cand.ptr)) return cand; } return null; } @@ -2495,6 +2510,7 @@ fn notification(c: *Conn, io: std.Io, si: usize, g: u32, raw: []const u8, method } if (std.mem.eql(u8, pkind, "begin")) { c.progress += 1; + c.cond.broadcast(io); const title = str(get(value, "title")) orelse ""; c.title_len = @intCast(@min(title.len, c.title.len)); @memcpy(c.title[0..c.title_len], title[0..c.title_len]); @@ -2521,6 +2537,7 @@ fn notification(c: *Conn, io: std.Io, si: usize, g: u32, raw: []const u8, method c.progress -= 1; const idle = c.progress <= 0; if (idle) c.progress = 0; + c.cond.broadcast(io); c.mu.unlock(io); // the setpoint every burst of progress ends on; `.always` + the // dedupe above means it lands exactly once however the reports raced @@ -2997,6 +3014,29 @@ test "rootOf takes the top-most marker and falls back to git then dir" { try std.testing.expect(std.mem.startsWith(u8, deep, nothing)); } +test "language server discovery honours PATH and overrides before the user bin directory" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const io = std.testing.io; + try tmp.dir.createDirPath(io, ".local/bin"); + try tmp.dir.createDirPath(io, "path-bin"); + for ([_][]const u8{ ".local/bin/zls", "path-bin/zls" }) |path| { + const file = try tmp.dir.createFile(io, path, .{ .permissions = .fromMode(0o700) }); + file.close(io); + } + var home_buf: [4096]u8 = undefined; + const home = home_buf[0..try tmp.dir.realPath(io, &home_buf)]; + var path_buf: [4096]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/path-bin", .{home}); + var out: [4096:0]u8 = undefined; + try std.testing.expect(std.mem.endsWith(u8, findBin("zls", path, home, &out).?, "/path-bin/zls")); + try std.testing.expect(std.mem.endsWith(u8, findBin("zls", "/no-such-bin", home, &out).?, "/.local/bin/zls")); + try std.testing.expect(findBin("", path, home, &out) == null); + try std.testing.expect(findBin("/no-such-bin/zls", path, home, &out) == null); + try std.testing.expect(findBin("zls", "", "", &out) == null); + try std.testing.expect(findBin(path, "", home, &out) == null); // a directory is not executable code +} + test "specFor routes extensions and honours the disable env" { try std.testing.expect(specFor("/x/main.rs") != null); try std.testing.expect(specFor("/x/README.md") == null); -- cgit v1.3