Skip to content

Commit 1cfe82e

Browse files
committed
Add better hover-text in search results
1 parent b624d4d commit 1cfe82e

File tree

6 files changed

+24
-27
lines changed

6 files changed

+24
-27
lines changed

src/scaladoc/scala/tools/nsc/doc/base/comment/Comment.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class Comment {
2121
/** The main body of the comment that describes what the entity does and is. */
2222
def body: Body
2323

24-
private def closeHtmlTags(inline: Inline) = {
24+
private def closeHtmlTags(inline: Inline): Inline = {
2525
val stack = mutable.ListBuffer.empty[HtmlTag]
2626
def scan(i: Inline) {
2727
i match {

src/scaladoc/scala/tools/nsc/doc/html/Page.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package scala
77
package tools.nsc.doc.html
88

99
import scala.tools.nsc.doc.model._
10+
import scala.tools.nsc.doc.base.comment
1011
import java.io.{FileOutputStream, File}
1112
import scala.reflect.NameTransformer
1213
import java.nio.channels.Channels
@@ -100,4 +101,16 @@ abstract class Page {
100101
}
101102
relativize(thisPage.path.reverse, destPath.reverse).mkString("/")
102103
}
104+
105+
protected def inlineToStr(inl: comment.Inline): String = inl match {
106+
case comment.Chain(items) => items flatMap (inlineToStr(_)) mkString ""
107+
case comment.Italic(in) => inlineToStr(in)
108+
case comment.Bold(in) => inlineToStr(in)
109+
case comment.Underline(in) => inlineToStr(in)
110+
case comment.Monospace(in) => inlineToStr(in)
111+
case comment.Text(text) => text
112+
case comment.Summary(in) => inlineToStr(in)
113+
case comment.EntityLink(comment.Text(text), _) => text
114+
case _ => inl.toString
115+
}
103116
}

src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -995,17 +995,6 @@ trait EntityPage extends HtmlPage {
995995
case _ => block.toString
996996
}
997997

998-
private def inlineToStr(inl: comment.Inline): String = inl match {
999-
case comment.Chain(items) => items flatMap (inlineToStr(_)) mkString ""
1000-
case comment.Italic(in) => inlineToStr(in)
1001-
case comment.Bold(in) => inlineToStr(in)
1002-
case comment.Underline(in) => inlineToStr(in)
1003-
case comment.Monospace(in) => inlineToStr(in)
1004-
case comment.Text(text) => text
1005-
case comment.Summary(in) => inlineToStr(in)
1006-
case _ => inl.toString
1007-
}
1008-
1009998
private def typeToHtmlWithStupidTypes(tpl: TemplateEntity, superTpl: TemplateEntity, superType: TypeEntity): NodeSeq =
1010999
if (tpl.universe.settings.useStupidTypes.value)
10111000
superTpl match {

src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ class IndexScript(universe: doc.Universe, index: doc.Index) extends Page {
3131
val merged = mergeByQualifiedName(templates)
3232

3333
val ary = merged.keys.toList.sortBy(_.toLowerCase).map(key => {
34-
val pairs = merged(key).flatMap { t =>
34+
val pairs = merged(key).flatMap { t: DocTemplateEntity =>
3535
Seq(
3636
kindToString(t) -> relativeLinkTo(t),
3737
"kind" -> kindToString(t),
38-
"members" -> membersToJSON(t.members.filter(!_.isShadowedOrAmbiguousImplicit)))
38+
"members" -> membersToJSON(t.members.filter(!_.isShadowedOrAmbiguousImplicit)),
39+
"shortDescription" -> shortDesc(t))
3940
}
4041

4142
JSONObject(Map(pairs : _*) + ("name" -> key))
@@ -76,6 +77,11 @@ class IndexScript(universe: doc.Universe, index: doc.Index) extends Page {
7677
}) : _*)
7778
}
7879

80+
/** Gets the short description i.e. the first sentence of the docstring */
81+
def shortDesc(mbr: MemberEntity): String = mbr.comment.fold("") { c =>
82+
inlineToStr(c.short).replaceAll("\n", "")
83+
}
84+
7985
/** Returns the json representation of the supplied members */
8086
def membersToJSON(entities: List[MemberEntity]): JSONType =
8187
JSONArray(entities map memberToJSON)

src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -939,17 +939,6 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp
939939
case _ => block.toString
940940
}
941941

942-
private def inlineToStr(inl: comment.Inline): String = inl match {
943-
case comment.Chain(items) => items flatMap (inlineToStr(_)) mkString ""
944-
case comment.Italic(in) => inlineToStr(in)
945-
case comment.Bold(in) => inlineToStr(in)
946-
case comment.Underline(in) => inlineToStr(in)
947-
case comment.Monospace(in) => inlineToStr(in)
948-
case comment.Text(text) => text
949-
case comment.Summary(in) => inlineToStr(in)
950-
case _ => inl.toString
951-
}
952-
953942
private def typeToHtmlWithStupidTypes(tpl: TemplateEntity, superTpl: TemplateEntity, superType: TypeEntity): NodeSeq =
954943
if (tpl.universe.settings.useStupidTypes.value)
955944
superTpl match {

src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function searchMembers(entities, regExp, pack) {
352352
nameElem.className = "entity";
353353

354354
var entityUrl = document.createElement("a");
355-
entityUrl.title = name;
355+
entityUrl.title = entity.shortDescription ? entity.shortDescription : name;
356356
entityUrl.href = toRoot + entity[entity.kind];
357357
entityUrl.appendChild(document.createTextNode(name));
358358

@@ -484,7 +484,7 @@ function listItem(entity, regExp) {
484484
nameElem.className = "entity";
485485

486486
var entityUrl = document.createElement("a");
487-
entityUrl.title = name;
487+
entityUrl.title = entity.shortDescription ? entity.shortDescription : name;
488488
entityUrl.href = toRoot + entity[entity.kind];
489489

490490
entityUrl.appendChild(document.createTextNode(name));

0 commit comments

Comments
 (0)