@@ -2079,6 +2079,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2079
2079
IncludeInstanceMembers = true ;
2080
2080
}
2081
2081
2082
+ bool isHiddenModuleName (Identifier Name) {
2083
+ return (Name.str ().startswith (" _" ) ||
2084
+ Name == Ctx.SwiftShimsModuleName ||
2085
+ Name.str () == SWIFT_ONONE_SUPPORT);
2086
+ }
2087
+
2082
2088
void addSubModuleNames (std::vector<std::pair<std::string, bool >>
2083
2089
&SubModuleNameVisibilityPairs) {
2084
2090
for (auto &Pair : SubModuleNameVisibilityPairs) {
@@ -2143,10 +2149,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2143
2149
2144
2150
auto mainModuleName = CurrModule->getName ();
2145
2151
for (auto ModuleName : ModuleNames) {
2146
- if (ModuleName.str ().startswith (" _" ) ||
2147
- ModuleName == mainModuleName ||
2148
- ModuleName == Ctx.SwiftShimsModuleName ||
2149
- ModuleName.str () == SWIFT_ONONE_SUPPORT)
2152
+ if (ModuleName == mainModuleName || isHiddenModuleName (ModuleName))
2150
2153
continue ;
2151
2154
2152
2155
auto MD = ModuleDecl::create (ModuleName, Ctx);
@@ -6231,6 +6234,25 @@ static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
6231
6234
llvm::SmallPtrSet<Identifier, 8 > seenModuleNames;
6232
6235
std::vector<RequestedCachedModule> RequestedModules;
6233
6236
6237
+ SmallPtrSet<ModuleDecl *, 4 > explictlyImportedModules;
6238
+ {
6239
+ // Collect modules directly imported in this SourceFile.
6240
+ SmallVector<ImportedModule, 4 > directImport;
6241
+ SF.getImportedModules (directImport,
6242
+ {ModuleDecl::ImportFilterKind::Default,
6243
+ ModuleDecl::ImportFilterKind::ImplementationOnly});
6244
+ for (auto import : directImport)
6245
+ explictlyImportedModules.insert (import .importedModule );
6246
+
6247
+ // Exclude modules implicitly imported in the current module.
6248
+ auto implicitImports = SF.getParentModule ()->getImplicitImports ();
6249
+ for (auto import : implicitImports.imports )
6250
+ explictlyImportedModules.erase (import .module .importedModule );
6251
+
6252
+ // Consider the current module "explicit".
6253
+ explictlyImportedModules.insert (SF.getParentModule ());
6254
+ }
6255
+
6234
6256
for (auto &Request: Lookup.RequestedCachedResults ) {
6235
6257
llvm::DenseSet<CodeCompletionCache::Key> ImportsSeen;
6236
6258
auto handleImport = [&](ImportedModule Import) {
@@ -6279,8 +6301,11 @@ static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
6279
6301
RequestedModules.push_back ({std::move (K), TheModule,
6280
6302
Request.OnlyTypes , Request.OnlyPrecedenceGroups });
6281
6303
6304
+ auto TheModuleName = TheModule->getName ();
6282
6305
if (Request.IncludeModuleQualifier &&
6283
- seenModuleNames.insert (TheModule->getName ()).second )
6306
+ (!Lookup.isHiddenModuleName (TheModuleName) ||
6307
+ explictlyImportedModules.contains (TheModule)) &&
6308
+ seenModuleNames.insert (TheModuleName).second )
6284
6309
Lookup.addModuleName (TheModule);
6285
6310
}
6286
6311
};
0 commit comments