Skip to content

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

Open
rrousselGit opened this issue Feb 6, 2025 · 5 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. P2 A bug or feature request we're likely to work on type-design

Comments

@rrousselGit
Copy link

Consider the following user-defined code:

@annotation
class Foo {}

Which then generates the following invalid code:

final int value = "";

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 with build_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:

// {@generatedBy line=1 column=1}
<insert some generated code>
// {@endGeneratedBy}

Such comments could be automatically added by source_gen when using AnnotationBuilder.
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

@dart-github-bot
Copy link
Collaborator

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.

@dart-github-bot dart-github-bot added legacy-area-analyzer Use area-devexp instead. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Feb 6, 2025
@keertip keertip added the P2 A bug or feature request we're likely to work on label Feb 7, 2025
@bwilkerson bwilkerson added type-design and removed P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels Feb 8, 2025
@bwilkerson
Copy link
Member

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.

@davidmorgan
Copy link
Contributor

dart-lang/build#3806

@rrousselGit
Copy link
Author

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?

#56764
#56518

@keertip keertip added P3 A lower priority bug or feature request P2 A bug or feature request we're likely to work on labels Feb 10, 2025
@bwilkerson
Copy link
Member

Those are at least some of them, yes. Thanks for finding them and linking them here.

@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Feb 12, 2025
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request labels Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. P2 A bug or feature request we're likely to work on type-design
Projects
None yet
Development

No branches or pull requests

6 participants