@@ -2406,6 +2406,10 @@ class ConstraintSystem {
2406
2406
// / diagnostics when result builder has multiple overloads.
2407
2407
llvm::SmallDenseSet<AnyFunctionRef> InvalidResultBuilderBodies;
2408
2408
2409
+ // / Arguments after the code completion token that were thus ignored (i.e.
2410
+ // / assigned fresh type variables) for type checking.
2411
+ llvm::SetVector<ConstraintLocator *> IgnoredArguments;
2412
+
2409
2413
// / Maps node types used within all portions of the constraint
2410
2414
// / system, instead of directly using the types on the
2411
2415
// / nodes themselves. This allows us to typecheck and
@@ -3171,9 +3175,24 @@ class ConstraintSystem {
3171
3175
return TypeVariables.count (typeVar) > 0 ;
3172
3176
}
3173
3177
3174
- // / Whether the given expression 's source range contains the code
3178
+ // / Whether the given ASTNode 's source range contains the code
3175
3179
// / completion location.
3176
- bool containsCodeCompletionLoc (Expr *expr) const ;
3180
+ bool containsCodeCompletionLoc (ASTNode node) const ;
3181
+ bool containsCodeCompletionLoc (const ArgumentList *args) const ;
3182
+
3183
+ // / Marks the argument with the \p ArgLoc locator as being ignored because it
3184
+ // / occurs after the code completion token. This assumes that the argument is
3185
+ // / not type checked (by assigning it a fresh type variable) and prevents
3186
+ // / fixes from being generated for this argument.
3187
+ void markArgumentIgnoredForCodeCompletion (ConstraintLocator *ArgLoc) {
3188
+ IgnoredArguments.insert (ArgLoc);
3189
+ }
3190
+
3191
+ // / Whether the argument with the \p ArgLoc locator occurs after the code
3192
+ // / completion tokena and thus should be ignored and not generate any fixes.
3193
+ bool isArgumentIgnoredForCodeCompletion (ConstraintLocator *ArgLoc) {
3194
+ return IgnoredArguments.count (ArgLoc) > 0 ;
3195
+ }
3177
3196
3178
3197
void setClosureType (const ClosureExpr *closure, FunctionType *type) {
3179
3198
assert (closure);
@@ -5534,8 +5553,44 @@ class MatchCallArgumentListener {
5534
5553
// / \returns true to indicate that this should cause a failure, false
5535
5554
// / otherwise.
5536
5555
virtual bool relabelArguments (ArrayRef<Identifier> newNames);
5556
+
5557
+ // / \returns true if matchCallArguments should try to claim the argument at
5558
+ // / \p argIndex while recovering from a failure. This is used to prevent
5559
+ // / claiming of arguments after the code completion token.
5560
+ virtual bool shouldClaimArgDuringRecovery (unsigned argIdx);
5561
+
5562
+ // / \returns true if \p arg can be claimed even though its argument label
5563
+ // / doesn't match. This is the case for arguments representing the code
5564
+ // / completion token if they don't contain a label. In these cases completion
5565
+ // / will suggest the label.
5566
+ virtual bool
5567
+ canClaimArgIgnoringNameMismatch (const AnyFunctionType::Param &arg);
5568
+ };
5569
+
5570
+ // / For a callsite containing a code completion expression, stores the index of
5571
+ // / the arg containing it along with the index of the first trailing closure and
5572
+ // / how many arguments were passed in total.
5573
+ struct CompletionArgInfo {
5574
+ unsigned completionIdx;
5575
+ Optional<unsigned > firstTrailingIdx;
5576
+ unsigned argCount;
5577
+
5578
+ // / \returns true if the given argument index is possibly about to be written
5579
+ // / by the user (given the completion index) so shouldn't be penalised as
5580
+ // / missing when ranking solutions.
5581
+ bool allowsMissingArgAt (unsigned argInsertIdx, AnyFunctionType::Param param);
5582
+
5583
+ // / \returns true if the argument containing the completion location is before
5584
+ // / the argument with the given index.
5585
+ bool isBefore (unsigned argIdx) { return completionIdx < argIdx; }
5537
5586
};
5538
5587
5588
+ // / Extracts the index of the argument containing the code completion location
5589
+ // / from the provided anchor if it's a \c CallExpr, \c SubscriptExpr, or
5590
+ // / \c ObjectLiteralExpr.
5591
+ Optional<CompletionArgInfo> getCompletionArgInfo (ASTNode anchor,
5592
+ ConstraintSystem &cs);
5593
+
5539
5594
// / Match the call arguments (as described by the given argument type) to
5540
5595
// / the parameters (as described by the given parameter type).
5541
5596
// /
0 commit comments