Skip to content

Commit 891494e

Browse files
authored
Merge pull request #25355 from nkcsgexi/indent-subs-end
SourceKit/Indentation: avoid indenting the end of subscript expressions in call chain.
2 parents fd39f2f + 2b19064 commit 891494e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/IDE/Formatting.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ class FormatContext {
489489
// }.map { <--- No indentation here.
490490
// ...
491491
// }
492-
if (AtExprEnd && AtCursorExpr && isa<CallExpr>(AtExprEnd)) {
492+
if (AtExprEnd && AtCursorExpr &&
493+
(isa<CallExpr>(AtExprEnd) || isa<SubscriptExpr>(AtExprEnd))) {
493494
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(AtCursorExpr)) {
494495
if (auto *Base = UDE->getBase()) {
495496
if (exprEndAtLine(Base, Line))

test/SourceKit/CodeFormat/indent-closure.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func foo9(input: [Int]){
6262
}
6363
}
6464

65+
func foo10() {
66+
Something() [
67+
].whatever
68+
}
69+
6570
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >%t.response
6671
// RUN: %sourcekitd-test -req=format -line=4 -length=1 %s >>%t.response
6772
// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >>%t.response
@@ -89,6 +94,9 @@ func foo9(input: [Int]){
8994
// RUN: %sourcekitd-test -req=format -line=62 -length=1 %s >>%t.response
9095
// RUN: %sourcekitd-test -req=format -line=63 -length=1 %s >>%t.response
9196

97+
// RUN: %sourcekitd-test -req=format -line=66 -length=1 %s >>%t.response
98+
// RUN: %sourcekitd-test -req=format -line=67 -length=1 %s >>%t.response
99+
92100
// RUN: %FileCheck --strict-whitespace %s <%t.response
93101

94102
// CHECK: key.sourcetext: " var abc = 1"
@@ -125,3 +133,6 @@ func foo9(input: [Int]){
125133
// CHECK: key.sourcetext: " return ele + 1"
126134
// CHECK: key.sourcetext: " }"
127135
// CHECK: key.sourcetext: "}"
136+
137+
// CHECK: key.sourcetext: " Something() ["
138+
// CHECK: key.sourcetext: " ].whatever"

0 commit comments

Comments
 (0)