Skip to content

Commit b520708

Browse files
committed
Sourcekit/Indentation: avoid indenting the end of array/dictionary literals if they appear at the argument end
rdar://40093469
1 parent 6da1be5 commit b520708

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: lib/IDE/Formatting.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ class FormatContext {
456456
auto AtCursorExpr = Cursor->getAsExpr();
457457
if (AtExprEnd && AtCursorExpr && (isa<ParenExpr>(AtCursorExpr) ||
458458
isa<TupleExpr>(AtCursorExpr))) {
459-
if (isa<CallExpr>(AtExprEnd)) {
459+
if (isa<CallExpr>(AtExprEnd) ||
460+
isa<ArrayExpr>(AtExprEnd) ||
461+
isa<DictionaryExpr>(AtExprEnd)) {
460462
if (exprEndAtLine(AtExprEnd, Line) &&
461463
exprEndAtLine(AtCursorExpr, Line)) {
462464
return false;

Diff for: test/SourceKit/CodeFormat/indent-closing-array.swift

+14
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,26 @@ struct Foo {
1515
"b": 2
1616
]
1717
}
18+
func foo() {
19+
print([
20+
"Hello, World!",
21+
"Hello, World!",
22+
])
23+
print([
24+
"Hello, World!": 1,
25+
"Hello, World!": 2,
26+
])
27+
}
1828
}
1929

2030
// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >%t.response
2131
// RUN: %sourcekitd-test -req=format -line=11 -length=1 %s >>%t.response
2232
// RUN: %sourcekitd-test -req=format -line=16 -length=1 %s >>%t.response
33+
// RUN: %sourcekitd-test -req=format -line=22 -length=1 %s >>%t.response
34+
// RUN: %sourcekitd-test -req=format -line=26 -length=1 %s >>%t.response
2335
// RUN: %FileCheck --strict-whitespace %s <%t.response
2436
// CHECK: key.sourcetext: " ]"
2537
// CHECK: key.sourcetext: " ]"
2638
// CHECK: key.sourcetext: " ]"
39+
// CHECK: key.sourcetext: " ])"
40+
// CHECK: key.sourcetext: " ])"

0 commit comments

Comments
 (0)