add trace promotion for error bundle diagnostics - #3240
Open
DaliVana wants to merge 1 commit into
Open
Conversation
When a compile error is located outside of the workspace (e.g. inside the standard library or a dependency), report the error at the innermost reference trace location that is inside the workspace instead. The original error location, the error notes and the remaining reference trace entries are preserved as LSP related information. Previously such errors were published under the library file's URI and their reference traces were discarded entirely, which made them effectively invisible in the editor. The new `promote_reference_traces` config option (default: true) can be used to restore the previous behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello, this implements "trace promotion" (zigtools/zls#3239) and (zigtools/zls#2018): when a compile error's primary location is outside the workspace (standard library, dependencies in the package cache, or generated files in cache directories), the diagnostic is reported at the innermost reference trace location that is inside the workspace. The line where user code handed off to the library. Full fidelity is preserved through LSP relatedInformation:
A new promote_reference_traces config option (default: true) restores the raw locations when disabled.
Why
Errors in comptime-heavy code often point into std (e.g. std.debug.print("{s}", .{42}) fails inside std/fmt.zig). ZLS published those diagnostics under the library file's URI — a file the user typically never has open — and discarded the reference trace during conversion, making the error effectively invisible in the editor.
How
Known limitations, left out deliberately: toggling the option only takes effect on the next build cycle (not added to the build-on-save restart set), workspace matching is byte-exact (case-insensitive filesystems can miss promotion — it fails open to the old behavior), and multi-root workspaces are scoped to each build's root. Deep comptime chains benefit from raising -freference-trace via build_on_save_args.
Tests cover: promotion with notes and sentinel entries, the disabled option, no-workspace-frame degradation, workspace-local errors staying put, innermost-frame selection with two user frames, null src_base_path, trace survival through version-merge (addBundleAsRoots), and the path predicate.
closes #3239
closes #2018