@@ -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);
@@ -6249,6 +6252,25 @@ static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
6249
6252
llvm::SmallPtrSet<Identifier, 8 > seenModuleNames;
6250
6253
std::vector<RequestedCachedModule> RequestedModules;
6251
6254
6255
+ SmallPtrSet<ModuleDecl *, 4 > explictlyImportedModules;
6256
+ {
6257
+ // Collect modules directly imported in this SourceFile.
6258
+ SmallVector<ImportedModule, 4 > directImport;
6259
+ SF.getImportedModules (directImport,
6260
+ {ModuleDecl::ImportFilterKind::Default,
6261
+ ModuleDecl::ImportFilterKind::ImplementationOnly});
6262
+ for (auto import : directImport)
6263
+ explictlyImportedModules.insert (import .importedModule );
6264
+
6265
+ // Exclude modules implicitly imported in the current module.
6266
+ auto implicitImports = SF.getParentModule ()->getImplicitImports ();
6267
+ for (auto import : implicitImports.imports )
6268
+ explictlyImportedModules.erase (import .module .importedModule );
6269
+
6270
+ // Consider the current module "explicit".
6271
+ explictlyImportedModules.insert (SF.getParentModule ());
6272
+ }
6273
+
6252
6274
for (auto &Request: Lookup.RequestedCachedResults ) {
6253
6275
llvm::DenseSet<CodeCompletionCache::Key> ImportsSeen;
6254
6276
auto handleImport = [&](ImportedModule Import) {
@@ -6297,8 +6319,11 @@ static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
6297
6319
RequestedModules.push_back ({std::move (K), TheModule,
6298
6320
Request.OnlyTypes , Request.OnlyPrecedenceGroups });
6299
6321
6322
+ auto TheModuleName = TheModule->getName ();
6300
6323
if (Request.IncludeModuleQualifier &&
6301
- seenModuleNames.insert (TheModule->getName ()).second )
6324
+ (!Lookup.isHiddenModuleName (TheModuleName) ||
6325
+ explictlyImportedModules.contains (TheModule)) &&
6326
+ seenModuleNames.insert (TheModuleName).second )
6302
6327
Lookup.addModuleName (TheModule);
6303
6328
}
6304
6329
};
0 commit comments