With kotlinpoet 2.0, can you somehow enable writin...
# squarelibraries
h
With kotlinpoet 2.0, can you somehow enable writing each parameter of a function on a new line (with trailing comma)?
j
No
2.0 hasn't changed anything except whitespace wrapping by default
It's otherwise just the next 1.x
h
Hm, I definitely do see some changes regarding a function with long name/types and parameters with default values: 1.18.1: public suspend fun HttpClient.bazACsrfToken(X_CSRF_Token: String = "FETCH", builder: suspend HttpRequestBuilder.() -> Unit = {}) { 2.0.0: public suspend fun HttpClient.bazACsrfToken(X_CSRF_Token: String = "FETCH", builder: suspend HttpRequestBuilder.() -> Unit = {}) { And IMHO, I would prefer this: public suspend fun HttpClient.bazACsrfToken( X_CSRF_Token: String = "FETCH", builder: suspend HttpRequestBuilder.() -> Unit = {}, ) {
j
That's probably the whitespace wrapping change
1
Wrapping to individual lines is currently done by count, not length
h
But you can't customize this count, can you?
j
No
h
Are you open to change the hard coded limit/discuss a customization?
j
No, that's not an option that should need to be customized.
If you'd like to attempt changing it to length-based we'd all welcome that https://github.com/square/kotlinpoet/issues/274
h
Hmmm, I don't think it should based on the line, but always produces a new line for each parameter of the function, and just set the counter to 0 🤷🏻‍♂️ And yes, this would result into more lines, even for small functions. But I also agree it's just a code style and everybody has its own.
j
It helps diffs, for sure. Although generated code isn't checked in frequently.
h
Yeah that's true, but if you use this argument, there is no need for smarter/prettier code style too. The most reason to checkin generated code is the test code for a custom code generator. And the diffs helps a lot.
c
We have a couple cases where generated code is checked in; diffs do help. We run a formatter on the generated code for consistency.
j
The existing formatting is best effort without customization. We also recommended the use of a formatter for people who need it.
1
One of the problems is that we currently write directly to the appendable, so we can't just rewind the stream. We have to change it to write the function signature to a separate
StringBuilder
, determine if it wrapped/exceeded the limit, and then either commit that directly to the real appendable or rewrite it forcing parameters onto each line. Not impossible, but slightly harder than it should be.
c
still not as complicated as generating an AST and rendering/formatting from that 😉 Thx for Kotlin Poet, its an amazing tool.
j
👍 There's dozens a few of us behind it, but i'm also thankful for its existence