From 17908d6d60850d9131b12e480b21e446b0b8eb9a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 14:08:53 -0300 Subject: 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 --- src/lsp/lsp_zls.zig | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src') 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| { -- cgit v1.3