diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-02-18 12:39:34 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-02-18 13:37:51 +0100 |
commit | 1cfe82eadeb1a7823c9ac3f3f8f2c9f376238c71 (patch) | |
tree | c5cfee0499b7324673a77f42cfa58ac378b5f27a | |
parent | b624d4df1e2eb961023bedc60770f1bb1594bdd9 (diff) | |
download | scala-1cfe82eadeb1a7823c9ac3f3f8f2c9f376238c71.tar.gz scala-1cfe82eadeb1a7823c9ac3f3f8f2c9f376238c71.tar.bz2 scala-1cfe82eadeb1a7823c9ac3f3f8f2c9f376238c71.zip |
Add better hover-text in search results
6 files changed, 24 insertions, 27 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/base/comment/Comment.scala b/src/scaladoc/scala/tools/nsc/doc/base/comment/Comment.scala index 183297f2c3..81f8c3ec06 100644 --- a/src/scaladoc/scala/tools/nsc/doc/base/comment/Comment.scala +++ b/src/scaladoc/scala/tools/nsc/doc/base/comment/Comment.scala @@ -21,7 +21,7 @@ abstract class Comment { /** The main body of the comment that describes what the entity does and is. */ def body: Body - private def closeHtmlTags(inline: Inline) = { + private def closeHtmlTags(inline: Inline): Inline = { val stack = mutable.ListBuffer.empty[HtmlTag] def scan(i: Inline) { i match { diff --git a/src/scaladoc/scala/tools/nsc/doc/html/Page.scala b/src/scaladoc/scala/tools/nsc/doc/html/Page.scala index aeda84adaf..875d7919c2 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/Page.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/Page.scala @@ -7,6 +7,7 @@ package scala package tools.nsc.doc.html import scala.tools.nsc.doc.model._ +import scala.tools.nsc.doc.base.comment import java.io.{FileOutputStream, File} import scala.reflect.NameTransformer import java.nio.channels.Channels @@ -100,4 +101,16 @@ abstract class Page { } relativize(thisPage.path.reverse, destPath.reverse).mkString("/") } + + protected def inlineToStr(inl: comment.Inline): String = inl match { + case comment.Chain(items) => items flatMap (inlineToStr(_)) mkString "" + case comment.Italic(in) => inlineToStr(in) + case comment.Bold(in) => inlineToStr(in) + case comment.Underline(in) => inlineToStr(in) + case comment.Monospace(in) => inlineToStr(in) + case comment.Text(text) => text + case comment.Summary(in) => inlineToStr(in) + case comment.EntityLink(comment.Text(text), _) => text + case _ => inl.toString + } } diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala index 86251fe872..37ce28a838 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala @@ -995,17 +995,6 @@ trait EntityPage extends HtmlPage { case _ => block.toString } - private def inlineToStr(inl: comment.Inline): String = inl match { - case comment.Chain(items) => items flatMap (inlineToStr(_)) mkString "" - case comment.Italic(in) => inlineToStr(in) - case comment.Bold(in) => inlineToStr(in) - case comment.Underline(in) => inlineToStr(in) - case comment.Monospace(in) => inlineToStr(in) - case comment.Text(text) => text - case comment.Summary(in) => inlineToStr(in) - case _ => inl.toString - } - private def typeToHtmlWithStupidTypes(tpl: TemplateEntity, superTpl: TemplateEntity, superType: TypeEntity): NodeSeq = if (tpl.universe.settings.useStupidTypes.value) superTpl match { diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala index 413c0a19d1..2c38036bb6 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala @@ -31,11 +31,12 @@ class IndexScript(universe: doc.Universe, index: doc.Index) extends Page { val merged = mergeByQualifiedName(templates) val ary = merged.keys.toList.sortBy(_.toLowerCase).map(key => { - val pairs = merged(key).flatMap { t => + val pairs = merged(key).flatMap { t: DocTemplateEntity => Seq( kindToString(t) -> relativeLinkTo(t), "kind" -> kindToString(t), - "members" -> membersToJSON(t.members.filter(!_.isShadowedOrAmbiguousImplicit))) + "members" -> membersToJSON(t.members.filter(!_.isShadowedOrAmbiguousImplicit)), + "shortDescription" -> shortDesc(t)) } JSONObject(Map(pairs : _*) + ("name" -> key)) @@ -76,6 +77,11 @@ class IndexScript(universe: doc.Universe, index: doc.Index) extends Page { }) : _*) } + /** Gets the short description i.e. the first sentence of the docstring */ + def shortDesc(mbr: MemberEntity): String = mbr.comment.fold("") { c => + inlineToStr(c.short).replaceAll("\n", "") + } + /** Returns the json representation of the supplied members */ def membersToJSON(entities: List[MemberEntity]): JSONType = JSONArray(entities map memberToJSON) diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala index 33c13c3bf3..f5e909cf90 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala @@ -939,17 +939,6 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp case _ => block.toString } - private def inlineToStr(inl: comment.Inline): String = inl match { - case comment.Chain(items) => items flatMap (inlineToStr(_)) mkString "" - case comment.Italic(in) => inlineToStr(in) - case comment.Bold(in) => inlineToStr(in) - case comment.Underline(in) => inlineToStr(in) - case comment.Monospace(in) => inlineToStr(in) - case comment.Text(text) => text - case comment.Summary(in) => inlineToStr(in) - case _ => inl.toString - } - private def typeToHtmlWithStupidTypes(tpl: TemplateEntity, superTpl: TemplateEntity, superType: TypeEntity): NodeSeq = if (tpl.universe.settings.useStupidTypes.value) superTpl match { diff --git a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js index 7ba18a26d9..c23ece144a 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js +++ b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js @@ -352,7 +352,7 @@ function searchMembers(entities, regExp, pack) { nameElem.className = "entity"; var entityUrl = document.createElement("a"); - entityUrl.title = name; + entityUrl.title = entity.shortDescription ? entity.shortDescription : name; entityUrl.href = toRoot + entity[entity.kind]; entityUrl.appendChild(document.createTextNode(name)); @@ -484,7 +484,7 @@ function listItem(entity, regExp) { nameElem.className = "entity"; var entityUrl = document.createElement("a"); - entityUrl.title = name; + entityUrl.title = entity.shortDescription ? entity.shortDescription : name; entityUrl.href = toRoot + entity[entity.kind]; entityUrl.appendChild(document.createTextNode(name)); |