-
Notifications
You must be signed in to change notification settings - Fork 57
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
proto3 standard compatibility improvements #143
Conversation
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.
Looks great! Just one suggestion
@@ -126,6 +126,8 @@ instance CanonicalRank DotProtoMessagePart | |||
DotProtoMessageReserved _fs -> Left (Right ()) | |||
-- We use '()' here because 'Canonicalize [DotProtoMessagePart]' | |||
-- collapses all of the 'DotProtoMessageReserved's into just one. | |||
DotProtoMessageOption _ -> Left (Right ()) |
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.
So I'm new to this section of the code, too, but I think I know what we need to do here. Basically, this module is formatting a .proto
file with everything in a specified order. The way that it works is that it maps each node in the syntax tree to some type that has an Ord
instance and then uses that Ord
instance to sort them.
This part of the code would probably be clearer and easier to fix if you first make a small refactor to replace the weird nested Either
type with a new separate datatype, like this:
data PartRank
= PartRankDefinition (Int, DotProtoIdentifier)
| PartRankReserved
| PartRankField (Maybe FieldNumber)
instance CanonicalRank DotProtoMessagePart where
canonicalRank = \case
DotProtoMessageField f -> PartRankField (canonicalRank f)
DotProtoMessageOneOf _ fs -> PartRankField (canonicalRank f)
DotProtoMessageDefinition d -> PartRankDefinition (canonicalRank d)
DotProtoMessageReserved _ -> PartRankReserved
… and then once you refactor it like that then it's easier to add in a new constructor for message options, like this:
data PartRank
= PartRankDefinition (Int, DotProtoIdentifier)
| PartRankReserved
| PartRankField (Maybe FieldNumber)
| PartRankOption DotProtoOption
instance CanonicalRank DotProtoMessagePart where
canonicalRank = \case
DotProtoMessageField f -> PartRankField (canonicalRank f)
DotProtoMessageOneOf _ fs -> PartRankField (canonicalRank f)
DotProtoMessageDefinition d -> PartRankDefinition (canonicalRank d)
DotProtoMessageReserved _ -> PartRankReserved
DotProtoMessageOption o -> PartRankOption o
I haven't type-checked that suggestion, so there might be a few mistakes or other things that would need to be fixed, but I think that's the general idea of how to go about this.
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.
@Gabriel439 thanks for advise, it worked perfectly! Fixed in 699277b
I also changed order of PartRank
constructors to provide more logical ordering of protobuf AST.
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.
I don't understand the "Added CircleCI support" part of this pull request, since we don't use CircleCI. What's your intention adding .circleci/config.yml
?
We are using CircleCI, in our fork, you can see it there https://github.com/coingaming/proto3-suite/commits/master But if you don't want it - I can remove it for sure. |
@tkachuk-labs I think it would be best if you removed it from the pull request to avoid confusion. I don't think it's common for open source projects to have multiple CI configs unless they're actually using those CI services. |
@evanrelf sure, no problem! |
…ation of DotProtoMessagePart, removed CircleCI support
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.
Looks great! Just one last thing
DotProtoMessageOption x -> PartRankOption x | ||
DotProtoMessageDefinition d -> PartRankDefinition (canonicalRank d) | ||
DotProtoMessageReserved _fs -> PartRankReserved | ||
-- We don't use '_fs' here because 'Canonicalize [DotProtoMessagePart]' |
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.
This comment needs to be relocated above the DotProtoMessageOneOf
case after your change
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.
But it was like this before. Comment is related to DotProtoMessageReserved _fs
AST node. So it depends on style of codebase - should I put comment after related to comment line, or before.
proto3-suite/tools/canonicalize-proto-file/Main.hs
Lines 126 to 128 in c40e73e
DotProtoMessageReserved _fs -> Left (Right ()) | |
-- We use '()' here because 'Canonicalize [DotProtoMessagePart]' | |
-- collapses all of the 'DotProtoMessageReserved's into just one. |
…linux generator binary matching local swagger2 version
I did added
|
@tim2CF: I added you as a collaborator so that you can merge this whenever you think this is ready |
Thanks, Gabriel! |
You're welcome! 🙂 |
Sure @evanrelf ! I've got busy with the other stuff, so if you will help me to fix conflicts and finally merge, this will be super cool! |
Hmm... @tim2CF, can you see if this option is enabled in the pull request sidebar? I can't seem to push to
Or maybe I've misunderstood that GitHub option? |
@evanrelf seems like organization github accounts don't have this feature, but I did invited you as a contributor directly from our fork repo. Please try it |
Thanks, that worked. This branch is now updated with the latest changes from @tim2CF Since Gabriel gave you the commit bit, feel free to merge whenever you're ready! EDIT: And feel free to remove me from |
Cool, thanks for the help @evanrelf ! |
DotProtoMessageOption
constructor to support options inside messages, provided example, included to tests, exampleglobalIdentifier
parser to support leading dots on field types, provided example, included to tests, exampleSwaggerObject
conditional compilation bug here