@@ -1884,6 +1884,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
18841884 bool FoundFunctionsWithoutFirstKeyword = false ;
18851885
18861886private:
1887+ bool isForCaching () const {
1888+ return Kind == LookupKind::ImportFromModule;
1889+ }
1890+
18871891 void foundFunction (const AbstractFunctionDecl *AFD) {
18881892 FoundFunctionCalls = true ;
18891893 const DeclName Name = AFD->getName ();
@@ -2589,7 +2593,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
25892593 }
25902594 bool implicitlyAsync = false ;
25912595 analyzeActorIsolation (VD, VarType, implicitlyAsync, NotRecommended);
2592- if (!NotRecommended && implicitlyAsync && !CanCurrDeclContextHandleAsync) {
2596+ if (!isForCaching () && !NotRecommended && implicitlyAsync &&
2597+ !CanCurrDeclContextHandleAsync) {
25932598 NotRecommended = NotRecommendedReason::InvalidAsyncContext;
25942599 }
25952600
@@ -2931,7 +2936,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
29312936 else
29322937 addTypeAnnotation (Builder, AFT->getResult (), genericSig);
29332938
2934- if (AFT->isAsync () && !CanCurrDeclContextHandleAsync) {
2939+ if (! isForCaching () && AFT->isAsync () && !CanCurrDeclContextHandleAsync) {
29352940 Builder.setNotRecommended (NotRecommendedReason::InvalidAsyncContext);
29362941 }
29372942 };
@@ -3045,7 +3050,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
30453050 bool implictlyAsync = false ;
30463051 analyzeActorIsolation (FD, AFT, implictlyAsync, NotRecommended);
30473052
3048- if (!NotRecommended && !IsImplicitlyCurriedInstanceMethod &&
3053+ if (!isForCaching () && !NotRecommended &&
3054+ !IsImplicitlyCurriedInstanceMethod &&
30493055 ((AFT && AFT->isAsync ()) || implictlyAsync) &&
30503056 !CanCurrDeclContextHandleAsync) {
30513057 NotRecommended = NotRecommendedReason::InvalidAsyncContext;
@@ -3245,7 +3251,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
32453251 addTypeAnnotation (Builder, *Result, CD->getGenericSignatureOfContext ());
32463252 }
32473253
3248- if (ConstructorType->isAsync () && !CanCurrDeclContextHandleAsync) {
3254+ if (!isForCaching () && ConstructorType->isAsync () &&
3255+ !CanCurrDeclContextHandleAsync) {
32493256 Builder.setNotRecommended (NotRecommendedReason::InvalidAsyncContext);
32503257 }
32513258 };
@@ -3296,7 +3303,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
32963303 bool implictlyAsync = false ;
32973304 analyzeActorIsolation (SD, subscriptType, implictlyAsync, NotRecommended);
32983305
3299- if (!NotRecommended && implictlyAsync && !CanCurrDeclContextHandleAsync) {
3306+ if (!isForCaching () && !NotRecommended && implictlyAsync &&
3307+ !CanCurrDeclContextHandleAsync) {
33003308 NotRecommended = NotRecommendedReason::InvalidAsyncContext;
33013309 }
33023310
@@ -7123,7 +7131,10 @@ void swift::ide::lookupCodeCompletionResultsFromModule(
71237131 CodeCompletionResultSink &targetSink, const ModuleDecl *module ,
71247132 ArrayRef<std::string> accessPath, bool needLeadingDot,
71257133 const DeclContext *currDeclContext) {
7126- CompletionLookup Lookup (targetSink, module ->getASTContext (), currDeclContext);
7134+ // Consisitently use the SourceFile as the decl context, to avoid decl
7135+ // context specific behaviors.
7136+ auto *SF = currDeclContext->getParentSourceFile ();
7137+ CompletionLookup Lookup (targetSink, module ->getASTContext (), SF);
71277138 Lookup.lookupExternalModuleDecls (module , accessPath, needLeadingDot);
71287139}
71297140
0 commit comments