Skip to content

[CodeCompletion] Don't generate constraints for parts of a result builder unrelated to the code completion token #42296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ class BuilderClosureVisitor
if (!cs)
return nullptr;


if (cs->isForCodeCompletion() && !cs->containsCodeCompletionLoc(expr)) {
auto var = buildVar(expr->getStartLoc());
cs->setType(var, PlaceholderType::get(ctx, var));
return var;
}

Expr *origExpr = expr;

if (oneWay) {
Expand Down Expand Up @@ -511,6 +518,12 @@ class BuilderClosureVisitor
bool isTopLevel = false) {
assert(payloadIndex < numPayloads);

if (cs && cs->isForCodeCompletion() && !cs->containsCodeCompletionLoc(ifStmt)) {
auto var = buildVar(ifStmt->getStartLoc());
cs->setType(var, PlaceholderType::get(ctx, var));
return var;
}

// First generate constraints for the conditions. This can introduce
// variable bindings that will be used within the "then" branch.
if (cs && cs->generateConstraints(ifStmt->getCond(), dc)) {
Expand Down Expand Up @@ -714,6 +727,12 @@ class BuilderClosureVisitor
}

VarDecl *visitSwitchStmt(SwitchStmt *switchStmt) {
if (cs && cs->isForCodeCompletion() && !cs->containsCodeCompletionLoc(switchStmt)) {
auto var = buildVar(switchStmt->getStartLoc());
cs->setType(var, PlaceholderType::get(ctx, var));
return var;
}

// Generate constraints for the subject expression, and capture its
// type for use in matching the various patterns.
Expr *subjectExpr = switchStmt->getSubjectExpr();
Expand Down Expand Up @@ -861,6 +880,14 @@ class BuilderClosureVisitor
return nullptr;
}

SourceLoc loc = forEachStmt->getForLoc();

if (cs && cs->isForCodeCompletion() && !cs->containsCodeCompletionLoc(forEachStmt)) {
auto var = buildVar(loc);
cs->setType(var, PlaceholderType::get(ctx, var));
return var;
}

// Generate constraints for the loop header. This also wires up the
// types for the patterns.
auto target = SolutionApplicationTarget::forForEachStmt(
Expand All @@ -886,7 +913,6 @@ class BuilderClosureVisitor
// Form a variable of array type that will capture the result of each
// iteration of the loop. We need a fresh type variable to remove the
// lvalue-ness of the array variable.
SourceLoc loc = forEachStmt->getForLoc();
VarDecl *arrayVar = buildVar(loc);
Type arrayElementType = cs->createTypeVariable(
cs->getConstraintLocator(forEachStmt), 0);
Expand Down