summaryrefslogtreecommitdiff
path: root/src/lsp/lsp.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-23 10:51:51 -0300
committerGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
commit7b743fcc7d568f13512a59089c5214bb6fa3282f (patch)
treeab133f70ded7b9b415115345adfc6ff043117b03 /src/lsp/lsp.zig
parentb8f076b63d6fcbb01539d5541520a32bccc0e219 (diff)
downloadpardes-7b743fcc7d568f13512a59089c5214bb6fa3282f.tar.gz
pardes-7b743fcc7d568f13512a59089c5214bb6fa3282f.zip
Audit (LSP, PDF): one client dispatch, docParams, renameEdits in one loop, std.c externs; one whole-page render, openBytes only
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/lsp/lsp.zig')
-rw-r--r--src/lsp/lsp.zig34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/lsp/lsp.zig b/src/lsp/lsp.zig
index 1c1b57a2..1263b583 100644
--- a/src/lsp/lsp.zig
+++ b/src/lsp/lsp.zig
@@ -91,39 +91,31 @@ test "an explain request narrates the query named in its arg, a definition by de
/// Every language, Zig's (zls) included, through the protocol client, which
/// runs its server as a child process. None on the web or the board.
-const backends = if (@import("pardes_config").platform == .web or @import("pardes_config").platform == .esp32p4)
- .{}
-else
- .{@import("lsp_client.zig")};
+const has_client = switch (@import("pardes_config").platform) {
+ .web, .esp32p4 => false,
+ else => true,
+};
+const client = if (has_client) @import("lsp_client.zig") else void;
pub const backend_name = "lsp-client";
-pub const supports: std.EnumSet(Kind) = blk: {
- var s: std.EnumSet(Kind) = .empty;
- for (0..backends.len) |i| s.setUnion(backends[i].supports);
- break :blk s;
-};
+pub const supports: std.EnumSet(Kind) = if (has_client) client.supports else .empty;
pub fn speaks(path: []const u8) bool {
- inline for (backends) |b| if (b.speaks(path)) return true;
- return false;
+ return has_client and client.speaks(path);
}
pub fn query(io: std.Io, gpa: std.mem.Allocator, arena: std.mem.Allocator, req: Req, out: *std.Io.Writer) !void {
if (req.kind == .status) {
try out.print("backend: {s}\n", .{backend_name});
- inline for (backends) |b| try b.query(io, gpa, arena, req, out);
+ if (has_client) try client.query(io, gpa, arena, req, out);
return;
}
- inline for (backends) |b| {
- if (b.speaks(req.path) and b.supports.contains(req.kind))
- return b.query(io, gpa, arena, req, out);
- }
- if (req.kind == .explain and backends.len > 0)
- return backends[0].query(io, gpa, arena, req, out);
+ if (has_client and (req.kind == .explain or (client.speaks(req.path) and client.supports.contains(req.kind))))
+ return client.query(io, gpa, arena, req, out);
// Nothing asked: said why, where an empty answer would read as nothing
// found.
- inline for (backends) |b| if (b.speaks(req.path))
+ if (speaks(req.path))
return none(out, "the language server for this file does not answer it", .{});
try none(out, "no language server for this file", .{});
}
@@ -136,7 +128,7 @@ pub fn none(out: *std.Io.Writer, comptime fmt: []const u8, args: anytype) std.Io
// Called on server reader threads; the sink must copy text before returning.
pub fn setStatusSink(ctx: ?*anyopaque, cb: ?*const fn (ctx: ?*anyopaque, text: []const u8) void) void {
- inline for (backends) |b| b.setStatusSink(ctx, cb);
+ if (has_client) client.setStatusSink(ctx, cb);
}
pub fn rel(base: []const u8, path: []const u8) []const u8 {
@@ -218,7 +210,7 @@ test "LSP encoders report every insufficient output capacity" {
}
test "a question no backend answers for a file says why rather than find nothing" {
- if (backends.len == 0) return;
+ if (!has_client) return;
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
var buf: [256]u8 = undefined;