Skip to content

Commit 4d09c18

Browse files
authored
Merge pull request #4750 from nkcsgexi/indentation-3.0
[SourceKit] Avoid adding indentation at the end of a CaptureListExpr.
2 parents b796108 + 4cb8c46 commit 4d09c18

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/IDE/Formatting.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ class FormatContext {
366366
Expr *AtExprEnd = End.getAsExpr();
367367
if (AtExprEnd && (isa<ClosureExpr>(AtExprEnd) ||
368368
isa<ParenExpr>(AtExprEnd) ||
369-
isa<TupleExpr>(AtExprEnd))) {
369+
isa<TupleExpr>(AtExprEnd) ||
370+
isa<CaptureListExpr>(AtExprEnd))) {
370371

371372
if (auto *Paren = dyn_cast_or_null<ParenExpr>(Cursor->getAsExpr())) {
372373
auto *SubExpr = Paren->getSubExpr();

test/SourceKit/CodeFormat/indent-closure.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ func foo4() {
3232
}()
3333
}
3434

35+
func foo5(input: Int, block: (Int) -> ()) -> Int {
36+
return 0
37+
}
38+
39+
func foo6() {
40+
_ = foo5(input: 0, block: { [unowned self] blockInput in
41+
foo4()
42+
})
43+
}
44+
3545
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >%t.response
3646
// RUN: %sourcekitd-test -req=format -line=4 -length=1 %s >>%t.response
3747
// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >>%t.response
@@ -46,6 +56,7 @@ func foo4() {
4656
// RUN: %sourcekitd-test -req=format -line=30 -length=1 %s >>%t.response
4757
// RUN: %sourcekitd-test -req=format -line=31 -length=1 %s >>%t.response
4858
// RUN: %sourcekitd-test -req=format -line=32 -length=1 %s >>%t.response
59+
// RUN: %sourcekitd-test -req=format -line=42 -length=1 %s >>%t.response
4960
// RUN: %FileCheck --strict-whitespace %s <%t.response
5061

5162
// CHECK: key.sourcetext: " var abc = 1"
@@ -68,3 +79,5 @@ func foo4() {
6879
// CHECK: key.sourcetext: " let test = {"
6980
// CHECK: key.sourcetext: " return 0"
7081
// CHECK: key.sourcetext: " }()"
82+
83+
// CHECK: key.sourcetext: " })"

0 commit comments

Comments
 (0)