aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/java/com/facebook
diff options
context:
space:
mode:
authorOmer Strulovich <ostrulovich@fb.com>2022-05-06 11:06:15 -0700
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2022-05-06 11:06:15 -0700
commit63eef564b24955a7429c930ab1b78458e2f6c8a1 (patch)
treeabfa2729f0bbb6be82d0f38a33b54cee1a74359b /core/src/main/java/com/facebook
parentb7ff8ba9f6bd5f1c65c4b7a508d186ca5ecb6180 (diff)
downloadktfmt-63eef564b24955a7429c930ab1b78458e2f6c8a1.tar.gz
Disabling grouping of fields after the first group in qualified expressions
Summary: This addresses the request to not try and pack fields in a qualified expression after the first grouping. Reviewed By: hick209 Differential Revision: D36202571 fbshipit-source-id: 4e342ce1917a9a7a3d3fcdb229b613752d02b941
Diffstat (limited to 'core/src/main/java/com/facebook')
-rw-r--r--core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt10
1 files changed, 6 insertions, 4 deletions
diff --git a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt
index e59a1ee..b84a857 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt
@@ -622,15 +622,17 @@ class KotlinInputAstVisitor(
(receiverExpression as? KtQualifiedExpression)?.selectorExpression
?: receiverExpression
val current = checkNotNull(part.selectorExpression)
- if (shouldGroupPartWithPrevious(parts, part, index, previous, current)) {
+ if (lastIndexToOpen == 0 &&
+ shouldGroupPartWithPrevious(parts, part, index, previous, current)) {
// this and the previous items should be grouped for better style
- // we add another group to open in the current index we have been using
- groupingInfos[lastIndexToOpen].groupOpenCount++
+ // we add another group to open in index 0
+ groupingInfos[0].groupOpenCount++
// we don't always close a group when emitting this node, so we need this flag to
// mark if we need to close a group
groupingInfos[index].shouldCloseGroup = true
} else {
- // use this index in to open future groups
+ // use this index in to open future groups for arrays and postfixes
+ // we will also stop grouping field access to the beginning of the expression
lastIndexToOpen = index
}
}