@@ -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,7 +1339,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13771339 void completeTypeIdentifierWithoutDot (IdentTypeRepr *ITR) override ;
13781340
13791341 void completeCaseStmtKeyword () override ;
1380- void completeCaseStmtBeginning () override ;
1342+ void completeCaseStmtBeginning (CodeCompletionExpr *E ) override ;
13811343 void completeDeclAttrBeginning (bool Sil, bool isIndependent) override ;
13821344 void completeDeclAttrParam (DeclAttrKind DK, int Index) override ;
13831345 void completeInPrecedenceGroup (SyntaxKind SK) override ;
@@ -3907,27 +3869,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39073869 }
39083870 }
39093871
3910- void getTypeContextEnumElementCompletions (SourceLoc Loc) {
3911- llvm::SaveAndRestore<LookupKind> ChangeLookupKind (
3912- Kind, LookupKind::EnumElement);
3913- NeedLeadingDot = !HaveDot;
3914-
3915- auto *Switch = cast_or_null<SwitchStmt>(
3916- findNearestStmt (CurrDeclContext, Loc, StmtKind::Switch));
3917- if (!Switch)
3918- return ;
3919- auto Ty = Switch->getSubjectExpr ()->getType ();
3920- if (!Ty)
3921- return ;
3922- ExprType = Ty;
3923- auto *TheEnumDecl = dyn_cast_or_null<EnumDecl>(Ty->getAnyNominal ());
3924- if (!TheEnumDecl)
3925- return ;
3926- for (auto Element : TheEnumDecl->getAllElements ()) {
3927- foundDecl (Element, DeclVisibilityKind::MemberOfCurrentNominal, {});
3928- }
3929- }
3930-
39313872 void getTypeCompletions (Type BaseType) {
39323873 Kind = LookupKind::Type;
39333874 this ->BaseType = BaseType;
@@ -4719,11 +4660,12 @@ void CodeCompletionCallbacksImpl::completeCaseStmtKeyword() {
47194660 CurDeclContext = P.CurDeclContext ;
47204661}
47214662
4722- void CodeCompletionCallbacksImpl::completeCaseStmtBeginning () {
4663+ void CodeCompletionCallbacksImpl::completeCaseStmtBeginning (CodeCompletionExpr *E ) {
47234664 assert (!InEnumElementRawValue);
47244665
47254666 Kind = CompletionKind::CaseStmtBeginning;
47264667 CurDeclContext = P.CurDeclContext ;
4668+ CodeCompleteTokenExpr = E;
47274669}
47284670
47294671void CodeCompletionCallbacksImpl::completeImportDecl (
@@ -5408,9 +5350,11 @@ void CodeCompletionCallbacksImpl::doneParsing() {
54085350 }
54095351
54105352 case CompletionKind::CaseStmtBeginning: {
5411- SourceLoc Loc = P.Context .SourceMgr .getCodeCompletionLoc ();
5412- Lookup.getValueCompletionsInDeclContext (Loc);
5413- Lookup.getTypeContextEnumElementCompletions (Loc);
5353+ ExprContextInfo ContextInfo (CurDeclContext, CodeCompleteTokenExpr);
5354+ Lookup.setExpectedTypes (ContextInfo.getPossibleTypes (),
5355+ ContextInfo.isSingleExpressionBody ());
5356+ Lookup.getUnresolvedMemberCompletions (ContextInfo.getPossibleTypes ());
5357+ DoPostfixExprBeginning ();
54145358 break ;
54155359 }
54165360
0 commit comments