-
Notifications
You must be signed in to change notification settings - Fork 207
Add EnumSection to allow decorators to modify enum member attributes #4039
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
base: main
Are you sure you want to change the base?
Conversation
Can you describe what problem this solves and an example of a using it? |
In our case, we're trying to add a
Then the string "NotBar" isn't able to be deserialized into A user could then implement a Line 118 in c63e792
|
Hey team, could we get some eyes on this please? Or if there is another way to customize attributes on enum members, can you please let us know? |
We appreciate the feature addition! I'm wondering if we could refactor this slightly to make it more consistent with our existing architecture. It seems a bit cleaner to move this customization out of
We will call this function in RustWriter.renderEnum:
This would allow concrete classes to override and add custom attributes to enum variants in a way that's consistent with our current pattern. The only trade-off would be a slight change in the output order: attributes would appear first, followed by docs and deprecated markers, and then the variant name:
Would this approach work for your use case? I think it gives us the same functionality while maintaining architectural consistency. |
Please see below comment |
Sorry, I lost context here. After ramping myself back up to speed, I'm not sure this solves our use case. We're trying to avoid overriding the enum generation completely, but instead use a decorator to modify the existing EnumGenerator behaviour. By adding a decorator that uses the Line 118 in c63e792
Lines 41 to 54 in c63e792
|
I have a broader architectural consideration: ideally, the That said, you've made a valid observation. We've already implemented this pattern for We can consider a more comprehensive refactoring of the Context/symbol provider responsibilities as a separate improvement effort if needed at a later stage. |
Thanks for the approval! I realized it would be handy to have |
Looks like there are quite a few CI failures, all similar to:
|
I see what's wrong, pushing a fix |
Getting closer, looks like its the tests failing now:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of small formatting things, but otherwise looks good. In favor of shipping if we can get all the CI failures cleaned up.
Motivation and Context
Allows users to use decorators to add additional attributes to members of an enum.
N/A
Description
Adds
EnumSection
with namedAdditionalMemberAttributes
to allow decorators to modify enum codegen.Testing
Could not find existing unit tests for customizations; please advise if you would like them to be added here. Ran
./gradlew
to ensure current tests pass.Checklist
.changelog
directory, specifying "client," "server," or both in theapplies_to
key.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.