Skip to content

Commit 6d2c014

Browse files
committed
completion
1 parent 23d7091 commit 6d2c014

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

include/swift/Sema/CompletionContextFinder.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
namespace swift {
2222

23+
namespace constraints {
24+
class SyntacticElementTarget;
25+
}
26+
2327
class CompletionContextFinder : public ASTWalker {
2428
enum class ContextKind {
2529
FallbackExpression,
@@ -53,12 +57,9 @@ class CompletionContextFinder : public ASTWalker {
5357
return MacroWalking::Arguments;
5458
}
5559

56-
/// Finder for completion contexts within the provided initial expression.
57-
CompletionContextFinder(ASTNode initialNode, DeclContext *DC)
58-
: InitialExpr(initialNode.dyn_cast<Expr *>()), InitialDC(DC) {
59-
assert(DC);
60-
initialNode.walk(*this);
61-
};
60+
/// Finder for completion contexts within the provided SyntacticElementTarget.
61+
CompletionContextFinder(constraints::SyntacticElementTarget target,
62+
DeclContext *DC);
6263

6364
/// Finder for completion contexts within the outermost non-closure context of
6465
/// the code completion expression's direct context.

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,8 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
23442344
SmallVector<Solution, 4> solutions;
23452345
cs.solveForCodeCompletion(solutions);
23462346

2347-
CompletionContextFinder analyzer(func, func->getDeclContext());
2347+
SyntacticElementTarget funcTarget(func);
2348+
CompletionContextFinder analyzer(funcTarget, func->getDeclContext());
23482349
if (analyzer.hasCompletion()) {
23492350
filterSolutionsForCodeCompletion(solutions, analyzer);
23502351
for (const auto &solution : solutions) {

lib/Sema/CompletionContextFinder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212

1313
#include "swift/Sema/CompletionContextFinder.h"
1414
#include "swift/Parse/Lexer.h"
15+
#include "swift/Sema/SyntacticElementTarget.h"
1516

1617
using namespace swift;
18+
using namespace constraints;
1719
using Fallback = CompletionContextFinder::Fallback;
1820

21+
CompletionContextFinder::CompletionContextFinder(
22+
SyntacticElementTarget target, DeclContext *DC)
23+
: InitialExpr(target.getAsExpr()), InitialDC(DC) {
24+
assert(DC);
25+
target.walk(*this);
26+
}
27+
1928
ASTWalker::PreWalkResult<Expr *>
2029
CompletionContextFinder::walkToExprPre(Expr *E) {
2130
if (auto *closure = dyn_cast<ClosureExpr>(E)) {

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,12 @@ bool TypeChecker::typeCheckForCodeCompletion(
574574
return false;
575575
}
576576

577-
auto node = target.getAsASTNode();
578-
if (!node)
579-
return false;
580-
581-
if (auto *expr = getAsExpr(node)) {
582-
node = expr->walk(SanitizeExpr(Context));
577+
if (getAsExpr(target.getAsASTNode())) {
578+
SanitizeExpr sanitizer(Context);
579+
target = *target.walk(sanitizer);
583580
}
584581

585-
CompletionContextFinder contextAnalyzer(node, DC);
582+
CompletionContextFinder contextAnalyzer(target, DC);
586583

587584
// If there was no completion expr (e.g. if the code completion location was
588585
// among tokens that were skipped over during parser error recovery) bail.

0 commit comments

Comments
 (0)