-
Notifications
You must be signed in to change notification settings - Fork 192
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
Make RustReservedWordsSymbolProvider
configurable
#2382
Conversation
The `toEnumVariantName` function existed on symbol provider to work around enum definitions not being shapes. In the future when we refactor to use `EnumShape` instead of `EnumTrait`, there will be `MemberShape`s for each enum member. This change incrementally moves us to that future by creating fake `MemberShape`s in the enum generator from the enum definition.
A new generated diff is ready to view.
A new doc preview is ready to view. |
ee7aade
to
4860d89
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
4860d89
to
4f59076
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
), | ||
enumMemberMap = mapOf( | ||
// Unknown is used as the name of the variant containing unexpected values | ||
"Unknown" to "UnknownValue", |
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.
From a comment on #2377, these should have constants.
3337f93
to
4a4f425
Compare
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.
Is the change from send
to send_value
shown in the Server Test intended?
It looks like we've lost this mapping
"build" -> "build_value"
"builder" -> "builder_value"
"default" -> "default_value"
"send" -> "send_value"
// To avoid conflicts with the `make_operation` and `presigned` functions on generated inputs
"make_operation" -> "make_operation_value"
"presigned" -> "presigned_value"
"customize" -> "customize_value"
// To avoid conflicts with the error metadata `meta` field
"meta" -> "meta_value"
on the server side, and it's been restored for the client side only?
Does Good catch though, I need to add a |
These are preserved in ServerReservedWords:
These seem unnecessary for server, but you tell me:
|
A new generated diff is ready to view.
A new doc preview is ready to view. |
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.
The list of server reserved words looks good.
|
||
class RustReservedWordSymbolProvider(private val base: RustSymbolProvider, private val model: Model) : | ||
WrappingSymbolProvider(base) { | ||
data class RustReservedWordConfig( |
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.
nit: RustReservedWordsConfig
to match the rest of the uses?
import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator | ||
|
||
val ClientReservedWords = RustReservedWordConfig( | ||
structMemberMap = StructureGenerator.structMemberMap + |
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.
nit: I consciously make the effort to use "structure" to refer to Smithy structure shapes, and use struct only to refer to Rust struct
s.
container is StructureShape -> when (val mapped = reservedWordConfig.structMemberMap[baseName]) { | ||
null -> reservedWordReplacedName | ||
else -> mapped | ||
} |
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.
container is StructureShape -> when (val mapped = reservedWordConfig.structMemberMap[baseName]) { | |
null -> reservedWordReplacedName | |
else -> mapped | |
} | |
container is StructureShape -> | |
reservedWordConfig.structMemberMap.getOrDefault(baseName, reservedWordReplacedName) |
These can be slightly simplified.
// Real models won't end in `_` so it's safe to stop here | ||
"UnknownValue" -> "UnknownValue_" | ||
else -> reservedWordReplacedName | ||
container is EnumShape || container.hasTrait<EnumTrait>() -> when (val mapped = reservedWordConfig.enumMemberMap[baseName]) { |
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.
EnumTrait
is only applicable to string shapes; a member shape's container cannot be a string shape.
container is EnumShape || container.hasTrait<EnumTrait>() -> when (val mapped = reservedWordConfig.enumMemberMap[baseName]) { | |
container is EnumShape -> when (val mapped = reservedWordConfig.enumMemberMap[baseName]) { |
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.
Hmmm... Yeah, I think this is dead code. toMemberName
isn't even called for enum rendering. I think I'll keep it around in the event that someone refactors EnumGenerator to use toMemberName
though since this is technically correct.
@@ -22,18 +22,108 @@ import software.amazon.smithy.rust.codegen.core.util.lookup | |||
internal class RustReservedWordSymbolProviderTest { |
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.
Great tests.
A new generated diff is ready to view.
A new doc preview is ready to view. |
Motivation and Context
Fixes #1766.
Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.