Skip to content

Commit

Permalink
Fix some inherited members not showing in searchbar in Scaladoc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jchyb committed Feb 27, 2022
1 parent 48c65c4 commit 598b8d3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
9 changes: 9 additions & 0 deletions scaladoc-testcases/src/tests/inheritedMembersFromHidden.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package tests
package inheritedMembersFromHidden

private[inheritedMembersFromHidden] trait HiddenTrait { //unexpected
def method: Unit
= ???
}

object PublicObject extends HiddenTrait //expected: object PublicObject
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 598b8d3

Please sign in to comment.