Skip to content

Commit d102209

Browse files
committed
[IDE/format] Disable the sibling check for dictionary/array literal elements.
This ends up creating too much indentation in some common cases. This effectively get us back to indentation behavior of Swift 2.2. Addresses rdar://26290643.
1 parent 39e7c77 commit d102209

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/IDE/Formatting.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,26 @@ class FormatWalker : public SourceEntityWalker {
536536

537537
// Array/Dictionary elements are siblings to align with each other.
538538
if (auto AE = dyn_cast_or_null<CollectionExpr>(Node.dyn_cast<Expr *>())) {
539-
SourceLoc LBracketLoc = AE->getLBracketLoc();
539+
// The following check ends-up creating too much indentation,
540+
// for example:
541+
// let something = [
542+
// a
543+
// ]
544+
//
545+
// Disabling the check gets us back to the Swift2.2 behavior:
546+
// let something = [
547+
// a
548+
// ]
549+
//
550+
// FIXME: We are going to revisit the behavior and the indentation we
551+
// want for dictionary/array literals.
552+
//
553+
/* SourceLoc LBracketLoc = AE->getLBracketLoc();
540554
if (isTargetImmediateAfter(LBracketLoc) &&
541555
!sameLineWithTarget(LBracketLoc)) {
542556
FoundSibling = LBracketLoc;
543557
NeedExtraIndentation = true;
544-
}
558+
}*/
545559
for (unsigned I = 0, N = AE->getNumElements(); I < N; I ++) {
546560
addPair(AE->getElement(I)->getEndLoc(),
547561
FindAlignLoc(AE->getElement(I)->getStartLoc()), tok::comma);

test/SourceKit/CodeFormat/indent-basic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ x
4040
// CHECK: key.sourcetext: " "
4141
// CHECK: key.sourcetext: "}"
4242
// "foo(a: ["
43-
// CHECK: key.sourcetext: " 3: 3"
43+
// CHECK: key.sourcetext: " 3: 3"
4444
// CHECK: key.sourcetext: " x"

0 commit comments

Comments
 (0)