File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
test/SourceKit/CodeFormat Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -355,6 +355,20 @@ class FormatContext {
355
355
}
356
356
}
357
357
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
+
358
372
// If we're at the beginning of a brace on a separate line in the context
359
373
// of anything other than BraceStmt, don't add an indent.
360
374
// For example:
Original file line number Diff line number Diff line change
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 {} }"
You can’t perform that action at this time.
0 commit comments