@@ -986,7 +986,7 @@ constraints::matchCallArguments(
986
986
}
987
987
988
988
static Optional<unsigned >
989
- getCompletionArgIndex (ASTNode anchor, SourceManager &SM ) {
989
+ getCompletionArgIndex (ASTNode anchor, ConstraintSystem &CS ) {
990
990
Expr *arg = nullptr ;
991
991
if (auto *CE = getAsExpr<CallExpr>(anchor))
992
992
arg = CE->getArg ();
@@ -998,20 +998,15 @@ getCompletionArgIndex(ASTNode anchor, SourceManager &SM) {
998
998
if (!arg)
999
999
return None;
1000
1000
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
-
1008
1001
if (auto *TE = dyn_cast<TupleExpr>(arg)) {
1009
1002
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
+ });
1011
1006
if (idx != elems.end ())
1012
1007
return std::distance (elems.begin (), idx);
1013
1008
} else if (auto *PE = dyn_cast<ParenExpr>(arg)) {
1014
- if (containsCompletion (PE->getSubExpr ()))
1009
+ if (CS. containsCodeCompletionLoc (PE->getSubExpr ()))
1015
1010
return 0 ;
1016
1011
}
1017
1012
return None;
@@ -1069,9 +1064,8 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
1069
1064
// completion location, later arguments shouldn't be considered missing
1070
1065
// (causing the solution to have a worse score) as the user just hasn't
1071
1066
// written them yet. Early exit to avoid recording them in this case.
1072
- SourceManager &SM = CS.getASTContext ().SourceMgr ;
1073
1067
if (!CompletionArgIdx)
1074
- CompletionArgIdx = getCompletionArgIndex (Locator.getAnchor (), SM );
1068
+ CompletionArgIdx = getCompletionArgIndex (Locator.getAnchor (), CS );
1075
1069
if (CompletionArgIdx && *CompletionArgIdx < argInsertIdx)
1076
1070
return newArgIdx;
1077
1071
}
@@ -1817,9 +1811,7 @@ static bool fixMissingArguments(ConstraintSystem &cs, ASTNode anchor,
1817
1811
// code completion location, since they may have just not been written yet.
1818
1812
if (cs.isForCodeCompletion ()) {
1819
1813
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) &&
1823
1815
(closure->hasAnonymousClosureVars () ||
1824
1816
(args.empty () && closure->getInLoc ().isInvalid ())))
1825
1817
return false ;
@@ -3812,9 +3804,7 @@ bool ConstraintSystem::repairFailures(
3812
3804
// other (explicit) argument's so source range containment alone isn't
3813
3805
// sufficient.
3814
3806
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) &&
3818
3808
!lhs->isVoid () && !lhs->isUninhabited ())
3819
3809
return true ;
3820
3810
}
0 commit comments