Skip to content

Commit 36ce8ff

Browse files
authored
Merge pull request #25155 from nkcsgexi/indent-array-call
Sourcekit/Indentation: avoid indenting the end of array/dictionary literals if they appear at the argument end
2 parents e9c4df0 + b520708 commit 36ce8ff

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IDE/Formatting.cpp

Lines changed: 3 additions & 1 deletion
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;

test/SourceKit/CodeFormat/indent-closing-array.swift

Lines changed: 14 additions & 0 deletions
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)