@@ -5457,35 +5457,18 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags,
5457
5457
AccessorCtx.reset ();
5458
5458
5459
5459
if (Tok.is (tok::code_complete)) {
5460
- if (CodeCompletion) {
5461
- CodeCompletionExpr *CCE = nullptr ;
5462
- if (IsFirstAccessor && !parsingLimitedSyntax) {
5463
- // If CC token is the first token after '{', it might be implicit
5464
- // getter. Set up dummy accessor as the decl context to populate
5465
- // 'self' decl.
5466
-
5467
- // FIXME: if there is already code inside the body, we should fall
5468
- // through to parseImplicitGetter and handle the completion there so
5469
- // that we can differentiate a single-expression body from the first
5470
- // expression in a multi-statement body.
5471
- auto getter = createAccessorFunc (
5472
- accessors.LBLoc , /* ValueNamePattern*/ nullptr , GenericParams,
5473
- Indices, StaticLoc, Flags, AccessorKind::Get,
5474
- storage, this , /* AccessorKeywordLoc*/ SourceLoc ());
5475
- CCE = new (Context) CodeCompletionExpr (Tok.getLoc ());
5476
- getter->setBodyParsed (BraceStmt::create (Context, Tok.getLoc (),
5477
- ASTNode (CCE), Tok.getLoc (),
5478
- /* implicit*/ true ));
5479
- accessors.add (getter);
5480
- CodeCompletion->setParsedDecl (getter);
5481
- } else {
5460
+ // Handle code completion here only if it's not the first accessor.
5461
+ // If it's the first accessor, it's handled in function body parsing
5462
+ // because it might be an implicit getter.
5463
+ if (!IsFirstAccessor || parsingLimitedSyntax) {
5464
+ if (CodeCompletion) {
5482
5465
CodeCompletion->setParsedDecl (storage);
5466
+ CodeCompletion->completeAccessorBeginning (nullptr );
5483
5467
}
5484
- CodeCompletion->completeAccessorBeginning (CCE);
5468
+ consumeToken (tok::code_complete);
5469
+ accessorHasCodeCompletion = true ;
5470
+ break ;
5485
5471
}
5486
- consumeToken (tok::code_complete);
5487
- accessorHasCodeCompletion = true ;
5488
- break ;
5489
5472
}
5490
5473
5491
5474
// parsingLimitedSyntax mode cannot have a body.
@@ -6348,6 +6331,23 @@ Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
6348
6331
if (Context.Stats )
6349
6332
Context.Stats ->getFrontendCounters ().NumFunctionsParsed ++;
6350
6333
6334
+ // In implicit getter, if a CC token is the first token after '{', it might
6335
+ // be a start of an accessor block. Perform special completion for that.
6336
+ if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
6337
+ if (peekToken ().is (tok::code_complete) && accessor->isImplicitGetter ()) {
6338
+ SourceLoc LBraceLoc, RBraceLoc;
6339
+ LBraceLoc = consumeToken (tok::l_brace);
6340
+ auto *CCE = new (Context) CodeCompletionExpr (Tok.getLoc ());
6341
+ CodeCompletion->setParsedDecl (accessor);
6342
+ CodeCompletion->completeAccessorBeginning (CCE);
6343
+ RBraceLoc = Tok.getLoc ();
6344
+ consumeToken (tok::code_complete);
6345
+ return makeParserCodeCompletionResult (
6346
+ BraceStmt::create (Context, LBraceLoc, ASTNode (CCE), RBraceLoc,
6347
+ /* implicit*/ true ));
6348
+ }
6349
+ }
6350
+
6351
6351
return parseBraceItemList (diag::invalid_diagnostic);
6352
6352
}
6353
6353
0 commit comments