@@ -132,31 +132,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
132132
133133 std::vector<std::pair<std::string, bool >> SubModuleNameVisibilityPairs;
134134
135- void addSuperKeyword (CodeCompletionResultSink &Sink) {
136- auto *DC = CurDeclContext->getInnermostTypeContext ();
137- if (!DC)
138- return ;
139- auto *CD = DC->getSelfClassDecl ();
140- if (!CD)
141- return ;
142- Type ST = CD->getSuperclass ();
143- if (ST.isNull () || ST->is <ErrorType>())
144- return ;
145-
146- CodeCompletionResultBuilder Builder (Sink, CodeCompletionResultKind::Keyword,
147- SemanticContextKind::CurrentNominal,
148- {});
149- if (auto *AFD = dyn_cast<AbstractFunctionDecl>(CurDeclContext)) {
150- if (AFD->getOverriddenDecl () != nullptr ) {
151- Builder.addFlair (CodeCompletionFlairBit::CommonKeywordAtCurrentPosition);
152- }
153- }
154-
155- Builder.setKeywordKind (CodeCompletionKeywordKind::kw_super);
156- Builder.addKeyword (" super" );
157- Builder.addTypeAnnotation (ST, PrintOptions ());
158- }
159-
160135 Optional<std::pair<Type, ConcreteDeclRef>> typeCheckParsedExpr () {
161136 assert (ParsedExpr && " should have an expression" );
162137
@@ -879,6 +854,32 @@ static void addExprKeywords(CodeCompletionResultSink &Sink, DeclContext *DC) {
879854 addKeyword (Sink, " await" , CodeCompletionKeywordKind::None, " " , flair);
880855}
881856
857+ static void addSuperKeyword (CodeCompletionResultSink &Sink, DeclContext *DC) {
858+ if (!DC)
859+ return ;
860+ auto *TC = DC->getInnermostTypeContext ();
861+ if (!TC)
862+ return ;
863+ auto *CD = TC->getSelfClassDecl ();
864+ if (!CD)
865+ return ;
866+ Type ST = CD->getSuperclass ();
867+ if (ST.isNull () || ST->is <ErrorType>())
868+ return ;
869+
870+ CodeCompletionResultBuilder Builder (Sink, CodeCompletionResultKind::Keyword,
871+ SemanticContextKind::CurrentNominal, {});
872+ if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC)) {
873+ if (AFD->getOverriddenDecl () != nullptr ) {
874+ Builder.addFlair (CodeCompletionFlairBit::CommonKeywordAtCurrentPosition);
875+ }
876+ }
877+
878+ Builder.setKeywordKind (CodeCompletionKeywordKind::kw_super);
879+ Builder.addKeyword (" super" );
880+ Builder.addTypeAnnotation (ST, PrintOptions ());
881+ }
882+
882883static void addOpaqueTypeKeyword (CodeCompletionResultSink &Sink) {
883884 addKeyword (Sink, " some" , CodeCompletionKeywordKind::None, " some" );
884885}
@@ -950,7 +951,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
950951 case CompletionKind::YieldStmtExpr:
951952 case CompletionKind::PostfixExprBeginning:
952953 case CompletionKind::ForEachSequence:
953- addSuperKeyword (Sink);
954+ addSuperKeyword (Sink, CurDeclContext );
954955 addLetVarKeywords (Sink);
955956 addExprKeywords (Sink, CurDeclContext);
956957 addAnyTypeKeyword (Sink, CurDeclContext->getASTContext ().TheAnyType );
@@ -1565,7 +1566,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
15651566 Lookup.setHaveLParen (false );
15661567
15671568 // Add any keywords that can be used in an argument expr position.
1568- addSuperKeyword (CompletionContext.getResultSink ());
1569+ addSuperKeyword (CompletionContext.getResultSink (), CurDeclContext );
15691570 addExprKeywords (CompletionContext.getResultSink (), CurDeclContext);
15701571
15711572 DoPostfixExprBeginning ();
@@ -1711,7 +1712,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
17111712 ContextInfo.isImplicitSingleExpressionReturn ());
17121713
17131714 // Add any keywords that can be used in an argument expr position.
1714- addSuperKeyword (CompletionContext.getResultSink ());
1715+ addSuperKeyword (CompletionContext.getResultSink (), CurDeclContext );
17151716 addExprKeywords (CompletionContext.getResultSink (), CurDeclContext);
17161717
17171718 DoPostfixExprBeginning ();
@@ -1769,7 +1770,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
17691770 Context.LangOpts .EnableExperimentalConcurrency ,
17701771 Context.LangOpts .EnableExperimentalDistributed );
17711772 addStmtKeywords (Sink, CurDeclContext, MaybeFuncBody);
1772- addSuperKeyword (Sink);
1773+ addSuperKeyword (Sink, CurDeclContext );
17731774 addLetVarKeywords (Sink);
17741775 addExprKeywords (Sink, CurDeclContext);
17751776 addAnyTypeKeyword (Sink, Context.TheAnyType );
0 commit comments