mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Move diagnoseMissingImportForMember() to Sema.
This will make it possible to use type checking APIs to determine the appropriate access level for suggested imports. NFC.
This commit is contained in:
@@ -4093,62 +4093,3 @@ version::Version ModuleDecl::getLanguageVersionBuiltWith() const {
|
||||
|
||||
return version::Version();
|
||||
}
|
||||
|
||||
bool swift::diagnoseMissingImportForMember(const ValueDecl *decl,
|
||||
const DeclContext *dc,
|
||||
SourceLoc loc) {
|
||||
if (decl->findImport(dc))
|
||||
return false;
|
||||
|
||||
auto &ctx = dc->getASTContext();
|
||||
auto definingModule = decl->getModuleContext();
|
||||
ctx.Diags.diagnose(loc, diag::candidate_from_missing_import,
|
||||
decl->getDescriptiveKind(), decl->getName(),
|
||||
definingModule);
|
||||
|
||||
SourceLoc bestLoc =
|
||||
ctx.Diags.getBestAddImportFixItLoc(decl, dc->getParentSourceFile());
|
||||
if (!bestLoc.isValid())
|
||||
return false;
|
||||
|
||||
llvm::SmallString<64> importText;
|
||||
|
||||
// Check other source files for import flags that should be applied to the
|
||||
// fix-it for consistency with the rest of the imports in the module.
|
||||
auto parentModule = dc->getParentModule();
|
||||
OptionSet<ImportFlags> flags;
|
||||
for (auto file : parentModule->getFiles()) {
|
||||
if (auto sf = dyn_cast<SourceFile>(file))
|
||||
flags |= sf->getImportFlags(definingModule);
|
||||
}
|
||||
|
||||
if (flags.contains(ImportFlags::Exported) ||
|
||||
parentModule->isClangOverlayOf(definingModule))
|
||||
importText += "@_exported ";
|
||||
if (flags.contains(ImportFlags::ImplementationOnly))
|
||||
importText += "@_implementationOnly ";
|
||||
if (flags.contains(ImportFlags::WeakLinked))
|
||||
importText += "@_weakLinked ";
|
||||
if (flags.contains(ImportFlags::SPIOnly))
|
||||
importText += "@_spiOnly ";
|
||||
|
||||
// FIXME: Access level should be considered, too.
|
||||
|
||||
// @_spi imports.
|
||||
if (decl->isSPI()) {
|
||||
auto spiGroups = decl->getSPIGroups();
|
||||
if (!spiGroups.empty()) {
|
||||
importText += "@_spi(";
|
||||
importText += spiGroups[0].str();
|
||||
importText += ") ";
|
||||
}
|
||||
}
|
||||
|
||||
importText += "import ";
|
||||
importText += definingModule->getName().str();
|
||||
importText += "\n";
|
||||
ctx.Diags.diagnose(bestLoc, diag::candidate_add_import, definingModule)
|
||||
.fixItInsert(bestLoc, importText);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user