[SourceKit][DocInfo] When the underlying type of a type alias decl exists, report the conformances of the underlying type. rdar://26408167 (#3394)

Showing only the conforming associated types provides
little information to doc viewers. This patch digs the
underlying type of an associated type to report the
conformance info of those.
This commit is contained in:
Xi Ge
2016-07-07 16:24:01 -07:00
committed by GitHub
parent 96fcc37759
commit 64efa48c65
5 changed files with 321 additions and 141 deletions

View File

@@ -445,6 +445,14 @@ static void passExtends(const ValueDecl *D, DocInfoConsumer &Consumer) {
Consumer.handleExtendsEntity(EntInfo);
}
static void passInheritsAndConformancesForValueDecl(const ValueDecl *VD,
DocInfoConsumer &Consumer) {
if (auto Overridden = VD->getOverriddenDecl())
passInherits(Overridden, Consumer);
passConforms(VD->getSatisfiedProtocolRequirements(/*Sorted=*/true),
Consumer);
}
static void reportRelated(ASTContext &Ctx,
const Decl *D,
const Decl* SynthesizedTarget,
@@ -461,15 +469,28 @@ static void reportRelated(ASTContext &Ctx,
passInherits(ED->getInherited(), Consumer);
} else if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
// If underlying type exists, report the inheritance and conformance of the
// underlying type.
auto Ty = TAD->getUnderlyingType();
if (Ty) {
if (auto NM = Ty->getCanonicalType()->getAnyNominal()) {
passInherits(NM->getInherited(), Consumer);
passConforms(NM->getSatisfiedProtocolRequirements(/*Sorted=*/true),
Consumer);
return;
}
}
// Otherwise, report the inheritance of the type alias itself.
passInheritsAndConformancesForValueDecl(TAD, Consumer);
} else if (const TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
passInherits(TD->getInherited(), Consumer);
passConforms(TD->getSatisfiedProtocolRequirements(/*Sorted=*/true),
Consumer);
} else if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (auto Overridden = VD->getOverriddenDecl())
passInherits(Overridden, Consumer);
passConforms(VD->getSatisfiedProtocolRequirements(/*Sorted=*/true),
Consumer);
passInheritsAndConformancesForValueDecl(VD, Consumer);
}
}