Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: In amino.pkg, add optional WithComments, use them in GenerateP…
…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]>
- Loading branch information