File tree 4 files changed +22
-14
lines changed
4 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 20
20
21
21
namespace swift {
22
22
23
+ namespace constraints {
24
+ class SyntacticElementTarget ;
25
+ }
26
+
23
27
class CompletionContextFinder : public ASTWalker {
24
28
enum class ContextKind {
25
29
FallbackExpression,
@@ -53,12 +57,9 @@ class CompletionContextFinder : public ASTWalker {
53
57
return MacroWalking::Arguments;
54
58
}
55
59
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);
62
63
63
64
// / Finder for completion contexts within the outermost non-closure context of
64
65
// / the code completion expression's direct context.
Original file line number Diff line number Diff line change @@ -984,7 +984,8 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
984
984
SmallVector<Solution, 4 > solutions;
985
985
cs.solveForCodeCompletion (solutions);
986
986
987
- CompletionContextFinder analyzer (func, func->getDeclContext ());
987
+ SyntacticElementTarget funcTarget (func);
988
+ CompletionContextFinder analyzer (funcTarget, func->getDeclContext ());
988
989
if (analyzer.hasCompletion ()) {
989
990
filterSolutionsForCodeCompletion (solutions, analyzer);
990
991
for (const auto &solution : solutions) {
Original file line number Diff line number Diff line change 12
12
13
13
#include " swift/Sema/CompletionContextFinder.h"
14
14
#include " swift/Parse/Lexer.h"
15
+ #include " swift/Sema/SyntacticElementTarget.h"
15
16
16
17
using namespace swift ;
18
+ using namespace constraints ;
17
19
using Fallback = CompletionContextFinder::Fallback;
18
20
21
+ CompletionContextFinder::CompletionContextFinder (
22
+ SyntacticElementTarget target, DeclContext *DC)
23
+ : InitialExpr(target.getAsExpr()), InitialDC(DC) {
24
+ assert (DC);
25
+ target.walk (*this );
26
+ }
27
+
19
28
ASTWalker::PreWalkResult<Expr *>
20
29
CompletionContextFinder::walkToExprPre (Expr *E) {
21
30
if (auto *closure = dyn_cast<ClosureExpr>(E)) {
Original file line number Diff line number Diff line change @@ -574,15 +574,12 @@ bool TypeChecker::typeCheckForCodeCompletion(
574
574
return false ;
575
575
}
576
576
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);
583
580
}
584
581
585
- CompletionContextFinder contextAnalyzer (node , DC);
582
+ CompletionContextFinder contextAnalyzer (target , DC);
586
583
587
584
// If there was no completion expr (e.g. if the code completion location was
588
585
// among tokens that were skipped over during parser error recovery) bail.
You can’t perform that action at this time.
0 commit comments