Skip to content

Commit a65ffab

Browse files
committed
[SourceKit][CodeFormat] When indent to siblings, respect tuple elements' names. rdar://24251847
1 parent 69ba5bc commit a65ffab

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
func foo(foo: Int, bar: Int, baz: Int, buzz: Int) -> Int {
2+
return foo + bar + baz + buzz
3+
}
4+
5+
foo(0,
6+
bar: 1,
7+
baz: 2,
8+
buzz: 3)
9+
10+
// RUN: %sourcekitd-test -req=format -line=6 -length=1 %s >%t.response
11+
// RUN: %sourcekitd-test -req=format -line=7 -length=1 %s >>%t.response
12+
// RUN: %sourcekitd-test -req=format -line=8 -length=1 %s >>%t.response
13+
// RUN: %sourcekitd-test -req=format -line=9 -length=1 %s >>%t.response
14+
// RUN: FileCheck --strict-whitespace %s <%t.response
15+
16+
// "foo(0,"
17+
// CHECK: key.sourcetext: " bar: 1,"
18+
19+
// " bar: 1,"
20+
// CHECK: key.sourcetext: " baz: 2,"
21+
22+
// " baz: 2,"
23+
// CHECK: key.sourcetext: " buzz: 3)"

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,8 +1894,11 @@ class FormatWalker: public ide::SourceEntityWalker {
18941894
// Trailing closures are not considered siblings to other args.
18951895
unsigned EndAdjust = TE->hasTrailingClosure() ? 1 : 0;
18961896
for (unsigned I = 0, N = TE->getNumElements() - EndAdjust; I < N; I ++) {
1897-
addPair(TE->getElement(I)->getEndLoc(),
1898-
FindAlignLoc(TE->getElement(I)->getStartLoc()), tok::comma);
1897+
auto EleStart = TE->getElementNameLoc(I);
1898+
if (EleStart.isInvalid()) {
1899+
EleStart = TE->getElement(I)->getStartLoc();
1900+
}
1901+
addPair(TE->getElement(I)->getEndLoc(), EleStart, tok::comma);
18991902
}
19001903
}
19011904

0 commit comments

Comments
 (0)