ktfmt icon indicating copy to clipboard operation
ktfmt copied to clipboard

Indent is inconsistent when lambda is qualified vs not.

Open stevietrouble opened this issue 4 years ago • 3 comments

Actual Behavior

val fn = launch {
  doThing()
  doAnother()
}

val fn =
    scope.launch {
  doThing()
  doAnother()  
}

Expected Behavior

val fn = launch {
  doThing()
  doAnother()
}

val fn = scope.launch {
  doThing()
  doAnother()  
}

stevietrouble avatar Apr 08 '21 18:04 stevietrouble

The issue is that lambdaOrScopingFunction and processLambdaOrScopingFunction do not handle dot qualified lambdas.

May need to refactor emitQualifiedExpression so that it only emits the selector expression, and returns the trailing lambda to the caller so that it can be emitted at a shallower syntactic block. Then we can call emitQualifiedExpression in processLambdaOrScopingFunction.

stevietrouble avatar Apr 08 '21 18:04 stevietrouble

Agreed, and I like the "expected behavior". The "scoping function formatting" was a bit of a stopgap, because I didn't know how things should look like if the "first line" (e.g., val fn = scope.launch {) doesn't fit in one line.

Seems that we should have

val fn =
    scope.launch {
      doThing()
      doAnother()  
    }

in that case, but GJF doesn't support this (https://github.com/google/google-java-format/issues/556)

What did you have in mind?

cgrushko avatar Apr 16 '21 20:04 cgrushko

Behavior of v0.47

val fn = launch {
    doThing()
    doAnother()
}

val fn =
    scope.launch {
        doThing()
        doAnother()
    }

This is not something we plan to work anytime in the future here, but we'd welcome PRs as long as they don't regress other areas

hick209 avatar Jun 05 '24 18:06 hick209