@@ -2460,7 +2460,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2460
2460
// speculative parse to validate it and look for 'in'.
2461
2461
if (Tok.isAny (
2462
2462
tok::at_sign, tok::l_paren, tok::l_square, tok::identifier,
2463
- tok::kw__)) {
2463
+ tok::kw__, tok::code_complete )) {
2464
2464
BacktrackingScope backtrack (*this );
2465
2465
2466
2466
// Consume attributes.
@@ -2496,11 +2496,11 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2496
2496
}
2497
2497
2498
2498
// Okay, we have a closure signature.
2499
- } else if (Tok.isIdentifierOrUnderscore ()) {
2499
+ } else if (Tok.isIdentifierOrUnderscore () || Tok. is (tok::code_complete) ) {
2500
2500
// Parse identifier (',' identifier)*
2501
2501
consumeToken ();
2502
2502
while (consumeIf (tok::comma)) {
2503
- if (Tok.isIdentifierOrUnderscore ()) {
2503
+ if (Tok.isIdentifierOrUnderscore () || Tok. is (tok::code_complete) ) {
2504
2504
consumeToken ();
2505
2505
continue ;
2506
2506
}
@@ -2575,7 +2575,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2575
2575
if (!consumeIf (tok::r_paren, ownershipLocEnd))
2576
2576
diagnose (Tok, diag::attr_unowned_expected_rparen);
2577
2577
}
2578
- } else if (Tok.isAny (tok::identifier, tok::kw_self) &&
2578
+ } else if (Tok.isAny (tok::identifier, tok::kw_self, tok::code_complete ) &&
2579
2579
peekToken ().isAny (tok::equal, tok::comma, tok::r_square)) {
2580
2580
// "x = 42", "x," and "x]" are all strong captures of x.
2581
2581
} else {
@@ -2584,7 +2584,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2584
2584
continue ;
2585
2585
}
2586
2586
2587
- if (Tok.isNot (tok::identifier, tok::kw_self)) {
2587
+ if (Tok.isNot (tok::identifier, tok::kw_self, tok::code_complete )) {
2588
2588
diagnose (Tok, diag::expected_capture_specifier_name);
2589
2589
skipUntil (tok::comma, tok::r_square);
2590
2590
continue ;
@@ -2602,10 +2602,20 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2602
2602
if (peekToken ().isNot (tok::equal)) {
2603
2603
// If this is the simple case, then the identifier is both the name and
2604
2604
// the expression to capture.
2605
- name = Context.getIdentifier (Tok.getText ());
2606
- auto initializerResult = parseExprIdentifier ();
2607
- status |= initializerResult;
2608
- initializer = initializerResult.get ();
2605
+ if (!Tok.is (tok::code_complete)) {
2606
+ name = Context.getIdentifier (Tok.getText ());
2607
+ auto initializerResult = parseExprIdentifier ();
2608
+ status |= initializerResult;
2609
+ initializer = initializerResult.get ();
2610
+ } else {
2611
+ auto CCE = new (Context) CodeCompletionExpr (Tok.getLoc ());
2612
+ if (CodeCompletion)
2613
+ CodeCompletion->completePostfixExprBeginning (CCE);
2614
+ name = Identifier ();
2615
+ initializer = CCE;
2616
+ consumeToken ();
2617
+ status.setHasCodeCompletion ();
2618
+ }
2609
2619
2610
2620
// It is a common error to try to capture a nested field instead of just
2611
2621
// a local name, reject it with a specific error message.
@@ -2617,7 +2627,13 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2617
2627
2618
2628
} else {
2619
2629
// Otherwise, the name is a new declaration.
2620
- consumeIdentifier (name, /* diagnoseDollarPrefix=*/ true );
2630
+ if (!Tok.is (tok::code_complete)) {
2631
+ consumeIdentifier (name, /* diagnoseDollarPrefix=*/ true );
2632
+ } else {
2633
+ // Ignore completion token because it's a new declaration.
2634
+ name = Identifier ();
2635
+ consumeToken (tok::code_complete);
2636
+ }
2621
2637
equalLoc = consumeToken (tok::equal);
2622
2638
2623
2639
auto ExprResult = parseExpr (diag::expected_init_capture_specifier);
@@ -2687,7 +2703,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2687
2703
bool HasNext;
2688
2704
do {
2689
2705
SyntaxParsingContext ClParamCtx (SyntaxContext, SyntaxKind::ClosureParam);
2690
- if (Tok.isNot (tok::identifier, tok::kw__)) {
2706
+ if (Tok.isNot (tok::identifier, tok::kw__, tok::code_complete )) {
2691
2707
diagnose (Tok, diag::expected_closure_parameter_name);
2692
2708
status.setIsParseError ();
2693
2709
break ;
@@ -2698,7 +2714,10 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2698
2714
if (Tok.is (tok::identifier)) {
2699
2715
nameLoc = consumeIdentifier (name, /* diagnoseDollarPrefix=*/ false );
2700
2716
} else {
2701
- nameLoc = consumeToken (tok::kw__);
2717
+ assert (Tok.isAny (tok::kw__ , tok::code_complete));
2718
+ // Consume and ignore code_completion token so that completion don't
2719
+ // suggest anything for the parameter name declaration.
2720
+ nameLoc = consumeToken ();
2702
2721
}
2703
2722
auto var = new (Context)
2704
2723
ParamDecl (SourceLoc (), SourceLoc (),
0 commit comments