@@ -386,6 +386,10 @@ class TypeVariableType::Implementation {
386
386
387
387
bool isTypeSequence () const ;
388
388
389
+ // / Determine whether this type variable represents a code completion
390
+ // / expression.
391
+ bool isCodeCompletionToken () const ;
392
+
389
393
// / Retrieve the representative of the equivalence class to which this
390
394
// / type variable belongs.
391
395
// /
@@ -2409,6 +2413,10 @@ class ConstraintSystem {
2409
2413
// / diagnostics when result builder has multiple overloads.
2410
2414
llvm::SmallDenseSet<AnyFunctionRef> InvalidResultBuilderBodies;
2411
2415
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
+
2412
2420
// / Maps node types used within all portions of the constraint
2413
2421
// / system, instead of directly using the types on the
2414
2422
// / nodes themselves. This allows us to typecheck and
@@ -3174,9 +3182,24 @@ class ConstraintSystem {
3174
3182
return TypeVariables.count (typeVar) > 0 ;
3175
3183
}
3176
3184
3177
- // / Whether the given expression 's source range contains the code
3185
+ // / Whether the given ASTNode 's source range contains the code
3178
3186
// / 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
+ }
3180
3203
3181
3204
void setClosureType (const ClosureExpr *closure, FunctionType *type) {
3182
3205
assert (closure);
@@ -5537,8 +5560,44 @@ class MatchCallArgumentListener {
5537
5560
// / \returns true to indicate that this should cause a failure, false
5538
5561
// / otherwise.
5539
5562
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);
5540
5575
};
5541
5576
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
+
5542
5601
// / Match the call arguments (as described by the given argument type) to
5543
5602
// / the parameters (as described by the given parameter type).
5544
5603
// /
0 commit comments