[CodeCompletion] Deduplicate the two isMemberCompletion functions in ParseExpr.cpp and ParseDecl.cpp

Also:
- propagate the Solution -> Result rename to Solution parameter of deliverDotExprResults
- fixup header comment in CodeCompletionTypeChecking.h
This commit is contained in:
Nathan Hawes
2020-09-09 12:14:53 -07:00
parent 7a06792e5d
commit b15c1fd349
6 changed files with 56 additions and 51 deletions

View File

@@ -1185,6 +1185,34 @@ Parser::getStringLiteralIfNotInterpolated(SourceLoc Loc,
Segments.front().Length));
}
bool Parser::
shouldSuppressSingleExpressionBodyTransform(ParserStatus Status,
MutableArrayRef<ASTNode> BodyElems) {
if (BodyElems.size() != 1)
return true;
if (!Status.hasCodeCompletion())
return false;
struct HasMemberCompletion: public ASTWalker {
bool Value = false;
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
if (auto *CCE = dyn_cast<CodeCompletionExpr>(E)) {
// If it has a base expression this is member completion, which is
// performed using the new solver-based mechanism, so it's ok to go
// ahead with the transform (and necessary to pick up the correct
// expected type).
Value = CCE->getBase();
return {false, nullptr};
}
return {true, E};
}
};
HasMemberCompletion Check;
BodyElems.front().walk(Check);
return !Check.Value;
}
struct ParserUnit::Implementation {
std::shared_ptr<SyntaxParseActions> SPActions;
LangOptions LangOpts;