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

Extend package choosing behavior to protobuf files with Enum types #339

Merged
merged 20 commits into from Oct 24, 2020

Conversation

dmarticus
Copy link
Contributor

Closes #337.

cc @a7emenov

dmartin-TA and others added 4 commits September 27, 2020 15:04
…. Now I need to update the name extracting method to not fail on fully-qualified names that end with the same word
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #339 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #339      +/-   ##
==========================================
+ Coverage   85.20%   85.23%   +0.02%     
==========================================
  Files          29       29              
  Lines        1954     1951       -3     
  Branches       28       24       -4     
==========================================
- Hits         1665     1663       -2     
+ Misses        289      288       -1     
Impacted Files Coverage Δ
...igherkindness/skeuomorph/protobuf/ParseProto.scala 96.57% <100.00%> (-0.06%) ⬇️
...in/scala/higherkindness/skeuomorph/mu/schema.scala 65.33% <0.00%> (+1.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 574226d...e558de3. Read the comment docs.

dzanot
dzanot previously approved these changes Oct 5, 2020
@dmarticus
Copy link
Contributor Author

@BenFradet let me know what you think of my explanation for your question when you have time :)

Copy link
Contributor

@L-Lavigne L-Lavigne left a comment

Choose a reason for hiding this comment

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

(See my reply to the comment thread.)

dzanot
dzanot previously approved these changes Oct 17, 2020
@dmarticus dmarticus changed the title Extend empty package handling to protobuf files with Enum types Extend package choosing behavior to protobuf files with Enum types Oct 23, 2020
@@ -450,17 +443,22 @@ object ParseProto {
}
}

private def matchOnPackageParameters[A](name: String, file: NamedDescriptor[A]) = {
Copy link
Contributor

@L-Lavigne L-Lavigne Oct 23, 2020

Choose a reason for hiding this comment

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

I suggest integrating this method into the initializer of NamedDescriptor.fullName (which isn't directly used anywhere else) and then simply calling file.fullName.endsWith(name).

Perhaps we could also change fullName to a val and rename it to something more descriptive like fullProtoName.

Copy link
Contributor

@L-Lavigne L-Lavigne Oct 23, 2020

Choose a reason for hiding this comment

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

Following up on that - we could have the following implementations in NamedDescriptor:

    val fullProtoName: String =
      (List(".", filePackage) ++ parentMessageNames :+ name).mkString(".")

    val scalaPrefix: List[String] =
      (scalaPackage.split('.').toList :+ enclosingProto) ++ parentMessageNames

I don't know if it would work for all cases, but it passes the unit tests at least. Also it means we could remove the javaPackage parameter and fqnParts member.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea a lot! Thanks for sharing! I will take a crack at this implementation :)

…cala

Co-authored-by: Lawrence Lavigne <contact.lavigne@gmail.com>
@@ -121,7 +123,7 @@ object ParseProto {
}
}

private def getPackageOrJavaPackage(file: FileDescriptorProto): String = {
private def namePackage(file: FileDescriptorProto): String = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(thinking aloud) should this be called choosePackageFrom or something else? namePackage seems ambiguous in a way I don't like.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should call it scalaPackage since that's what the ScalaPB doc (linked in the method's comment) says it is. We'd also rename the NamedDescriptor parameter accordingly. (As per my other suggestion: fqn would become scalaPackage and packageName would become filePackage).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I addressed this comment and your other one in my most recent change! @L-Lavigne :)

@dmarticus
Copy link
Contributor Author

@L-Lavigne any insights as to why this dropped coverage? I added more tests than before but the code coverage bot says I decreased coverage overall... might add some additional unit tests to see if that helps.

* a `java_package` and a `package`, so this approach makes sure that we always match with the correct
* value).
*/
val fullName: String =
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this one anymore, in my experiments I was matching on fullProtoName instead (since that one is specially built using the filePackage and not the javaPackage). If that works we can eliminate the javaPackage constructor parameter altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah good call! Sorry; thank you for clarifying :)

Copy link
Contributor

@L-Lavigne L-Lavigne left a comment

Choose a reason for hiding this comment

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

Great job! 🎉

@dmarticus dmarticus merged commit 24ba7e7 into master Oct 24, 2020
@dmarticus dmarticus deleted the issue337 branch October 24, 2020 04:31
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.

Invalid enums generated if package option is not supplied
5 participants