Skip to content

restrain cross-file symbol references within it's build system module#2608

Merged
Techatrix merged 9 commits intomasterfrom
techatrix/references
Feb 17, 2026
Merged

restrain cross-file symbol references within it's build system module#2608
Techatrix merged 9 commits intomasterfrom
techatrix/references

Conversation

@Techatrix
Copy link
Member

@Techatrix Techatrix commented Feb 15, 2026

fixes #1071

When requesting references on a file that is within a build system module, the search will be constrained within the given module. This should give more predictable results compared to flawed approach that is preceded it (see #1071). However, this does not yet account from references across modules (or projects) which can be implemented in the future.

This change also fixes an issue with #2339 where symbol references would load all build files inside of the workspace. This is especially problematic with projects that have many build files like the Zig compiler codebase.

Followup Issues:

Preparation for better cross-file references.
A percent encoding with one upper and one lower case letter would not be normalized properly.
Also avoids unnecessary loop iterations when encountering an already normalized percent encoding.
This enable imports to be resolved on documents with non `file` uri scheme.
This logic is mostly guesswork. Perhaps we can bring it back after fixing cross file references.
Please Andrew, remove cImport from the language. I beg you.
When requesting references on a file that is within a build system
module, the search will be constrained within the given module. This
does not account for references across modules (or projects) which may be
implemented in the future.

When the file is not part of a build system module, the search will be
across all files that are loaded by ZLS. With workspace  symbols (#2339)
all files in workspace folders will be loaded. Files that never
(transitively) import the target symbol file will be filtered out so
this isn't necessarily as slow as it may sound like.
@Techatrix Techatrix force-pushed the techatrix/references branch from 8a9cb60 to 7508e06 Compare February 15, 2026 16:44
@xdBronch
Copy link
Contributor

xdBronch commented Feb 16, 2026

// a.zig
const b = @import("b.zig");
const Foo = b.Foo;
comptime {
    _ = Foo;
}

// b.zig
pub const Foo = struct {};

this fails to find the _ = Foo;

Only works for aliases that do not rename the symbol.

```zig
const A = foo.A; // works
const B = foo.A; // doesn't work because the symbol was renamed
```
@Techatrix Techatrix force-pushed the techatrix/references branch from 7508e06 to d387dd5 Compare February 16, 2026 18:24
@Techatrix
Copy link
Member Author

this fails to find the _ = Foo;

Fixed.

@Techatrix Techatrix merged commit 3008897 into master Feb 17, 2026
6 checks passed
@Techatrix Techatrix deleted the techatrix/references branch February 17, 2026 20:28
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.

Broken cross-file references

2 participants

Comments