@@ -338,44 +338,6 @@ std::string swift::ide::removeCodeCompletionTokens(
338338 return CleanFile;
339339}
340340
341- namespace {
342- class StmtFinder : public ASTWalker {
343- SourceManager &SM;
344- SourceLoc Loc;
345- StmtKind Kind;
346- Stmt *Found = nullptr ;
347-
348- public:
349- StmtFinder (SourceManager &SM, SourceLoc Loc, StmtKind Kind)
350- : SM(SM), Loc(Loc), Kind(Kind) {}
351-
352- std::pair<bool , Stmt *> walkToStmtPre (Stmt *S) override {
353- return { SM.rangeContainsTokenLoc (S->getSourceRange (), Loc), S };
354- }
355-
356- Stmt *walkToStmtPost (Stmt *S) override {
357- if (S->getKind () == Kind) {
358- Found = S;
359- return nullptr ;
360- }
361- return S;
362- }
363-
364- Stmt *getFoundStmt () const {
365- return Found;
366- }
367- };
368- } // end anonymous namespace
369-
370- static Stmt *findNearestStmt (const DeclContext *DC, SourceLoc Loc,
371- StmtKind Kind) {
372- auto &SM = DC->getASTContext ().SourceMgr ;
373- StmtFinder Finder (SM, Loc, Kind);
374- // FIXME(thread-safety): the walker is mutating the AST.
375- const_cast <DeclContext *>(DC)->walkContext (Finder);
376- return Finder.getFoundStmt ();
377- }
378-
379341CodeCompletionString::CodeCompletionString (ArrayRef<Chunk> Chunks) {
380342 std::uninitialized_copy (Chunks.begin (), Chunks.end (),
381343 getTrailingObjects<Chunk>());
@@ -1377,8 +1339,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13771339 void completeTypeIdentifierWithoutDot (IdentTypeRepr *ITR) override ;
13781340
13791341 void completeCaseStmtKeyword () override ;
1380- void completeCaseStmtBeginning () override ;
1381- void completeCaseStmtDotPrefix () override ;
1342+ void completeCaseStmtBeginning (CodeCompletionExpr *E) override ;
13821343 void completeDeclAttrBeginning (bool Sil, bool isIndependent) override ;
13831344 void completeDeclAttrParam (DeclAttrKind DK, int Index) override ;
13841345 void completeInPrecedenceGroup (SyntaxKind SK) override ;
@@ -3908,27 +3869,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39083869 }
39093870 }
39103871
3911- void getTypeContextEnumElementCompletions (SourceLoc Loc) {
3912- llvm::SaveAndRestore<LookupKind> ChangeLookupKind (
3913- Kind, LookupKind::EnumElement);
3914- NeedLeadingDot = !HaveDot;
3915-
3916- auto *Switch = cast_or_null<SwitchStmt>(
3917- findNearestStmt (CurrDeclContext, Loc, StmtKind::Switch));
3918- if (!Switch)
3919- return ;
3920- auto Ty = Switch->getSubjectExpr ()->getType ();
3921- if (!Ty)
3922- return ;
3923- ExprType = Ty;
3924- auto *TheEnumDecl = dyn_cast_or_null<EnumDecl>(Ty->getAnyNominal ());
3925- if (!TheEnumDecl)
3926- return ;
3927- for (auto Element : TheEnumDecl->getAllElements ()) {
3928- foundDecl (Element, DeclVisibilityKind::MemberOfCurrentNominal, {});
3929- }
3930- }
3931-
39323872 void getTypeCompletions (Type BaseType) {
39333873 Kind = LookupKind::Type;
39343874 this ->BaseType = BaseType;
@@ -4720,18 +4660,12 @@ void CodeCompletionCallbacksImpl::completeCaseStmtKeyword() {
47204660 CurDeclContext = P.CurDeclContext ;
47214661}
47224662
4723- void CodeCompletionCallbacksImpl::completeCaseStmtBeginning () {
4663+ void CodeCompletionCallbacksImpl::completeCaseStmtBeginning (CodeCompletionExpr *E ) {
47244664 assert (!InEnumElementRawValue);
47254665
47264666 Kind = CompletionKind::CaseStmtBeginning;
47274667 CurDeclContext = P.CurDeclContext ;
4728- }
4729-
4730- void CodeCompletionCallbacksImpl::completeCaseStmtDotPrefix () {
4731- assert (!InEnumElementRawValue);
4732-
4733- Kind = CompletionKind::CaseStmtDotPrefix;
4734- CurDeclContext = P.CurDeclContext ;
4668+ CodeCompleteTokenExpr = E;
47354669}
47364670
47374671void CodeCompletionCallbacksImpl::completeImportDecl (
@@ -5017,7 +4951,6 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
50174951 case CompletionKind::SuperExpr:
50184952 case CompletionKind::SuperExprDot:
50194953 case CompletionKind::CaseStmtBeginning:
5020- case CompletionKind::CaseStmtDotPrefix:
50214954 case CompletionKind::TypeIdentifierWithDot:
50224955 case CompletionKind::TypeIdentifierWithoutDot:
50234956 break ;
@@ -5417,16 +5350,11 @@ void CodeCompletionCallbacksImpl::doneParsing() {
54175350 }
54185351
54195352 case CompletionKind::CaseStmtBeginning: {
5420- SourceLoc Loc = P.Context .SourceMgr .getCodeCompletionLoc ();
5421- Lookup.getValueCompletionsInDeclContext (Loc);
5422- Lookup.getTypeContextEnumElementCompletions (Loc);
5423- break ;
5424- }
5425-
5426- case CompletionKind::CaseStmtDotPrefix: {
5427- Lookup.setHaveDot (SourceLoc ());
5428- SourceLoc Loc = P.Context .SourceMgr .getCodeCompletionLoc ();
5429- Lookup.getTypeContextEnumElementCompletions (Loc);
5353+ ExprContextInfo ContextInfo (CurDeclContext, CodeCompleteTokenExpr);
5354+ Lookup.setExpectedTypes (ContextInfo.getPossibleTypes (),
5355+ ContextInfo.isSingleExpressionBody ());
5356+ Lookup.getUnresolvedMemberCompletions (ContextInfo.getPossibleTypes ());
5357+ DoPostfixExprBeginning ();
54305358 break ;
54315359 }
54325360
0 commit comments