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.
  • Loading branch information
jchyb committed Feb 23, 2022
1 parent 48c65c4 commit 78bd5a9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
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.isEmpty || m.inheritedFrom.get.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

0 comments on commit 78bd5a9

Please sign in to comment.