Skip to content

[CodeCompletion] Migrate AccessorBeginning to solver-based #41922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,20 +1397,31 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion(bool MaybeFuncBody) {
CurDeclContext, CompletionContext, Consumer);
return true;
}
case CompletionKind::StmtOrExpr:
case CompletionKind::AccessorBeginning:
case CompletionKind::ForEachSequence:
case CompletionKind::PostfixExprBeginning: {
assert(CodeCompleteTokenExpr);
case CompletionKind::PostfixExprBeginning:
case CompletionKind::StmtOrExpr: {
assert(CurDeclContext);

ExprTypeCheckCompletionCallback Lookup(CodeCompleteTokenExpr,
CurDeclContext);
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
Context.CompletionCallback, &Lookup);
typeCheckContextAt(CurDeclContext, CompletionLoc);

if (!Lookup.gotCallback()) {
Lookup.fallbackTypeCheck(CurDeclContext);
if (CodeCompleteTokenExpr) {
// 'CodeCompletionTokenExpr == nullptr' happens when completing e.g.
// var x: Int {
// get { ... }
// #^COMPLETE^#
// }
// In this case we don't want to provide any expression results. We still
// need to have a TypeCheckCompletionCallback so we can call
// deliverResults on it to deliver the keyword results from the completion
// context's result sink to the consumer.
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
Context.CompletionCallback, &Lookup);
typeCheckContextAt(CurDeclContext, CompletionLoc);

if (!Lookup.gotCallback()) {
Lookup.fallbackTypeCheck(CurDeclContext);
}
}

addKeywords(CompletionContext.getResultSink(), MaybeFuncBody);
Expand Down Expand Up @@ -1564,6 +1575,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
case CompletionKind::ForEachSequence:
case CompletionKind::PostfixExprBeginning:
case CompletionKind::AfterPoundExpr:
case CompletionKind::AccessorBeginning:
llvm_unreachable("should be already handled");
return;

Expand Down Expand Up @@ -1680,16 +1692,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
break;
}

case CompletionKind::AccessorBeginning: {
if (isa<AccessorDecl>(ParsedDecl)) {
ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr);
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
ContextInfo.isImplicitSingleExpressionReturn());
DoPostfixExprBeginning();
}
break;
}

case CompletionKind::AttributeBegin: {
Lookup.getAttributeDeclCompletions(IsInSil, AttTargetDK);

Expand Down
8 changes: 6 additions & 2 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7377,12 +7377,16 @@ Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
SourceLoc LBraceLoc, RBraceLoc;
LBraceLoc = consumeToken(tok::l_brace);
auto *CCE = new (Context) CodeCompletionExpr(Tok.getLoc());
auto *Return =
new (Context) ReturnStmt(SourceLoc(), CCE, /*implicit=*/true);
CodeCompletion->setParsedDecl(accessor);
CodeCompletion->completeAccessorBeginning(CCE);
RBraceLoc = Tok.getLoc();
consumeToken(tok::code_complete);
auto *BS = BraceStmt::create(Context, LBraceLoc, ASTNode(CCE), RBraceLoc,
/*implicit*/ true);
auto *BS =
BraceStmt::create(Context, LBraceLoc, ASTNode(Return), RBraceLoc,
/*implicit*/ true);
AFD->setHasSingleExpressionBody();
AFD->setBodyParsed(BS);
return {BS, Fingerprint::ZERO()};
}
Expand Down