mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
Following on from updating regular member completion, this hooks up unresolved member completion (i.e. .<complete here>) to the typeCheckForCodeCompletion API to generate completions from all solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any). This lets us produce unresolved member completions even when the contextual type is ambiguous or involves errors. Whenever typeCheckExpression is called on an expression containing a code completion expression and a CompletionCallback has been set, each solution formed is passed to the callback so the type of the completion expression can be extracted and used to lookup up the members to return.
This commit is contained in:
@@ -3802,6 +3802,24 @@ bool ConstraintSystem::repairFailures(
|
||||
}
|
||||
}
|
||||
|
||||
if (isForCodeCompletion()) {
|
||||
// If the argument contains the code completion location, the user has not
|
||||
// finished typing out this argument yet. Treat the mismatch as valid so
|
||||
// we don't penalize this solution.
|
||||
if (auto *arg = getAsExpr(simplifyLocatorToAnchor(loc))) {
|
||||
// Ignore synthesized args like $match in implicit pattern match
|
||||
// operator calls. Their source location is usually the same as the
|
||||
// other (explicit) argument's so source range containment alone isn't
|
||||
// sufficient.
|
||||
bool isSynthesizedArg = arg->isImplicit() && isa<DeclRefExpr>(arg);
|
||||
SourceRange range = arg->getSourceRange();
|
||||
if (!isSynthesizedArg && range.isValid() &&
|
||||
Context.SourceMgr.rangeContainsCodeCompletionLoc(range) &&
|
||||
!lhs->isVoid() && !lhs->isUninhabited())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (repairByInsertingExplicitCall(lhs, rhs))
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user