Re-apply "[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863"

This commit is contained in:
Xi Ge
2016-03-25 11:44:56 -07:00
committed by Michael Ilseman
parent 0798b3c3ae
commit c94172869b
3 changed files with 34 additions and 7 deletions

View File

@@ -1604,10 +1604,22 @@ public:
}
}
bool isModuleLoaded(ASTContext &Ctx, clang::Module *M) {
return Ctx.getLoadedModule(llvm::makeArrayRef(
std::make_pair(Ctx.getIdentifier(M->getTopLevelModuleName()),
SourceLoc())));
void collectImportedModules(llvm::StringSet<> &ImportedModules) {
SmallVector<Module::ImportedModule, 16> Imported;
SmallVector<Module::ImportedModule, 16> FurtherImported;
CurrDeclContext->getParentSourceFile()->getImportedModules(Imported,
Module::ImportFilter::All);
while(!Imported.empty()) {
ModuleDecl *MD = Imported.front().second;
Imported.erase(Imported.begin());
if (!ImportedModules.insert(MD->getNameStr()).second)
continue;
FurtherImported.clear();
MD->getImportedModules(FurtherImported, Module::ImportFilter::Public);
for (auto SubMod : FurtherImported) {
Imported.push_back(SubMod);
}
}
}
void addImportModuleNames() {
@@ -1619,6 +1631,8 @@ public:
return LHS->getTopLevelModuleName().compare_lower(
RHS->getTopLevelModuleName()) < 0;
});
llvm::StringSet<> ImportedModules;
collectImportedModules(ImportedModules);
for (auto *M : Modules) {
if (M->isAvailable() &&
!M->getTopLevelModuleName().startswith("_") &&
@@ -1636,8 +1650,7 @@ public:
Builder.addTypeAnnotation("Module");
// Imported modules are not recommended.
Builder.setNotRecommended(isModuleLoaded(CurrDeclContext->
getASTContext(), M));
Builder.setNotRecommended(ImportedModules.count(MD->getNameStr()) != 0);
}
}
}
@@ -2492,7 +2505,7 @@ public:
addCompoundFunctionName(CD, Reason);
return;
}
if (auto MT = ExprType->getRValueType()->getAs<AnyMetatypeType>()) {
if (HaveDot) {
Type Ty;