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

Chained constructor call is not formatted correctly #1762

Open
fejesjoco opened this issue Dec 4, 2023 · 0 comments
Open

Chained constructor call is not formatted correctly #1762

fejesjoco opened this issue Dec 4, 2023 · 0 comments

Comments

@fejesjoco
Copy link
Contributor

Describe the bug
When I use .callThisConstructor to have one constructor call another one, it looks formatting was forgotten.

To Reproduce

      TypeSpec.classBuilder("HelloWorld")
        .addFunction(
          FunSpec.constructorBuilder()
            .addParameter("x".repeat(30), String::class)
            .addParameter("y".repeat(30), String::class)
            .callThisConstructor(
              CodeBlock.of("x".repeat(30)),
              CodeBlock.of("y".repeat(30)),
              CodeBlock.of("x".repeat(30)),
              CodeBlock.of("y".repeat(30)),
              buildCodeBlock {
                beginControlFlow("thisIsAMethodThatUsesALambdaAndReturnsSomethingForTheConstructor")
                addStatement("z".repeat(30) + "()")
                endControlFlow()
              }
            )
            .build()
        )
        .build()
    )
    .build()
    .writeTo(System.out)

This prints:

package com.test

import kotlin.String

public class HelloWorld {
  public constructor(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: String, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: String)
      : this(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
      thisIsAMethodThatUsesALambdaAndReturnsSomethingForTheConstructor {
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz()
  }
  )
}

If this() is counted as the 1st line, then the 2nd and 3rd lines are aligned vertically with the colon but they should be more indented than that, because the this() call opened a new nesting level like it was a statement call. And what follows inside the method call in the 4th and 5th lines should be indented even more but it's actually going backwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants