Skip to content

Commit 4b379db

Browse files
authored
Merge pull request swiftlang#18231 from keith/ks/indent-closing-square
IDE: Fix formatting of closing square brackets
2 parents d38e714 + 2d91af2 commit 4b379db

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/IDE/Formatting.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,9 @@ class CodeFormatter {
813813
StringRef Text, TokenInfo ToInfo) {
814814

815815
// If having sibling locs to align with, respect siblings.
816-
if (FC.HasSibling()) {
816+
auto isClosingSquare =
817+
ToInfo && ToInfo.StartOfLineTarget->getKind() == tok::r_square;
818+
if (!isClosingSquare && FC.HasSibling()) {
817819
StringRef Line = swift::ide::getTextForLine(LineIndex, Text, /*Trim*/true);
818820
StringBuilder Builder;
819821
FC.padToSiblingColumn(Builder, FmtOptions);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
struct Foo {
2+
let bar = [
3+
1,
4+
2,
5+
]
6+
7+
func baz() {
8+
let qux = [
9+
"a": 1,
10+
"b": 2,
11+
]
12+
13+
let quxx = [
14+
"a": 1,
15+
"b": 2
16+
]
17+
}
18+
}
19+
20+
// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >%t.response
21+
// RUN: %sourcekitd-test -req=format -line=11 -length=1 %s >>%t.response
22+
// RUN: %sourcekitd-test -req=format -line=16 -length=1 %s >>%t.response
23+
// RUN: %FileCheck --strict-whitespace %s <%t.response
24+
// CHECK: key.sourcetext: " ]"
25+
// CHECK: key.sourcetext: " ]"
26+
// CHECK: key.sourcetext: " ]"

0 commit comments

Comments
 (0)