@@ -1397,20 +1397,31 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion(bool MaybeFuncBody) {
1397
1397
CurDeclContext, CompletionContext, Consumer);
1398
1398
return true ;
1399
1399
}
1400
- case CompletionKind::StmtOrExpr :
1400
+ case CompletionKind::AccessorBeginning :
1401
1401
case CompletionKind::ForEachSequence:
1402
- case CompletionKind::PostfixExprBeginning: {
1403
- assert (CodeCompleteTokenExpr);
1402
+ case CompletionKind::PostfixExprBeginning:
1403
+ case CompletionKind::StmtOrExpr: {
1404
1404
assert (CurDeclContext);
1405
1405
1406
1406
ExprTypeCheckCompletionCallback Lookup (CodeCompleteTokenExpr,
1407
1407
CurDeclContext);
1408
- llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector (
1409
- Context.CompletionCallback , &Lookup);
1410
- typeCheckContextAt (CurDeclContext, CompletionLoc);
1411
-
1412
- if (!Lookup.gotCallback ()) {
1413
- Lookup.fallbackTypeCheck (CurDeclContext);
1408
+ if (CodeCompleteTokenExpr) {
1409
+ // 'CodeCompletionTokenExpr == nullptr' happens when completing e.g.
1410
+ // var x: Int {
1411
+ // get { ... }
1412
+ // #^COMPLETE^#
1413
+ // }
1414
+ // In this case we don't want to provide any expression results. We still
1415
+ // need to have a TypeCheckCompletionCallback so we can call
1416
+ // deliverResults on it to deliver the keyword results from the completion
1417
+ // context's result sink to the consumer.
1418
+ llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector (
1419
+ Context.CompletionCallback , &Lookup);
1420
+ typeCheckContextAt (CurDeclContext, CompletionLoc);
1421
+
1422
+ if (!Lookup.gotCallback ()) {
1423
+ Lookup.fallbackTypeCheck (CurDeclContext);
1424
+ }
1414
1425
}
1415
1426
1416
1427
addKeywords (CompletionContext.getResultSink (), MaybeFuncBody);
@@ -1564,6 +1575,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
1564
1575
case CompletionKind::ForEachSequence:
1565
1576
case CompletionKind::PostfixExprBeginning:
1566
1577
case CompletionKind::AfterPoundExpr:
1578
+ case CompletionKind::AccessorBeginning:
1567
1579
llvm_unreachable (" should be already handled" );
1568
1580
return ;
1569
1581
@@ -1680,16 +1692,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
1680
1692
break ;
1681
1693
}
1682
1694
1683
- case CompletionKind::AccessorBeginning: {
1684
- if (isa<AccessorDecl>(ParsedDecl)) {
1685
- ExprContextInfo ContextInfo (CurDeclContext, CodeCompleteTokenExpr);
1686
- Lookup.setExpectedTypes (ContextInfo.getPossibleTypes (),
1687
- ContextInfo.isImplicitSingleExpressionReturn ());
1688
- DoPostfixExprBeginning ();
1689
- }
1690
- break ;
1691
- }
1692
-
1693
1695
case CompletionKind::AttributeBegin: {
1694
1696
Lookup.getAttributeDeclCompletions (IsInSil, AttTargetDK);
1695
1697
0 commit comments