@@ -1404,20 +1404,31 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion(bool MaybeFuncBody) {
1404
1404
CurDeclContext, CompletionContext, Consumer);
1405
1405
return true ;
1406
1406
}
1407
- case CompletionKind::StmtOrExpr :
1407
+ case CompletionKind::AccessorBeginning :
1408
1408
case CompletionKind::ForEachSequence:
1409
- case CompletionKind::PostfixExprBeginning: {
1410
- assert (CodeCompleteTokenExpr);
1409
+ case CompletionKind::PostfixExprBeginning:
1410
+ case CompletionKind::StmtOrExpr: {
1411
1411
assert (CurDeclContext);
1412
1412
1413
1413
ExprTypeCheckCompletionCallback Lookup (CodeCompleteTokenExpr,
1414
1414
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
+ }
1421
1432
}
1422
1433
1423
1434
addKeywords (CompletionContext.getResultSink (), MaybeFuncBody);
@@ -1571,6 +1582,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
1571
1582
case CompletionKind::ForEachSequence:
1572
1583
case CompletionKind::PostfixExprBeginning:
1573
1584
case CompletionKind::AfterPoundExpr:
1585
+ case CompletionKind::AccessorBeginning:
1574
1586
llvm_unreachable (" should be already handled" );
1575
1587
return ;
1576
1588
@@ -1687,16 +1699,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
1687
1699
break ;
1688
1700
}
1689
1701
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
-
1700
1702
case CompletionKind::AttributeBegin: {
1701
1703
Lookup.getAttributeDeclCompletions (IsInSil, AttTargetDK);
1702
1704
0 commit comments