From 598b8d3383c6331ef3aa8a4a81b2a603cac19e96 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Wed, 23 Feb 2022 11:33:33 +0100 Subject: [PATCH] Fix some inherited members not showing in searchbar in Scaladoc Allows to search for public members inherited from hidden classlikes in Scaladoc. Additionally, to avoid confusing users about the missing link in the "Inherited from:" field, a "(hidden)" adnotation was also added. A "inheritedMembersFromHidden" Signature Test was also added. --- .../src/tests/inheritedMembersFromHidden.scala | 9 +++++++++ scaladoc/src/dotty/tools/scaladoc/api.scala | 2 +- .../dotty/tools/scaladoc/renderers/MemberRenderer.scala | 4 +++- .../src/dotty/tools/scaladoc/renderers/Resources.scala | 2 +- .../dotty/tools/scaladoc/tasty/ClassLikeSupport.scala | 2 +- .../tools/scaladoc/translators/FilterAttributes.scala | 2 +- .../signatures/TranslatableSignaturesTestCases.scala | 2 ++ 7 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 scaladoc-testcases/src/tests/inheritedMembersFromHidden.scala diff --git a/scaladoc-testcases/src/tests/inheritedMembersFromHidden.scala b/scaladoc-testcases/src/tests/inheritedMembersFromHidden.scala new file mode 100644 index 000000000000..8658f300af73 --- /dev/null +++ b/scaladoc-testcases/src/tests/inheritedMembersFromHidden.scala @@ -0,0 +1,9 @@ +package tests +package inheritedMembersFromHidden + +private[inheritedMembersFromHidden] trait HiddenTrait { //unexpected + def method: Unit + = ??? +} + +object PublicObject extends HiddenTrait //expected: object PublicObject diff --git a/scaladoc/src/dotty/tools/scaladoc/api.scala b/scaladoc/src/dotty/tools/scaladoc/api.scala index 314dcc3c7261..a59f1512dbf9 100644 --- a/scaladoc/src/dotty/tools/scaladoc/api.scala +++ b/scaladoc/src/dotty/tools/scaladoc/api.scala @@ -82,7 +82,7 @@ enum Origin: case class Overridden(name: String, dri: DRI) -case class InheritedFrom(name: String, dri: DRI) +case class InheritedFrom(name: String, dri: DRI, isSourceSuperclassHidden: Boolean) case class Annotation(val dri: DRI, val params: List[Annotation.AnnotationParameter]) diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala index 19dd4e4b7403..1980459dd097 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala @@ -29,7 +29,9 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext case _ => Nil def inheritedFrom(m: Member) = m.inheritedFrom match - case Some(InheritedFrom(name, dri)) => tableRow("Inherited from:", signatureRenderer.renderLink(name, dri)) + case Some(InheritedFrom(name, dri, isSourceSuperclassHidden)) => + val hiddenNameSuffix = if isSourceSuperclassHidden then " (hidden)" else "" + tableRow("Inherited from:", signatureRenderer.renderLink(name + hiddenNameSuffix, dri)) case _ => Nil def docAttributes(m: Member): Seq[AppliedTag] = diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala index 5a5e60f08879..dcb9abb79f3b 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala @@ -150,7 +150,7 @@ trait Resources(using ctx: DocContext) extends Locations, Writer: val entry = mkEntry(member.dri, member.name, flattenToText(sig), descr, member.kind.name) val children = member .membersBy(m => m.kind != Kind.Package && !m.kind.isInstanceOf[Classlike]) - .filter(m => m.origin == Origin.RegularlyDefined && m.inheritedFrom.isEmpty) + .filter(m => m.origin == Origin.RegularlyDefined && m.inheritedFrom.fold(false)(_.isSourceSuperclassHidden)) Seq(entry) ++ children.flatMap(processMember) processMember(m) diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala index 31e27e234332..7d5886193c6b 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala @@ -183,7 +183,7 @@ trait ClassLikeSupport: } private def parseInheritedMember(c: ClassDef)(s: Tree): Option[Member] = - def inheritance = Some(InheritedFrom(s.symbol.owner.normalizedName, s.symbol.dri)) + def inheritance = Some(InheritedFrom(s.symbol.owner.normalizedName, s.symbol.dri, s.symbol.owner.isHiddenByVisibility)) processTreeOpt(s)(s match case c: ClassDef if c.symbol.shouldDocumentClasslike => Some(parseClasslike(c, signatureOnly = true)) case other => { diff --git a/scaladoc/src/dotty/tools/scaladoc/translators/FilterAttributes.scala b/scaladoc/src/dotty/tools/scaladoc/translators/FilterAttributes.scala index 1202e76a548c..7c43d378fab5 100644 --- a/scaladoc/src/dotty/tools/scaladoc/translators/FilterAttributes.scala +++ b/scaladoc/src/dotty/tools/scaladoc/translators/FilterAttributes.scala @@ -14,7 +14,7 @@ object FilterAttributes: Map("visibility" -> m.visibility.name) private def inheritedFrom(m: Member): Map[String, String] = m.inheritedFrom match - case Some(InheritedFrom(name, _)) => Map("inherited" -> name) + case Some(InheritedFrom(name, _, _)) => Map("inherited" -> name) case _ => Map.empty private def origin(m: Member): Map[String, String] = m.origin match diff --git a/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala b/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala index 699aff7b6cf6..958320a41bdc 100644 --- a/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala +++ b/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala @@ -58,6 +58,8 @@ class InheritanceLoop extends SignatureTest("inheritanceLoop", SignatureTest.all class InheritedMembers extends SignatureTest("inheritedMembers2", SignatureTest.all.filter(_ != "class"), sourceFiles = List("inheritedMembers1", "inheritedMembers2")) +class InheritedFromHiddenClasslike extends SignatureTest("inheritedMembersFromHidden", SignatureTest.all) + class ComplexNames extends SignatureTest("complexNames", Seq("def", "class")) class WrongDocumentationLinks extends SignatureTest("links", Seq("def"))