-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Macros follow-up: Transpose compilation errors in the generated code to the corresponding annotation #60063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Summary: Generated code from annotations may contain compilation errors. The proposal suggests adding comments to link generated code to its source annotation, improving error reporting. |
I'm not where I can easily find the references, but there were some discussions about navigation related to the macros work, and I believe that those discussions are equally relevant for any code generation support. We should link to them from this issue if this is where the conversation will be resumed for the non-macros case. @davidmorgan For visibility. |
Those issues? |
Those are at least some of them, yes. Thanks for finding them and linking them here. |
Consider the following user-defined code:
Which then generates the following invalid code:
This generated code contains a compilation error. But inspecting the generated code can be tedious.
One thing macros proposed was to host any such compilation error directly on the
@annotation
. We should be able to do the same withbuild_runner
using Analyzer.Proposal: Box generated code in comments that point to the associated annotation
The main challenge to this feature is knowing "Which annotation generated which code?"
For that, I propose to introduce a convention: Generated code should tell which annotation they are coming from.
We could imagine this:
Such comments could be automatically added by
source_gen
when usingAnnotationBuilder
.And the analyzer would pick-it-up and show any compilation error within those bounds in the annotation instead.
Of course, clicking on the error would open the generated code at the revelant location
The text was updated successfully, but these errors were encountered: