-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add --no-field-prefix
option
#228
base: master
Are you sure you want to change the base?
Conversation
a7810c5
to
aebd273
Compare
d89c30d
to
04e93ac
Compare
04e93ac
to
9197b19
Compare
@riz0id Could you review this PR? |
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.
Thanks for this feature. Mostly this looks good, though I do have some requests.
prefixedMethodNameWithFlag :: MonadError CompileError m => IsPrefixed -> String -> String -> m String | ||
prefixedMethodNameWithFlag _ _ "" = invalidTypeNameError "<empty name>" | ||
prefixedMethodNameWithFlag (IsPrefixed flag) serviceName (x : xs) | ||
| flag = prefixedMethodName serviceName (x : xs) | ||
| isLower x = return (fieldLikeName (x : xs)) | ||
| otherwise = fieldLikeName <$> typeLikeName (x : xs) | ||
|
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.
Do you need a keyword check in this function too?
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 is needed for the same reason in this comment (#228 (comment)), since the function is used in generating service field name and needed to avoid parse error.
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.
OK, so if it is needed, then could you add it?
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.
Thank you for your comment, I added a commit including changes you requested. Could you please review for that?
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.
Does prefixedMethodNameWithFlag
also need a keyword check?
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.
@j6carey Sorry I forgot including the commit, I'll add it.
@riz0id Thank you for the review. I'm not sure I follow your opinion correctly, but I also agree adding hs_name
option and removing the part of my changes to avoid colliding with keywords.
I strongly suggest not trying to do any case convention changes and just use the name of service methods and message fields that are provided in the protobuf source. I can't think of any situations where there is a benefit to modifying the lexical content names. Also, theres no function that exists that can convert snake case to camel case without opening up the potential for unintended name shadowing in the code generator.
I have a question about this part. In this PR, should the use of toCamelCase
be avoided, or allowed temporally to consider that it will be removed in the future?
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.
In this PR and until we have a hs_name
option, we should stick to the naming convention rules that the rest of proto3-suite
uses for record selector names which is what you do here with toCamelCase
. In the future though, when we have facilities to override names in generated Haskell code, we will probably make breaking changes to instead use snake case for records. Currently the number of edge cases that need to be considered in order to rename protobuf names to camel case Haskell identifiers is getting out of hand. Using snake case record selectors makes a lot more sense (imo) since:
- Protobuf suggests snake case for message field names by convention.
- Snake case would not require specific rules to avoid collisions with keywords or double underscores (i.e. "__").
- Many people (myself included) already use snake case by convention to distinguish record selectors from ordinary functions.
tldr; Yes use toCamelCase
for now, but once proto3-suite
supports a hs_name
option expect breaking changes that use snake case for message field names.
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.
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.
My concerns have been addressed, but @riz0id , did you want the keyword checks eliminated, or are they OK until hs_name
is available?
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.
@riz0id Do you have any remaining concerns?
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.
My concerns have been addressed, but @riz0id , did you want the keyword checks eliminated, or are they OK until hs_name
is available?
tools/compile-proto-file/Main.hs
Outdated
@@ -47,5 +47,10 @@ parseArgs = info (helper <*> parser) (fullDesc <> progDesc "Compiles a .proto fi | |||
$ long "largeRecords" | |||
<> help "Use large-records library to optimize the core code size of generated records" | |||
|
|||
isPrefixed = IsPrefixed . not <$> switch ( | |||
long "no-field-prefix" | |||
<> help "Remove prefix for record field names" |
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 is a nitpicking, but perhaps more natural explanation of the behaviour would be "do not prefix record field names by the type names", since it does not remove anything when this is enabled.
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.
Thank you, I fixed this part of the message.
Added option to remove field name prefixes from records generated by
compile-proto-file
. This change is intended for use withNoFieldSelectors
for auto-generated records.