mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863
Reported: http://stackoverflow.com/questions/36180575/struck-out-module-xcode-7-3
This commit is contained in:
@@ -1604,10 +1604,21 @@ 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());
|
||||
ImportedModules.insert(MD->getNameStr());
|
||||
FurtherImported.clear();
|
||||
MD->getImportedModules(FurtherImported, Module::ImportFilter::Public);
|
||||
for (auto SubMod : FurtherImported) {
|
||||
Imported.push_back(SubMod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addImportModuleNames() {
|
||||
@@ -1619,6 +1630,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 +1649,7 @@ public:
|
||||
Builder.addTypeAnnotation("Module");
|
||||
|
||||
// Imported modules are not recommended.
|
||||
Builder.setNotRecommended(isModuleLoaded(CurrDeclContext->
|
||||
getASTContext(), M));
|
||||
Builder.setNotRecommended(ImportedModules.count(MD->getNameStr()) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
test/IDE/Inputs/complete_import_multifile2.swift
Normal file
3
test/IDE/Inputs/complete_import_multifile2.swift
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
import Foo
|
||||
import Foo.FooSub
|
||||
11
test/IDE/complete_import_multifile1.swift
Normal file
11
test/IDE/complete_import_multifile1.swift
Normal file
@@ -0,0 +1,11 @@
|
||||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -F %S/Inputs/mock-sdk -code-completion-token=CLANG_IMPORT1 | FileCheck %s -check-prefix=CLANG_IMPORT1
|
||||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -second-source-filename %S/Inputs/complete_import_multifile2.swift -F %S/Inputs/mock-sdk -code-completion-token=CLANG_IMPORT1 | FileCheck %s -check-prefix=CLANG_IMPORT1
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import #^CLANG_IMPORT1^#
|
||||
|
||||
// CLANG_IMPORT1: Begin completions
|
||||
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[Foo]: Foo[#Module#]; name=Foo
|
||||
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[FooHelper]: FooHelper[#Module#]; name=FooHelper
|
||||
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[Bar]: Bar[#Module#]; name=Bar
|
||||
// CLANG_IMPORT1-NOT: SwiftShims
|
||||
Reference in New Issue
Block a user