Skip to content

Commit 552134a

Browse files
authored
Merge pull request #32276 from rintaro/ide-conformingmethods-disablelabeledtrailingclosure-rdar63781922
[SourceKit] Disable labeled trailing closure completion support except code completion
2 parents e5a5ab1 + 67e88f4 commit 552134a

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
@@ -3213,6 +3213,13 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
32133213
if (!Tok.is(tok::code_complete))
32143214
break;
32153215

3216+
// If the current completion mode doesn't support trailing closure
3217+
// completion, leave the token here and let "postfix completion" to
3218+
// handle it.
3219+
if (CodeCompletion &&
3220+
!CodeCompletion->canPerformCompleteLabeledTrailingClosure())
3221+
break;
3222+
32163223
// foo() {} <token>
32173224
auto CCExpr = new (Context) CodeCompletionExpr(Tok.getLoc());
32183225
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)