diff options
5 files changed, 34 insertions, 7 deletions
diff --git a/dottydoc/js/src/html/Layout.scala b/dottydoc/js/src/html/Layout.scala index a57655d3f..3977878c2 100644 --- a/dottydoc/js/src/html/Layout.scala +++ b/dottydoc/js/src/html/Layout.scala @@ -62,7 +62,6 @@ object Index { def companionHref(m: Entity): Option[PackageMember] = { val pack = m.path.dropRight(1).mkString(".") - println(pack) ParsedIndex.packages.get(pack) .flatMap(_.children.find(e => e.name == m.name && e.path.last != m.path.last)) } diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala index 2e24d02d7..b585c2745 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala @@ -28,10 +28,23 @@ object Phases { /** Saves the commentParser function for later evaluation, for when the AST has been filled */ def track(symbol: Symbol, ctx: Context)(op: => Entity) = { val entity = op + val commentParser = { (entity: Entity, packs: Map[String, Package]) => wikiParser.parseHtml(symbol, entity, packs)(ctx) } - commentCache = commentCache + (entity -> commentParser) + + entity match { + case p: Package => + val path = p.path.mkString(".") + commentCache = commentCache + (packages.get(path).map { ex => + val children = (ex.children ::: p.children).distinct.sortBy(_.name) + Package(p.name, children, p.path, None) + }.getOrElse(p) -> commentParser) + case _ => + commentCache = commentCache + (entity -> commentParser) + } + + entity } diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyEntities.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyEntities.scala index 683fc6b19..7da961a98 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyEntities.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyEntities.scala @@ -88,7 +88,6 @@ final case class HtmlTag(data: String) extends Inline { final case class Summary(text: Inline) extends Inline sealed trait LinkTo -final case class LinkToMember(mbr: Entity, parent: Entity) extends LinkTo final case class LinkToEntity(entity: Entity) extends LinkTo final case class LinkToExternal(name: String, url: String) extends LinkTo final case class Tooltip(name: String) extends LinkTo diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyParsers.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyParsers.scala index 6e7988f43..3cfc34e41 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyParsers.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/BodyParsers.scala @@ -25,10 +25,15 @@ object BodyParsers { def enityLinkToHtml(target: Inline, link: LinkTo) = link match { case Tooltip(_) => inlineToHtml(target) case LinkToExternal(n, url) => s"""<a href="$url">$n</a>""" - case LinkToMember(mbr, parent) => - s"""<a href="${relativePath(parent)}#${mbr.name}">${mbr.name}</a>""" - case LinkToEntity(target: Entity) => - s"""<a href="${relativePath(target)}">${target.name}</a>""" + case LinkToEntity(t: Entity) => t match { + // Entity is a package member + case e: Entity with Members => + s"""<a href="${relativePath(t)}">${inlineToHtml(target)}</a>""" + // Entity is a Val / Def + case x => x.parent.fold(inlineToHtml(target)) { xpar => + s"""<a href="${relativePath(xpar)}#${x.name}">${inlineToHtml(target)}</a>""" + } + } } def relativePath(target: Entity) = diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/util/MemberLookup.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/util/MemberLookup.scala index ad8d99341..933ed682f 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/util/MemberLookup.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/util/MemberLookup.scala @@ -14,6 +14,10 @@ import model.comment._ import model.Entities._ trait MemberLookup { + /** Performs a lookup based on the provided (pruned) query string + * + * Will return a `Tooltip` if unsucessfull, otherwise a LinkToEntity or LinkToExternal + */ def lookup( entity: Entity, packages: Map[String, Package], @@ -23,9 +27,13 @@ trait MemberLookup { val notFound: LinkTo = Tooltip(query) val querys = query.split("\\.").toList + /** Looks for the specified entity among `ent`'s members */ def localLookup(ent: Entity with Members, searchStr: String): LinkTo = ent.members.find(_.name == searchStr).fold(notFound)(e => LinkToEntity(e)) + /** Looks for an entity down in the structure, if the search list is Nil, + * the search stops + */ def downwardLookup(ent: Entity with Members, search: List[String]): LinkTo = search match { case Nil => notFound @@ -39,6 +47,9 @@ trait MemberLookup { .fold(notFound)(e => downwardLookup(e, xs)) } + /** Finds package with longest matching name, then does downwardLookup in + * the package + */ def globalLookup: LinkTo = { def longestMatch(list: List[String]): List[String] = if (list == Nil) Nil |