Skip to content

Conversation

@Techatrix
Copy link
Member

ZLS had an inaccurate view of how modules work in the build system. It would previously merge every module in the entire build graph into one single module which can easily lead to incorrect results in any non trivial project that contains multiple modules. This PR will keep track of each individual module so that analysis can differentiate between them just like how the compiler does it.

Some examples of what has been improved:

  • @import("root") now actually figures out in which module a given file is in.
  • auto complete for @import will only show the modules that have been directly added to the module that the current file belongs to
  • @import("some_name") will resolve the correct module if there are multiple modules that have imported different modules with "some_name" as their name.

One issue this PR doesn't fully address is when there are multiple modules with the same root source file that have conflicting definitions. This is only achievable using multiple compilation units because Zig fortunately disallows sharing a root source file within a single compilation unit.

Related PR #2308

@Techatrix Techatrix force-pushed the techatrix/model-build-system branch from 31a1a3a to 725af1e Compare November 18, 2025 19:32
The completions are ordered like this:
- the `std` module
- the `builtin` module
- the `root` module
- other modules
- files

This is the same as the source.organizeImports code action.
This allows the build runner check to handle paths that are in the
local or global zig cache.
@Techatrix Techatrix force-pushed the techatrix/model-build-system branch from 725af1e to 31481f3 Compare November 19, 2025 19:41
@dotcarmen
Copy link
Contributor

@import("root") now actually figures out in which module a given file is in.

fyi - it seems that can't really be relied upon

https://gist.github.com/dotcarmen/7f186613f1f839427a839c33306af9dd <- the output is:

hello, world!
exe says hello

what happens when a module is imported by multiple roots? i think it's best to not resolve @import("root") to anything to avoid any footguns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants