Skip to content

Commit 991cc3f

Browse files
authored
Merge pull request #32315 from rintaro/5.3-ide-conformingmethods-disablelabeledtrailingclosure-rdar63781922
[5.3][SourceKit] Disable labeled trailing closure support except code completion
2 parents eaa3e34 + 8f1415c commit 991cc3f

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ class CodeCompletionCallbacks {
198198

199199
virtual void completeCallArg(CodeCompletionExpr *E, bool isFirst) {};
200200

201+
virtual bool canPerformCompleteLabeledTrailingClosure() const {
202+
return false;
203+
}
204+
201205
virtual void completeLabeledTrailingClosure(CodeCompletionExpr *E,
202206
bool isAtStartOfLine) {};
203207

lib/IDE/CodeCompletion.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,10 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
16871687
void completeLabeledTrailingClosure(CodeCompletionExpr *E,
16881688
bool isAtStartOfLine) override;
16891689

1690+
bool canPerformCompleteLabeledTrailingClosure() const override {
1691+
return true;
1692+
}
1693+
16901694
void completeReturnStmt(CodeCompletionExpr *E) override;
16911695
void completeYieldStmt(CodeCompletionExpr *E,
16921696
Optional<unsigned> yieldIndex) override;

lib/Parse/ParseExpr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,6 +3216,13 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
32163216
if (!Tok.is(tok::code_complete))
32173217
break;
32183218

3219+
// If the current completion mode doesn't support trailing closure
3220+
// completion, leave the token here and let "postfix completion" to
3221+
// handle it.
3222+
if (CodeCompletion &&
3223+
!CodeCompletion->canPerformCompleteLabeledTrailingClosure())
3224+
break;
3225+
32193226
// foo() {} <token>
32203227
auto CCExpr = new (Context) CodeCompletionExpr(Tok.getLoc());
32213228
if (CodeCompletion)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-ide-test -conforming-methods -source-filename %s -code-completion-token=AFTER_TRAILINGCLOSURE -module-name MyModule -conforming-methods-expected-types 's:8MyModule7TargetPP' | %FileCheck %s -check-prefix=AFTER_TRAILINGCLOSURE
2+
3+
public protocol TargetP {}
4+
struct ConcreteP: TargetP {}
5+
6+
public struct MyStruct {
7+
init(arg1: Int = 0, fn: () -> Int) {}
8+
9+
public func returnSomeP -> some TargetP { ConcreteP() }
10+
public func returnConcreteP -> ConcreteP { ConcreteP() }
11+
public func reutrnInt -> Int { 1 }
12+
}
13+
14+
func test() {
15+
MyStruct {
16+
1
17+
} #^AFTER_TRAILINGCLOSURE^#
18+
}
19+
20+
//AFTER_TRAILINGCLOSURE: -----BEGIN CONFORMING METHOD LIST-----
21+
//AFTER_TRAILINGCLOSURE-NEXT: - TypeName: MyStruct
22+
//AFTER_TRAILINGCLOSURE-NEXT: - Members:
23+
//AFTER_TRAILINGCLOSURE-NEXT: - Name: returnSomeP()
24+
//AFTER_TRAILINGCLOSURE-NEXT: TypeName: some TargetP
25+
//AFTER_TRAILINGCLOSURE-NEXT: - Name: returnConcreteP()
26+
//AFTER_TRAILINGCLOSURE-NEXT: TypeName: ConcreteP
27+
//AFTER_TRAILINGCLOSURE-NEXT: -----END CONFORMING METHOD LIST-----

0 commit comments

Comments
 (0)