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

Add generated comments to Kotlin files (default true) #486

Merged
merged 1 commit into from
May 23, 2022

Conversation

shashachu
Copy link
Contributor

Will respect the existing --omit-file-comments flag

Fixes #485

Will respect the existing `--omit-file-comments` flag

Fixes microsoft#485
@@ -2606,5 +2617,12 @@ class KotlinCodeGenerator(
private fun String.capitalize(): String {
return this.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.US) else it.toString() }
}

companion object {
private const val FILE_COMMENT =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how you feel about this copypasta; there wasn't an obvious shared place to put the constants but I'm happy to move.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd have imagined that after working in this codebase, you'd have seen enough copypasta from me not to worry about it 😆

(This is absolutely fine by me, thank you for asking)

private fun generate(thrift: String, config: (KotlinCodeGenerator.() -> KotlinCodeGenerator)? = null): List<FileSpec> {
val configOrDefault = config ?: { this }
val configOrDefault = config ?: { emitFileComment(false) }
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 can also default this to true but it's a bit annoying to handle the changing timestamp.

@codecov-commenter
Copy link

Codecov Report

Merging #486 (eaf3841) into master (96a7179) will increase coverage by 0.02%.
The diff coverage is 85.71%.

@@             Coverage Diff              @@
##             master     #486      +/-   ##
============================================
+ Coverage     59.15%   59.18%   +0.02%     
- Complexity      865      868       +3     
============================================
  Files            69       69              
  Lines          6481     6488       +7     
  Branches       1010     1012       +2     
============================================
+ Hits           3834     3840       +6     
- Misses         2345     2346       +1     
  Partials        302      302              
Impacted Files Coverage Δ
.../com/microsoft/thrifty/compiler/ThriftyCompiler.kt 0.00% <0.00%> (ø)
.../com/microsoft/thrifty/kgen/KotlinCodeGenerator.kt 84.81% <100.00%> (+0.06%) ⬆️

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 96a7179...eaf3841. Read the comment docs.

@@ -149,6 +151,7 @@ class KotlinCodeGenerator(
private var emitJvmName: Boolean = false
private var emitJvmStatic: Boolean = false
private var emitBigEnums: Boolean = false
private var emitFileComment: Boolean = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally I'd prefer this to default to false, if only to minimize the disruption to others. AFAIK most people using thrifty are still manually checking in the generated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benjamin-bader I don't have a strong opinion either way, but it does default to true for Java sources, which means the default will change depending on whether you generate Java or Kotlin. I will defer to you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You make a good point. I'd forgotten entirely about the Java code-generator, despite directly referring to it. Shows where our focus is, I suppose. Let's keep it on by default, then.

@benjamin-bader
Copy link
Collaborator

Sorry for the delay; crazy family visit == no time to think about anything! I appreciate the effort. This basically LGTM but I'd like to make the comment an opt-in feature - that is, it should default to false.

@shashachu
Copy link
Contributor Author

@benjamin-bader How dare you prioritize family over your volunteer OSS work! :) Anyway, I responded to your comment re the default value. I can update the docs if we end up having different behavior for Java vs Kotlin.

@benjamin-bader
Copy link
Collaborator

How dare you prioritize family over your volunteer OSS work! :)

It's one weakness that I indulge, I admit.

Thanks for your contributions, as always!

@benjamin-bader benjamin-bader merged commit c2d854b into microsoft:master May 23, 2022
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.

Question/feature request: Add header/comments to each file
3 participants