@@ -2416,18 +2416,6 @@ void CompletionLookup::addPostfixOperatorCompletion(OperatorDecl *op,
2416
2416
addTypeAnnotation (builder, resultType);
2417
2417
}
2418
2418
2419
- void CompletionLookup::tryPostfixOperator (Expr *expr, PostfixOperatorDecl *op) {
2420
- ConcreteDeclRef referencedDecl;
2421
- FunctionType *funcTy = getTypeOfCompletionOperator (
2422
- const_cast <DeclContext *>(CurrDeclContext), expr, op->getName (),
2423
- DeclRefKind::PostfixOperator, referencedDecl);
2424
- if (!funcTy)
2425
- return ;
2426
-
2427
- // TODO: Use referencedDecl (FuncDecl) instead of 'op' (OperatorDecl).
2428
- addPostfixOperatorCompletion (op, funcTy->getResult ());
2429
- }
2430
-
2431
2419
void CompletionLookup::addAssignmentOperator (Type RHSType) {
2432
2420
CodeCompletionResultBuilder builder = makeResultBuilder (
2433
2421
CodeCompletionResultKind::BuiltinOperator, SemanticContextKind::None);
@@ -2472,104 +2460,6 @@ void CompletionLookup::addInfixOperatorCompletion(OperatorDecl *op,
2472
2460
addTypeAnnotation (builder, resultType);
2473
2461
}
2474
2462
2475
- void CompletionLookup::tryInfixOperatorCompletion (Expr *foldedExpr,
2476
- InfixOperatorDecl *op) {
2477
- ConcreteDeclRef referencedDecl;
2478
- FunctionType *funcTy = getTypeOfCompletionOperator (
2479
- const_cast <DeclContext *>(CurrDeclContext), foldedExpr, op->getName (),
2480
- DeclRefKind::BinaryOperator, referencedDecl);
2481
- if (!funcTy)
2482
- return ;
2483
-
2484
- Type lhsTy = funcTy->getParams ()[0 ].getPlainType ();
2485
- Type rhsTy = funcTy->getParams ()[1 ].getPlainType ();
2486
- Type resultTy = funcTy->getResult ();
2487
-
2488
- // Don't complete optional operators on non-optional types.
2489
- if (!lhsTy->getRValueType ()->getOptionalObjectType ()) {
2490
- // 'T ?? T'
2491
- if (op->getName ().str () == " ??" )
2492
- return ;
2493
- // 'T == nil'
2494
- if (auto NT = rhsTy->getNominalOrBoundGenericNominal ())
2495
- if (NT->getName () ==
2496
- CurrDeclContext->getASTContext ().Id_OptionalNilComparisonType )
2497
- return ;
2498
- }
2499
-
2500
- // If the right-hand side and result type are both type parameters, we're
2501
- // not providing a useful completion.
2502
- if (resultTy->isTypeParameter () && rhsTy->isTypeParameter ())
2503
- return ;
2504
-
2505
- // TODO: Use referencedDecl (FuncDecl) instead of 'op' (OperatorDecl).
2506
- addInfixOperatorCompletion (op, funcTy->getResult (),
2507
- funcTy->getParams ()[1 ].getPlainType ());
2508
- }
2509
-
2510
- Expr *
2511
- CompletionLookup::typeCheckLeadingSequence (Expr *LHS,
2512
- ArrayRef<Expr *> leadingSequence) {
2513
- if (leadingSequence.empty ())
2514
- return LHS;
2515
-
2516
- SourceRange sequenceRange (leadingSequence.front ()->getStartLoc (),
2517
- LHS->getEndLoc ());
2518
- auto *expr = findParsedExpr (CurrDeclContext, sequenceRange);
2519
- if (!expr)
2520
- return LHS;
2521
-
2522
- if (expr->getType () && !expr->getType ()->hasError ())
2523
- return expr;
2524
-
2525
- if (!typeCheckExpression (const_cast <DeclContext *>(CurrDeclContext), expr))
2526
- return expr;
2527
- return LHS;
2528
- }
2529
-
2530
- void CompletionLookup::getOperatorCompletions (
2531
- Expr *LHS, ArrayRef<Expr *> leadingSequence) {
2532
- if (IsSuperRefExpr)
2533
- return ;
2534
-
2535
- Expr *foldedExpr = typeCheckLeadingSequence (LHS, leadingSequence);
2536
-
2537
- SmallVector<OperatorDecl *, 16 > operators;
2538
- collectOperators (operators);
2539
- // FIXME: this always chooses the first operator with the given name.
2540
- llvm::DenseSet<Identifier> seenPostfixOperators;
2541
- llvm::DenseSet<Identifier> seenInfixOperators;
2542
-
2543
- for (auto op : operators) {
2544
- switch (op->getKind ()) {
2545
- case DeclKind::PrefixOperator:
2546
- // Don't insert prefix operators in postfix position.
2547
- // FIXME: where should these get completed?
2548
- break ;
2549
- case DeclKind::PostfixOperator:
2550
- if (seenPostfixOperators.insert (op->getName ()).second )
2551
- tryPostfixOperator (LHS, cast<PostfixOperatorDecl>(op));
2552
- break ;
2553
- case DeclKind::InfixOperator:
2554
- if (seenInfixOperators.insert (op->getName ()).second )
2555
- tryInfixOperatorCompletion (foldedExpr, cast<InfixOperatorDecl>(op));
2556
- break ;
2557
- default :
2558
- llvm_unreachable (" unexpected operator kind" );
2559
- }
2560
- }
2561
-
2562
- if (leadingSequence.empty () && LHS->getType () &&
2563
- LHS->getType ()->hasLValueType ()) {
2564
- addAssignmentOperator (LHS->getType ()->getRValueType ());
2565
- }
2566
-
2567
- // FIXME: unify this with the ?.member completions.
2568
- if (auto T = LHS->getType ())
2569
- if (auto ValueT = T->getRValueType ()->getOptionalObjectType ())
2570
- addPostfixBang (ValueT);
2571
- }
2572
-
2573
2463
void CompletionLookup::addTypeRelationFromProtocol (
2574
2464
CodeCompletionResultBuilder &builder, CodeCompletionLiteralKind kind) {
2575
2465
Type literalType;
0 commit comments