@@ -386,6 +386,10 @@ class TypeVariableType::Implementation {
386386
387387 bool isTypeSequence () const ;
388388
389+ // / Determine whether this type variable represents a code completion
390+ // / expression.
391+ bool isCodeCompletionToken () const ;
392+
389393 // / Retrieve the representative of the equivalence class to which this
390394 // / type variable belongs.
391395 // /
@@ -2409,6 +2413,10 @@ class ConstraintSystem {
24092413 // / diagnostics when result builder has multiple overloads.
24102414 llvm::SmallDenseSet<AnyFunctionRef> InvalidResultBuilderBodies;
24112415
2416+ // / Arguments after the code completion token that were thus ignored (i.e.
2417+ // / assigned fresh type variables) for type checking.
2418+ llvm::SetVector<ConstraintLocator *> IgnoredArguments;
2419+
24122420 // / Maps node types used within all portions of the constraint
24132421 // / system, instead of directly using the types on the
24142422 // / nodes themselves. This allows us to typecheck and
@@ -3174,9 +3182,24 @@ class ConstraintSystem {
31743182 return TypeVariables.count (typeVar) > 0 ;
31753183 }
31763184
3177- // / Whether the given expression 's source range contains the code
3185+ // / Whether the given ASTNode 's source range contains the code
31783186 // / completion location.
3179- bool containsCodeCompletionLoc (Expr *expr) const ;
3187+ bool containsCodeCompletionLoc (ASTNode node) const ;
3188+ bool containsCodeCompletionLoc (const ArgumentList *args) const ;
3189+
3190+ // / Marks the argument with the \p ArgLoc locator as being ignored because it
3191+ // / occurs after the code completion token. This assumes that the argument is
3192+ // / not type checked (by assigning it a fresh type variable) and prevents
3193+ // / fixes from being generated for this argument.
3194+ void markArgumentIgnoredForCodeCompletion (ConstraintLocator *ArgLoc) {
3195+ IgnoredArguments.insert (ArgLoc);
3196+ }
3197+
3198+ // / Whether the argument with the \p ArgLoc locator occurs after the code
3199+ // / completion tokena and thus should be ignored and not generate any fixes.
3200+ bool isArgumentIgnoredForCodeCompletion (ConstraintLocator *ArgLoc) {
3201+ return IgnoredArguments.count (ArgLoc) > 0 ;
3202+ }
31803203
31813204 void setClosureType (const ClosureExpr *closure, FunctionType *type) {
31823205 assert (closure);
@@ -5537,8 +5560,44 @@ class MatchCallArgumentListener {
55375560 // / \returns true to indicate that this should cause a failure, false
55385561 // / otherwise.
55395562 virtual bool relabelArguments (ArrayRef<Identifier> newNames);
5563+
5564+ // / \returns true if matchCallArguments should try to claim the argument at
5565+ // / \p argIndex while recovering from a failure. This is used to prevent
5566+ // / claiming of arguments after the code completion token.
5567+ virtual bool shouldClaimArgDuringRecovery (unsigned argIdx);
5568+
5569+ // / \returns true if \p arg can be claimed even though its argument label
5570+ // / doesn't match. This is the case for arguments representing the code
5571+ // / completion token if they don't contain a label. In these cases completion
5572+ // / will suggest the label.
5573+ virtual bool
5574+ canClaimArgIgnoringNameMismatch (const AnyFunctionType::Param &arg);
55405575};
55415576
5577+ // / For a callsite containing a code completion expression, stores the index of
5578+ // / the arg containing it along with the index of the first trailing closure and
5579+ // / how many arguments were passed in total.
5580+ struct CompletionArgInfo {
5581+ unsigned completionIdx;
5582+ Optional<unsigned > firstTrailingIdx;
5583+ unsigned argCount;
5584+
5585+ // / \returns true if the given argument index is possibly about to be written
5586+ // / by the user (given the completion index) so shouldn't be penalised as
5587+ // / missing when ranking solutions.
5588+ bool allowsMissingArgAt (unsigned argInsertIdx, AnyFunctionType::Param param);
5589+
5590+ // / \returns true if the argument containing the completion location is before
5591+ // / the argument with the given index.
5592+ bool isBefore (unsigned argIdx) { return completionIdx < argIdx; }
5593+ };
5594+
5595+ // / Extracts the index of the argument containing the code completion location
5596+ // / from the provided anchor if it's a \c CallExpr, \c SubscriptExpr, or
5597+ // / \c ObjectLiteralExpr.
5598+ Optional<CompletionArgInfo> getCompletionArgInfo (ASTNode anchor,
5599+ ConstraintSystem &cs);
5600+
55425601// / Match the call arguments (as described by the given argument type) to
55435602// / the parameters (as described by the given parameter type).
55445603// /
0 commit comments