Skip to content
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

Implement hack_namespace option for hack codegen #31

Merged
merged 2 commits into from
Aug 5, 2024

Conversation

jtquip88
Copy link
Contributor

@jtquip88 jtquip88 commented Jul 30, 2024

Modify proto-hack codegen to support a custom namespace for generated hack code.
A new option called hack_namespace can be added to .proto files as a compiler hint. Eg. `option (hack_namespace) = "fizzy\bazzy";. When the hack_namespace option is set, the generated hack classes will be placed in the specified namespace.

Change details:

  • The namespace at the top of generated class is changed to custom hack namespace if available.
  • If a file has hack_namespace, all references to its fields in other proto classes will use custom namespace prefix.
    When running the codegen, the first phase is to build a namespace tree for protobuf file. During this phase, a new attribute cFqn will also be populated. This attribute is the fully qualified name of the field prefixed with custom namespace. When generating output classes, cFqn will be used to refer to fields instead of fqn, if it is available.

@@ -17,3 +17,15 @@ enum AEnum2 {
message refexample3 {
Funky funky = 1;
}

service MyService {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a service here to validate custom hack namespace is reflected in generated service definitions as well.

}

func newNamespace(parent *Namespace, myName string) *Namespace {
// Builds a namespace tree with the given fully qualified name and custom fully qualified name.
func newNamespace(parent *Namespace, myName string, customName *string) *Namespace {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go doesn't have optional parameters so had to use a variadic(reference type) parameter customName.

@jtquip88 jtquip88 merged commit 594428b into master Aug 5, 2024
2 checks passed
@junoatwork junoatwork deleted the add_custom_hack_namepsace branch August 6, 2024 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants