@@ -25,22 +25,6 @@ class SyntacticElementTarget;
2525}
2626
2727class CompletionContextFinder : public ASTWalker {
28- enum class ContextKind {
29- FallbackExpression,
30- StringInterpolation,
31- SingleStmtClosure,
32- MultiStmtClosure,
33- ErrorExpression
34- };
35-
36- struct Context {
37- ContextKind Kind;
38- Expr *E;
39- };
40-
41- // / Stack of all "interesting" contexts up to code completion expression.
42- llvm::SmallVector<Context, 4 > Contexts;
43-
4428 // / If we are completing inside an expression, the \c CodeCompletionExpr that
4529 // / represents the code completion token.
4630
@@ -49,44 +33,18 @@ class CompletionContextFinder : public ASTWalker {
4933 // / component.
5034 llvm::PointerUnion<CodeCompletionExpr *, const KeyPathExpr *> CompletionNode;
5135
52- Expr *InitialExpr = nullptr ;
53- DeclContext *InitialDC;
54-
55- // / Whether we're looking for any viable fallback expression.
56- bool ForFallback = false ;
57-
58- // / Finder for fallback completion contexts within the outermost non-closure
59- // / context of the code completion expression's direct context.
60- CompletionContextFinder (DeclContext *completionDC)
61- : InitialDC(completionDC), ForFallback(true ) {
62- while (auto *ACE = dyn_cast<AbstractClosureExpr>(InitialDC))
63- InitialDC = ACE->getParent ();
64- InitialDC->walkContext (*this );
65- }
66-
6736public:
6837 MacroWalking getMacroWalkingBehavior () const override {
6938 return MacroWalking::Arguments;
7039 }
7140
7241 // / Finder for completion contexts within the provided SyntacticElementTarget.
73- CompletionContextFinder (constraints::SyntacticElementTarget target,
74- DeclContext *DC);
75-
76- static CompletionContextFinder forFallback (DeclContext *DC) {
77- return CompletionContextFinder (DC);
78- }
42+ CompletionContextFinder (constraints::SyntacticElementTarget target);
7943
8044 PreWalkResult<Expr *> walkToExprPre (Expr *E) override ;
8145
82- PostWalkResult<Expr *> walkToExprPost (Expr *E) override ;
83-
8446 PreWalkAction walkToDeclPre (Decl *D) override ;
8547
86- bool locatedInStringInterpolation () const {
87- return hasContext (ContextKind::StringInterpolation);
88- }
89-
9048 bool hasCompletionExpr () const {
9149 return CompletionNode.dyn_cast <CodeCompletionExpr *>() != nullptr ;
9250 }
@@ -114,28 +72,8 @@ class CompletionContextFinder : public ASTWalker {
11472 // / If we are completing in a key path, returns the index at which the key
11573 // / path has the code completion component.
11674 size_t getKeyPathCompletionComponentIndex () const ;
117-
118- struct Fallback {
119- Expr *E; // /< The fallback expression.
120- DeclContext *DC; // /< The fallback expression's decl context.
121- bool SeparatePrecheck; // /< True if the fallback may require prechecking.
122- };
123-
124- // / As a fallback sometimes its useful to not only type-check
125- // / code completion expression directly but instead add some
126- // / of the enclosing context e.g. when completion is an argument
127- // / to a call.
128- std::optional<Fallback> getFallbackCompletionExpr () const ;
129-
130- private:
131- bool hasContext (ContextKind kind) const {
132- return llvm::find_if (Contexts, [&kind](const Context &currContext) {
133- return currContext.Kind == kind;
134- }) != Contexts.end ();
135- }
13675};
13776
138-
13977// / Returns \c true if \p range is valid and contains the IDE inspection
14078// / target. This performs the underlying check based on \c CharSourceRange
14179// / to make sure we correctly return \c true if the ide inspection target
0 commit comments