@@ -1884,6 +1884,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1884
1884
bool FoundFunctionsWithoutFirstKeyword = false ;
1885
1885
1886
1886
private:
1887
+ bool isForCaching () const {
1888
+ return Kind == LookupKind::ImportFromModule;
1889
+ }
1890
+
1887
1891
void foundFunction (const AbstractFunctionDecl *AFD) {
1888
1892
FoundFunctionCalls = true ;
1889
1893
const DeclName Name = AFD->getName ();
@@ -2589,7 +2593,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2589
2593
}
2590
2594
bool implicitlyAsync = false ;
2591
2595
analyzeActorIsolation (VD, VarType, implicitlyAsync, NotRecommended);
2592
- if (!NotRecommended && implicitlyAsync && !CanCurrDeclContextHandleAsync) {
2596
+ if (!isForCaching () && !NotRecommended && implicitlyAsync &&
2597
+ !CanCurrDeclContextHandleAsync) {
2593
2598
NotRecommended = NotRecommendedReason::InvalidAsyncContext;
2594
2599
}
2595
2600
@@ -2931,7 +2936,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2931
2936
else
2932
2937
addTypeAnnotation (Builder, AFT->getResult (), genericSig);
2933
2938
2934
- if (AFT->isAsync () && !CanCurrDeclContextHandleAsync) {
2939
+ if (! isForCaching () && AFT->isAsync () && !CanCurrDeclContextHandleAsync) {
2935
2940
Builder.setNotRecommended (NotRecommendedReason::InvalidAsyncContext);
2936
2941
}
2937
2942
};
@@ -3045,7 +3050,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3045
3050
bool implictlyAsync = false ;
3046
3051
analyzeActorIsolation (FD, AFT, implictlyAsync, NotRecommended);
3047
3052
3048
- if (!NotRecommended && !IsImplicitlyCurriedInstanceMethod &&
3053
+ if (!isForCaching () && !NotRecommended &&
3054
+ !IsImplicitlyCurriedInstanceMethod &&
3049
3055
((AFT && AFT->isAsync ()) || implictlyAsync) &&
3050
3056
!CanCurrDeclContextHandleAsync) {
3051
3057
NotRecommended = NotRecommendedReason::InvalidAsyncContext;
@@ -3245,7 +3251,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3245
3251
addTypeAnnotation (Builder, *Result, CD->getGenericSignatureOfContext ());
3246
3252
}
3247
3253
3248
- if (ConstructorType->isAsync () && !CanCurrDeclContextHandleAsync) {
3254
+ if (!isForCaching () && ConstructorType->isAsync () &&
3255
+ !CanCurrDeclContextHandleAsync) {
3249
3256
Builder.setNotRecommended (NotRecommendedReason::InvalidAsyncContext);
3250
3257
}
3251
3258
};
@@ -3296,7 +3303,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3296
3303
bool implictlyAsync = false ;
3297
3304
analyzeActorIsolation (SD, subscriptType, implictlyAsync, NotRecommended);
3298
3305
3299
- if (!NotRecommended && implictlyAsync && !CanCurrDeclContextHandleAsync) {
3306
+ if (!isForCaching () && !NotRecommended && implictlyAsync &&
3307
+ !CanCurrDeclContextHandleAsync) {
3300
3308
NotRecommended = NotRecommendedReason::InvalidAsyncContext;
3301
3309
}
3302
3310
@@ -7123,7 +7131,10 @@ void swift::ide::lookupCodeCompletionResultsFromModule(
7123
7131
CodeCompletionResultSink &targetSink, const ModuleDecl *module ,
7124
7132
ArrayRef<std::string> accessPath, bool needLeadingDot,
7125
7133
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);
7127
7138
Lookup.lookupExternalModuleDecls (module , accessPath, needLeadingDot);
7128
7139
}
7129
7140
0 commit comments