zigtools / zls

A Zig language server supporting Zig developers with features like autocomplete and goto definition
MIT License
2.86k stars 290 forks source link

referencing the same module by different import names has regressed #1994

Closed leecannon closed 1 month ago

leecannon commented 1 month ago

Zig Version

0.14.0-dev.944+0e99f517f

Zig Language Server Version

0.14.0-dev.72+d8084a3

Client / Code Editor / Extensions

VSCode vscode-zig

Steps to Reproduce and Observed Behavior

Since https://github.com/zigtools/zls/pull/1983 the ZLS build runner no longer captures having multiple import names for the same module, resulting in it being unable to resolve @import's that the zig compiler is fine with.

// build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{
        .name = "fff",
        .root_source_file = b.path("main.zig"),
        .target = b.standardTargetOptions(.{}),
        .optimize = b.standardOptimizeOption(.{}),
    });

    exe.root_module.addImport("self", &exe.root_module);

    const run_cmd = b.addRunArtifact(exe);
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

// main.zig
const root = @import("root");
const self = @import("self");

pub fn main() void {}

With 0.14.0-dev.72+d8084a3 build runner:

{
  "deps_build_roots": [],
  "packages": [
    {
      "name": "root",
      "path": "/home/lee/src/fff/src/main.zig"
    }
  ],
  // the rest is fine
}%

With 0.14.0-dev.67+312b7dc (commit before https://github.com/zigtools/zls/pull/1983) build runner:

$ zig build --build-runner ../zls/src/build_runner/0.12.0.zig
{
  "deps_build_roots": [],
  "packages": [
    {
      "name": "root",
      "path": "/home/lee/src/fff/src/main.zig"
    },
    {
      "name": "self",
      "path": "/home/lee/src/fff/src/main.zig"
    }
  ],
  // the rest is fine
}%

This seems to be due to Module.DependencyIterator.next building a set of unique modules disregarding multiple import names. https://github.com/ziglang/zig/blob/cf87a1a7cf57123aad533a73d8e0fa4d4916a674/lib/std/Build/Module.zig#L382-L387

Expected Behavior

The build runners packages list should include all import names a module has not just one.

Relevant log output

No response