-
Notifications
You must be signed in to change notification settings - Fork 382
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
Amino proto file loses Go doc comments #1157
Comments
I definitely agree with the idea of forwarding comments to I'm not opposed to having a dedicated |
It looks like amino has support for field comments in the P3Field struct. But I don't see any code which sets it (other than tests). |
…roto3MessagePartial (#1235) This PR resolves issue #1157 by adding support for the optional `WithComments`. See the issue for motivation. - In `amino.pkg.Type`, add optional fields `Comment` and ` FieldComments` . - Add the `Package` method `WithComments` which can optionally be used after `WithTypes`. This reads the Go source file and scans the AST for struct and field comments which are added to the `Type` object. - Update `GenerateProto3MessagePartial` to copy the comments to the `P3Doc` and related `P3Field` objects which already have an optional `Comment` field for comments that are already included in the Protobuf file. - Add test file `comments_test.go` . As shown in the test, you can use `WithComments` after `WithTypes`: pkg := amino.RegisterPackage( amino.NewPackage( "github.com/gnolang/gno/tm2/pkg/amino/genproto", "amino_test", amino.GetCallersDirname(), ).WithTypes( &TestMessageName{}, &TestMessageName2{}, // Add comments from this same source file. ).WithComments(path.Join(amino.GetCallersDirname(), "comments_test.go"))) If your Go struct looks like: // message comment type TestMessageName struct { // field comment 1 FieldName1 string // field comment 2 FieldName2 []uint64 } then your Protobuf file has: // message comment message TestMessageName { // field comment 1 string FieldName1 = 1; // field comment 2 repeated uint64 FieldName2 = 2; } <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Signed-off-by: Jeff Thompson <[email protected]> Co-authored-by: Morgan Bazalgette <[email protected]>
Closing as resolved by PR #1235 . |
…roto3MessagePartial (gnolang#1235) This PR resolves issue gnolang#1157 by adding support for the optional `WithComments`. See the issue for motivation. - In `amino.pkg.Type`, add optional fields `Comment` and ` FieldComments` . - Add the `Package` method `WithComments` which can optionally be used after `WithTypes`. This reads the Go source file and scans the AST for struct and field comments which are added to the `Type` object. - Update `GenerateProto3MessagePartial` to copy the comments to the `P3Doc` and related `P3Field` objects which already have an optional `Comment` field for comments that are already included in the Protobuf file. - Add test file `comments_test.go` . As shown in the test, you can use `WithComments` after `WithTypes`: pkg := amino.RegisterPackage( amino.NewPackage( "github.com/gnolang/gno/tm2/pkg/amino/genproto", "amino_test", amino.GetCallersDirname(), ).WithTypes( &TestMessageName{}, &TestMessageName2{}, // Add comments from this same source file. ).WithComments(path.Join(amino.GetCallersDirname(), "comments_test.go"))) If your Go struct looks like: // message comment type TestMessageName struct { // field comment 1 FieldName1 string // field comment 2 FieldName2 []uint64 } then your Protobuf file has: // message comment message TestMessageName { // field comment 1 string FieldName1 = 1; // field comment 2 repeated uint64 FieldName2 = 2; } <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Signed-off-by: Jeff Thompson <[email protected]> Co-authored-by: Morgan Bazalgette <[email protected]>
Consider this Go struct where the Receiver field has a comment. Amino converts it but the proto message Receiver field doesn't have the comment.
I know that Amino uses reflection of the Go struct type which doesn't include comments. But we could use
parser.ParseFile
to get the AST from the source code file, only for the purpose of finding comments. Then amino could copy the doc comment into the proto message.What do you think? Is it desirable for the proto message output from amino to include field comments? Is there another way to do it?
The text was updated successfully, but these errors were encountered: