@@ -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 ();
@@ -2588,7 +2592,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2588
2592
}
2589
2593
bool implicitlyAsync = false ;
2590
2594
analyzeActorIsolation (VD, VarType, implicitlyAsync, NotRecommended);
2591
- if (!NotRecommended && implicitlyAsync && !CanCurrDeclContextHandleAsync) {
2595
+ if (!isForCaching () && !NotRecommended && implicitlyAsync &&
2596
+ !CanCurrDeclContextHandleAsync) {
2592
2597
NotRecommended = NotRecommendedReason::InvalidAsyncContext;
2593
2598
}
2594
2599
@@ -2930,7 +2935,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2930
2935
else
2931
2936
addTypeAnnotation (Builder, AFT->getResult (), genericSig);
2932
2937
2933
- if (AFT->isAsync () && !CanCurrDeclContextHandleAsync) {
2938
+ if (! isForCaching () && AFT->isAsync () && !CanCurrDeclContextHandleAsync) {
2934
2939
Builder.setNotRecommended (NotRecommendedReason::InvalidAsyncContext);
2935
2940
}
2936
2941
};
@@ -3044,7 +3049,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3044
3049
bool implictlyAsync = false ;
3045
3050
analyzeActorIsolation (FD, AFT, implictlyAsync, NotRecommended);
3046
3051
3047
- if (!NotRecommended && !IsImplicitlyCurriedInstanceMethod &&
3052
+ if (!isForCaching () && !NotRecommended &&
3053
+ !IsImplicitlyCurriedInstanceMethod &&
3048
3054
((AFT && AFT->isAsync ()) || implictlyAsync) &&
3049
3055
!CanCurrDeclContextHandleAsync) {
3050
3056
NotRecommended = NotRecommendedReason::InvalidAsyncContext;
@@ -3244,7 +3250,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3244
3250
addTypeAnnotation (Builder, *Result, CD->getGenericSignatureOfContext ());
3245
3251
}
3246
3252
3247
- if (ConstructorType->isAsync () && !CanCurrDeclContextHandleAsync) {
3253
+ if (!isForCaching () && ConstructorType->isAsync () &&
3254
+ !CanCurrDeclContextHandleAsync) {
3248
3255
Builder.setNotRecommended (NotRecommendedReason::InvalidAsyncContext);
3249
3256
}
3250
3257
};
@@ -3295,7 +3302,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3295
3302
bool implictlyAsync = false ;
3296
3303
analyzeActorIsolation (SD, subscriptType, implictlyAsync, NotRecommended);
3297
3304
3298
- if (!NotRecommended && implictlyAsync && !CanCurrDeclContextHandleAsync) {
3305
+ if (!isForCaching () && !NotRecommended && implictlyAsync &&
3306
+ !CanCurrDeclContextHandleAsync) {
3299
3307
NotRecommended = NotRecommendedReason::InvalidAsyncContext;
3300
3308
}
3301
3309
@@ -7122,7 +7130,10 @@ void swift::ide::lookupCodeCompletionResultsFromModule(
7122
7130
CodeCompletionResultSink &targetSink, const ModuleDecl *module ,
7123
7131
ArrayRef<std::string> accessPath, bool needLeadingDot,
7124
7132
const DeclContext *currDeclContext) {
7125
- CompletionLookup Lookup (targetSink, module ->getASTContext (), currDeclContext);
7133
+ // Consisitently use the SourceFile as the decl context, to avoid decl
7134
+ // context specific behaviors.
7135
+ auto *SF = currDeclContext->getParentSourceFile ();
7136
+ CompletionLookup Lookup (targetSink, module ->getASTContext (), SF);
7126
7137
Lookup.lookupExternalModuleDecls (module , accessPath, needLeadingDot);
7127
7138
}
7128
7139
0 commit comments