Skip to content

Commit 52756d1

Browse files
committed
[CodeCompletion] Skip conjuction elements that are unrelated to the code completion token
1 parent bbd7a91 commit 52756d1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ class ResultBuilderTransform
10791079
// to rank code completion items that match the type expected by
10801080
// buildBlock higher.
10811081
buildBlockArguments.push_back(expr);
1082+
} else if (ctx.CompletionCallback && expr->getSourceRange().isValid() && !ctx.SourceMgr.rangeContainsIDEInspectionTarget(expr->getSourceRange())) {
1083+
auto *resultVar = buildPlaceholderVar(expr->getStartLoc(), newBody);
1084+
buildBlockArguments.push_back(builder.buildVarRef(resultVar, expr->getStartLoc()));
10821085
} else {
10831086
auto *capture = captureExpr(expr, newBody);
10841087
// A reference to the synthesized variable is passed as an argument

lib/Sema/CSSyntacticElement.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,19 @@ class SyntacticElementConstraintGenerator
10301030

10311031
SmallVector<ElementInfo, 4> elements;
10321032
for (auto element : braceStmt->getElements()) {
1033+
if (cs.isForCodeCompletion() && !cs.containsIDEInspectionTarget(element)) {
1034+
// Statements and expressions can't influence the expresion that
1035+
// contains the code completion token. To improve performance, skip
1036+
// type checking them entirely.
1037+
if (element.is<Expr *>()) {
1038+
continue;
1039+
} else if (element.is<Stmt *>() && !element.isStmt(StmtKind::Guard)) {
1040+
// Guard statements might define variables that are used in the code
1041+
// completion expression. Don't skip them.
1042+
continue;
1043+
}
1044+
}
1045+
10331046
if (auto *decl = element.dyn_cast<Decl *>()) {
10341047
if (auto *PDB = dyn_cast<PatternBindingDecl>(decl)) {
10351048
visitPatternBinding(PDB, elements);

0 commit comments

Comments
 (0)