Skip to content

Commit 321f3d3

Browse files
authored
Merge pull request #25943 from nkcsgexi/indent-param-5.1
[5.1] SourceKit/Indentation: avoid indenting closing paren of function-like decls if it appears in a new line
2 parents acb3517 + 4d27f67 commit 321f3d3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/IDE/Formatting.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,20 @@ class FormatContext {
355355
}
356356
}
357357

358+
// func foo(a: Int,
359+
// b: Int
360+
// ) {} <- Avoid adding indentation here
361+
SourceLoc SignatureEnd;
362+
if (auto *AFD = dyn_cast_or_null<AbstractFunctionDecl>(Cursor->getAsDecl())) {
363+
SignatureEnd = AFD->getSignatureSourceRange().End;
364+
} else if (auto *SD = dyn_cast_or_null<SubscriptDecl>(Cursor->getAsDecl())) {
365+
SignatureEnd = SD->getSignatureSourceRange().End;
366+
}
367+
if (SignatureEnd.isValid() && TInfo &&
368+
TInfo.StartOfLineTarget->getLoc() == SignatureEnd) {
369+
return false;
370+
}
371+
358372
// If we're at the beginning of a brace on a separate line in the context
359373
// of anything other than BraceStmt, don't add an indent.
360374
// For example:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public static func buildBlock(
2+
_ shapes: PathShape...
3+
) -> PathShape {
4+
return nil
5+
}
6+
7+
class C {
8+
init(a: Int,
9+
b: Int
10+
) {}
11+
subscript(index1: Int,
12+
index2: Int
13+
) -> Int { get {} }
14+
}
15+
16+
// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >%t.response
17+
// RUN: %sourcekitd-test -req=format -line=10 -length=1 %s >>%t.response
18+
// RUN: %sourcekitd-test -req=format -line=13 -length=1 %s >>%t.response
19+
// RUN: %FileCheck --strict-whitespace %s <%t.response
20+
21+
// CHECK: key.sourcetext: ") -> PathShape {"
22+
// CHECK: key.sourcetext: " ) {}"
23+
// CHECK: key.sourcetext: " ) -> Int { get {} }"

0 commit comments

Comments
 (0)