summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 14:08:53 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commit17908d6d60850d9131b12e480b21e446b0b8eb9a (patch)
tree3ae320efa41aa86337d7a1b0e6af5690090891e6
parent7cf2c9947ce0a5529b15835b7e1eecb30a2e68c2 (diff)
downloadpardes-17908d6d60850d9131b12e480b21e446b0b8eb9a.tar.gz
pardes-17908d6d60850d9131b12e480b21e446b0b8eb9a.zip
Lspinfo lists pardes's own dependency imports only for a file in pardes's tree
The in-process ZLS's report listed the module map of the build pardes came from (vaxis, ghostty and the rest) for any .zig file, a project that has none of them included. It now lists them only for a file in that tree (project_root, a build option), and says there are none for any other. Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--build.zig2
-rw-r--r--src/lsp/lsp_zls.zig26
2 files changed, 24 insertions, 4 deletions
diff --git a/build.zig b/build.zig
index 79de8a81..b43f3fd9 100644
--- a/build.zig
+++ b/build.zig
@@ -752,6 +752,8 @@ pub fn build(b: *std.Build) void {
for ([_]?*std.Build.Step.Options{ opts, gui_opts }) |maybe| if (maybe) |o| {
o.addOption([]const []const u8, "module_names", mod_names);
o.addOption([]const []const u8, "module_roots", mod_roots);
+ // Whose imports those are: a .zig file outside this tree has none of them.
+ o.addOption([]const u8, "project_root", b.build_root.path orelse "");
};
const iso_off = b.addOptions();
diff --git a/src/lsp/lsp_zls.zig b/src/lsp/lsp_zls.zig
index 09493c26..2311ec47 100644
--- a/src/lsp/lsp_zls.zig
+++ b/src/lsp/lsp_zls.zig
@@ -354,10 +354,14 @@ fn status(arena: std.mem.Allocator, req: lsp.Req, out: *std.Io.Writer) !void {
// The dependency module map, which is the answer to "why does gd work on
// std and not on @import(\"vaxis\")" — if a name is not on this list, the
// build did not import it and nothing can resolve it.
- try out.print("\ndependency imports gd can follow ({d}):\n", .{cfg.module_names.len});
- for (cfg.module_names, cfg.module_roots) |n, r| {
- try out.print(" {s:<14} {s}\n", .{ n, r });
- }
+ // pardes's own build's imports: listed for a file in its tree, none for
+ // any other project's file, which does not have them.
+ if (inProject(req.path)) {
+ try out.print("\ndependency imports gd can follow ({d}):\n", .{cfg.module_names.len});
+ for (cfg.module_names, cfg.module_roots) |n, r| {
+ try out.print(" {s:<14} {s}\n", .{ n, r });
+ }
+ } else try out.print("\ndependency imports gd can follow: none (this file is not in the tree pardes was built from)\n", .{});
try out.print("asked from: {s}\n", .{if (req.path.len == 0) "a pane with no file" else req.path});
try out.print("\nanswers:", .{});
@@ -426,6 +430,20 @@ fn status(arena: std.mem.Allocator, req: lsp.Req, out: *std.Io.Writer) !void {
/// running ITS build.zig.
/// 3. A module whose root source is a GENERATED file is absent from the
/// table: it has no path until make() runs.
+/// Whether `path` is in the tree pardes was built from, whose build's
+/// imports `cfg.module_names` are.
+fn inProject(path: []const u8) bool {
+ const project = std.mem.trimEnd(u8, cfg.project_root, "/");
+ return project.len > 0 and path.len > project.len and std.mem.startsWith(u8, path, project) and path[project.len] == '/';
+}
+
+test "only a file in pardes's own tree is told pardes's dependency imports" {
+ var buf: [4096]u8 = undefined;
+ const inside = try std.fmt.bufPrint(&buf, "{s}/src/main.zig", .{std.mem.trimEnd(u8, cfg.project_root, "/")});
+ try std.testing.expect(inProject(inside));
+ try std.testing.expect(!inProject("/tmp/elsewhere/main.zig"));
+}
+
fn moduleRoot(name: []const u8) ?[]const u8 {
comptime std.debug.assert(cfg.module_names.len == cfg.module_roots.len);
for (cfg.module_names, cfg.module_roots) |n, r| {