-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Macros follow-up: Support emitting diagnostics in the generated code #60062
Comments
Summary: User requests a mechanism to emit custom diagnostics from code generators, suggesting a |
I would love to have a way for the analyzer and the compilers to emit diagnostics that are generated by a code generator. My expectation is that generator authors would use this feature to provide a better UX for their users. I would prefer to have support for this that doesn't require writing the diagnostics into the generated code. I think the UX would be much better if they are communicated to the tools in a different way. But if we can't find a better way to get the diagnostic information then I think we should explore using generated output, whether a comment or an annotation, as a means of getting this information to the tools. (A note to possible designers: there's more information about a diagnostic that I'd want to have communicated than what's proposed in the above example.) @davidmorgan For visibility. |
Yes, for sure we want a way for generators to report diagnostics--and fixes. More generally what we want is an information channel generator -> analysis server.
|
The specifics of the communication channel depends on the architecture of the system. Once we know how and when we're going to generate code I suspect that the choice of a communication channel will be fairly obvious. |
One very useful feature Macros proposed was the ability to emit custom errors/warnings.
This was helpful because code-generators often have some form of error cases.
Since macros are cancelled, could we maybe have some dumbed down version of this?
Proposal: A custom comment similar to
// ignore
for emitting diagnosticsOne way generators could emit diagnostics could be through comments.
For example, we could imagine a generator output:
// @diagnostic kind=error line=10 colum=5 message="You must provide a constuctor"
This would output an error in the associated file, with the given parameters.
Bonus: Have
build
orsource_gen
automatically emit such comment when an exception is thrown by generatorsCurrently, generators rely on throwing
InvalidSourceException
to emit similar error reports.The generation tooling could catch those and output a corresponding
// @diagnostic
,The text was updated successfully, but these errors were encountered: