@@ -986,7 +986,7 @@ constraints::matchCallArguments(
986986}
987987
988988static Optional<unsigned >
989- getCompletionArgIndex (ASTNode anchor, SourceManager &SM ) {
989+ getCompletionArgIndex (ASTNode anchor, ConstraintSystem &CS ) {
990990 Expr *arg = nullptr ;
991991 if (auto *CE = getAsExpr<CallExpr>(anchor))
992992 arg = CE->getArg ();
@@ -998,20 +998,15 @@ getCompletionArgIndex(ASTNode anchor, SourceManager &SM) {
998998 if (!arg)
999999 return None;
10001000
1001- auto containsCompletion = [&](Expr *elem) {
1002- if (!elem)
1003- return false ;
1004- SourceRange range = elem->getSourceRange ();
1005- return range.isValid () && SM.rangeContainsCodeCompletionLoc (range);
1006- };
1007-
10081001 if (auto *TE = dyn_cast<TupleExpr>(arg)) {
10091002 auto elems = TE->getElements ();
1010- auto idx = llvm::find_if (elems, containsCompletion);
1003+ auto idx = llvm::find_if (elems, [&](Expr *elem) {
1004+ return CS.containsCodeCompletionLoc (elem);
1005+ });
10111006 if (idx != elems.end ())
10121007 return std::distance (elems.begin (), idx);
10131008 } else if (auto *PE = dyn_cast<ParenExpr>(arg)) {
1014- if (containsCompletion (PE->getSubExpr ()))
1009+ if (CS. containsCodeCompletionLoc (PE->getSubExpr ()))
10151010 return 0 ;
10161011 }
10171012 return None;
@@ -1069,9 +1064,8 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
10691064 // completion location, later arguments shouldn't be considered missing
10701065 // (causing the solution to have a worse score) as the user just hasn't
10711066 // written them yet. Early exit to avoid recording them in this case.
1072- SourceManager &SM = CS.getASTContext ().SourceMgr ;
10731067 if (!CompletionArgIdx)
1074- CompletionArgIdx = getCompletionArgIndex (Locator.getAnchor (), SM );
1068+ CompletionArgIdx = getCompletionArgIndex (Locator.getAnchor (), CS );
10751069 if (CompletionArgIdx && *CompletionArgIdx < argInsertIdx)
10761070 return newArgIdx;
10771071 }
@@ -1817,9 +1811,7 @@ static bool fixMissingArguments(ConstraintSystem &cs, ASTNode anchor,
18171811 // code completion location, since they may have just not been written yet.
18181812 if (cs.isForCodeCompletion ()) {
18191813 if (auto *closure = getAsExpr<ClosureExpr>(anchor)) {
1820- SourceManager &SM = closure->getASTContext ().SourceMgr ;
1821- SourceRange range = closure->getSourceRange ();
1822- if (range.isValid () && SM.rangeContainsCodeCompletionLoc (range) &&
1814+ if (cs.containsCodeCompletionLoc (closure) &&
18231815 (closure->hasAnonymousClosureVars () ||
18241816 (args.empty () && closure->getInLoc ().isInvalid ())))
18251817 return false ;
@@ -3812,9 +3804,7 @@ bool ConstraintSystem::repairFailures(
38123804 // other (explicit) argument's so source range containment alone isn't
38133805 // sufficient.
38143806 bool isSynthesizedArg = arg->isImplicit () && isa<DeclRefExpr>(arg);
3815- SourceRange range = arg->getSourceRange ();
3816- if (!isSynthesizedArg && range.isValid () &&
3817- Context.SourceMgr .rangeContainsCodeCompletionLoc (range) &&
3807+ if (!isSynthesizedArg && containsCodeCompletionLoc (arg) &&
38183808 !lhs->isVoid () && !lhs->isUninhabited ())
38193809 return true ;
38203810 }
0 commit comments