[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:
Nathan Hawes
2020-10-14 14:44:23 -07:00
parent 7abf272c1c
commit ca7fb37aba
19 changed files with 461 additions and 266 deletions

View File

@@ -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;