Skip to content

Commit 07efec4

Browse files
authored
Merge pull request #42184 from ahoppen/pr/migrage-accessorbeginning-solver-based
[5.7][CodeCompletion] Migrate AccessorBeginning to solver-based
2 parents a7f0fff + 8cd5bbd commit 07efec4

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,20 +1404,31 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion(bool MaybeFuncBody) {
14041404
CurDeclContext, CompletionContext, Consumer);
14051405
return true;
14061406
}
1407-
case CompletionKind::StmtOrExpr:
1407+
case CompletionKind::AccessorBeginning:
14081408
case CompletionKind::ForEachSequence:
1409-
case CompletionKind::PostfixExprBeginning: {
1410-
assert(CodeCompleteTokenExpr);
1409+
case CompletionKind::PostfixExprBeginning:
1410+
case CompletionKind::StmtOrExpr: {
14111411
assert(CurDeclContext);
14121412

14131413
ExprTypeCheckCompletionCallback Lookup(CodeCompleteTokenExpr,
14141414
CurDeclContext);
1415-
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
1416-
Context.CompletionCallback, &Lookup);
1417-
typeCheckContextAt(CurDeclContext, CompletionLoc);
1418-
1419-
if (!Lookup.gotCallback()) {
1420-
Lookup.fallbackTypeCheck(CurDeclContext);
1415+
if (CodeCompleteTokenExpr) {
1416+
// 'CodeCompletionTokenExpr == nullptr' happens when completing e.g.
1417+
// var x: Int {
1418+
// get { ... }
1419+
// #^COMPLETE^#
1420+
// }
1421+
// In this case we don't want to provide any expression results. We still
1422+
// need to have a TypeCheckCompletionCallback so we can call
1423+
// deliverResults on it to deliver the keyword results from the completion
1424+
// context's result sink to the consumer.
1425+
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
1426+
Context.CompletionCallback, &Lookup);
1427+
typeCheckContextAt(CurDeclContext, CompletionLoc);
1428+
1429+
if (!Lookup.gotCallback()) {
1430+
Lookup.fallbackTypeCheck(CurDeclContext);
1431+
}
14211432
}
14221433

14231434
addKeywords(CompletionContext.getResultSink(), MaybeFuncBody);
@@ -1571,6 +1582,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
15711582
case CompletionKind::ForEachSequence:
15721583
case CompletionKind::PostfixExprBeginning:
15731584
case CompletionKind::AfterPoundExpr:
1585+
case CompletionKind::AccessorBeginning:
15741586
llvm_unreachable("should be already handled");
15751587
return;
15761588

@@ -1687,16 +1699,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
16871699
break;
16881700
}
16891701

1690-
case CompletionKind::AccessorBeginning: {
1691-
if (isa<AccessorDecl>(ParsedDecl)) {
1692-
ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr);
1693-
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
1694-
ContextInfo.isImplicitSingleExpressionReturn());
1695-
DoPostfixExprBeginning();
1696-
}
1697-
break;
1698-
}
1699-
17001702
case CompletionKind::AttributeBegin: {
17011703
Lookup.getAttributeDeclCompletions(IsInSil, AttTargetDK);
17021704

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7377,12 +7377,16 @@ Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
73777377
SourceLoc LBraceLoc, RBraceLoc;
73787378
LBraceLoc = consumeToken(tok::l_brace);
73797379
auto *CCE = new (Context) CodeCompletionExpr(Tok.getLoc());
7380+
auto *Return =
7381+
new (Context) ReturnStmt(SourceLoc(), CCE, /*implicit=*/true);
73807382
CodeCompletion->setParsedDecl(accessor);
73817383
CodeCompletion->completeAccessorBeginning(CCE);
73827384
RBraceLoc = Tok.getLoc();
73837385
consumeToken(tok::code_complete);
7384-
auto *BS = BraceStmt::create(Context, LBraceLoc, ASTNode(CCE), RBraceLoc,
7385-
/*implicit*/ true);
7386+
auto *BS =
7387+
BraceStmt::create(Context, LBraceLoc, ASTNode(Return), RBraceLoc,
7388+
/*implicit*/ true);
7389+
AFD->setHasSingleExpressionBody();
73867390
AFD->setBodyParsed(BS);
73877391
return {BS, Fingerprint::ZERO()};
73887392
}

0 commit comments

Comments
 (0)