Zig Version
0.16.0
ZLS Version
0.16.0
Client / Code Editor / Extensions
helix
Steps to Reproduce and Observed Behavior
- clone https://github.com/thrombe/zls
- git checkout import-bugs
- cd examples/many_modules
- open code editor (in my case, helix)
- trigger
goto definition on @cInclude("c.h") in common.zig. it works
- open
root.zig, uncomment the common.zig import
- restart zls
- trigger
goto definition on @cInclude("c.h") in common.zig. this time, it does not resolve
more detailed instructions and issue explation after my debugging.
https://github.com/thrombe/zls/blob/import-bugs/examples/many_modules/README.md
Expected Behavior
@cInclude("c.h") should resolve correctly
Attach ZLS log output
logs after uncommenting the line in root.zig and triggering goto definition on @cInclude("c.h") a few times.
zls.log
info ( main ): Starting ZLS 0.16.0 @ '/nix/store/gyznl9c2gb73126ricbv96dsd673b5b1-zls/bin/zls'
info ( main ): Log File: /home/issac/.cache/zls/zls.log (info)
info ( main ): Loaded config: /home/issac/.config/zls.json
info (server): Client Info: helix (25.07.1 (a05c151b))
info (server): added Workspace Folder: file:///home/issac/daata/repos/checkout/code_read/zls/examples/many_modules (4 files)
info (server): Set config option 'build_on_save_args' to ["-fincremental"]
info (server): Set config option 'builtin_path' to "/home/issac/.cache/zls/builtin.zig"
info (server): Set config option 'zig_lib_path' to "/nix/store/19cahh4irrwrj16dl4sbzll0ygn406ap-zig-0.16.0/lib"
info (server): Set config option 'zig_exe_path' to "/nix/store/19cahh4irrwrj16dl4sbzll0ygn406ap-zig-0.16.0/bin/zig"
info (server): Set config option 'build_runner_path' to "/home/issac/.cache/zls/build_runner/0536d83f23cda18cf0a02d9cd4e6dce4/build_runner.zig"
info (server): Set config option 'global_cache_path' to "/home/issac/.cache/zls"
info (store ): Loaded build file 'file:///home/issac/daata/repos/checkout/code_read/zls/examples/many_modules/build.zig'
info (store ): Loaded build file 'file:///home/issac/daata/repos/checkout/code_read/zls/build.zig'
After some debugging, i found that DocumentStore.getAssociatedBuildFile returns only the first root_source_file that references a file (like common.zig).
here's the relavant code:
But in this setup:
common.zig is used by multiple modules
- each module may have different include paths
ZLS picks one and ignores the others.
So:
- include paths from the “wrong” module are used
c.h can’t be found anymore
Note that compilation works because common.zig import in root.zig is never used
Zig Version
0.16.0
ZLS Version
0.16.0
Client / Code Editor / Extensions
helix
Steps to Reproduce and Observed Behavior
goto definitionon@cInclude("c.h")incommon.zig. it worksroot.zig, uncomment thecommon.zigimportgoto definitionon@cInclude("c.h")incommon.zig. this time, it does not resolvemore detailed instructions and issue explation after my debugging.
https://github.com/thrombe/zls/blob/import-bugs/examples/many_modules/README.md
Expected Behavior
@cInclude("c.h")should resolve correctlyAttach ZLS log output
logs after uncommenting the line in
root.zigand triggeringgoto definitionon@cInclude("c.h")a few times.zls.log
After some debugging, i found that
DocumentStore.getAssociatedBuildFilereturns only the first root_source_file that references a file (likecommon.zig).here's the relavant code:
But in this setup:
common.zigis used by multiple modulesZLS picks one and ignores the others.
So:
c.hcan’t be found anymoreNote that compilation works because
common.zigimport inroot.zigis never used