Skip to content

Commit d0693c0

Browse files
abgruszeckiromanowski
authored andcommitted
Display tooltips for unresolved links
ScalaCommentToContentConverter needed to be refactored to inherit from DocTagToContentConverter (because our version of `buildContent` needs to always be called first before the super version, otherwise nested tags aren't seen by our implementation).
1 parent 22f2f62 commit d0693c0

File tree

5 files changed

+63
-23
lines changed

5 files changed

+63
-23
lines changed

scala3doc-testcases/src/tests/tests.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ package tests
4444
*
4545
* And yet another: [[example.level2.Documentation]].
4646
*
47-
* This is my friend: [[tests\.B\]]].
47+
* This is my friend: [[tests.B]].
4848
*
4949
* And this is his companion: [[tests.B$ link to the companion]].
5050
*
51+
* And this is a link that failed to resolve [[absent]].
52+
*
53+
* And this is a link that failed to parse [[#]].
54+
*
5155
* @author Gal Anonim
5256
* @version 1.0.0
5357
* @result A class doesn't actually have a result.
@@ -172,7 +176,7 @@ class Methods:
172176
*
173177
* Even though this line should be separated from previous one.
174178
*
175-
* @throws scala.Error Throws errors.
179+
* @throws java.lang.Error Throws errors.
176180
* @example
177181
* ```
178182
* (m : Methods).generic2(d(), e()): B

scala3doc/src/dotty/dokka/tasty/comments/BaseConverter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait BaseConverter {
1313
val msg = err.getMessage
1414
// TODO: for better experience we should show source location here
1515
println("WARN: " + msg)
16-
dkkd.A(List(dkk.text(queryStr)).asJava, Map("href" -> "#").asJava)
16+
dkkd.A(List(dkk.text(queryStr)).asJava, Map("title" -> msg, "href" -> "#").asJava)
1717
case Right(query) =>
1818
thunk(query)
1919
}

scala3doc/src/dotty/dokka/tasty/comments/MarkdownConverter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class MarkdownConverter(val repr: Repr) extends BaseConverter {
181181
dkkd.DocumentationLink(sym.dri, resolveBody(default = targetText), kt.emptyMap)
182182
case None =>
183183
println(s"WARN: Definition lookup for following query failed: $queryStr")
184-
dkkd.A(resolveBody(default = query.join), Map("href" -> "#").asJava)
184+
dkkd.A(resolveBody(default = query.join), Map("title" -> s"Definition was not found: $queryStr", "href" -> "#").asJava)
185185
}
186186
}
187187
}

scala3doc/src/dotty/dokka/transformers/ScalaCommentToContentConverter.scala

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,41 @@ import org.jetbrains.dokka.model.properties.PropertyContainer
66
import org.jetbrains.dokka.pages._
77
import collection.JavaConverters._
88
import org.jetbrains.dokka.base.transformers.pages.comments.{DocTagToContentConverter, CommentsToContentConverter}
9+
import org.jetbrains.dokka.model.properties.{PropertyContainer, ExtraProperty, ExtraProperty$Key, MergeStrategy}
910
import java.util.{Set => JSet, List => JList}
1011

12+
object ScalaCommentToContentConverter extends DocTagToContentConverter {
13+
override def buildContent(
14+
docTag: DocTag,
15+
dci: DCI,
16+
sourceSets: JSet[? <: DokkaConfiguration$DokkaSourceSet],
17+
styles: JSet[? <: Style],
18+
extra: PropertyContainer[ContentNode]
19+
): JList[ContentNode] = docTag match {
20+
case docTag: A =>
21+
val superRes = super.buildContent(docTag, dci, sourceSets, styles, extra).get(0)
22+
val res = superRes.withNewExtras(superRes.getExtra plus ExtraLinkAttributes(
23+
title = docTag.getParams.asScala.get("title")
24+
))
25+
List(res).asJava
26+
case h: Html => List(
27+
HtmlContentNode(
28+
h.getChildren.asScala.collect{case c: Text => c}.head.getBody,
29+
dci,
30+
sourceSets.asScala.toSet.toDisplay.asScala.toSet,
31+
styles.asScala.toSet
32+
)
33+
).asJava
34+
case other => super.buildContent(other, dci, sourceSets, styles, extra)
35+
}
1136

12-
object ScalaCommentToContentConverter extends CommentsToContentConverter:
13-
val defaultConverter = DocTagToContentConverter()
14-
override def buildContent(
15-
docTag: DocTag,
16-
dci: DCI,
17-
sourceSets: JSet[? <: DokkaConfiguration$DokkaSourceSet],
18-
styles: JSet[? <: Style],
19-
extra: PropertyContainer[ContentNode]
20-
): JList[ContentNode] = docTag match {
21-
case h: Html => List(
22-
HtmlContentNode(
23-
h.getChildren.asScala.collect{case c: Text => c}.head.getBody,
24-
dci,
25-
sourceSets.asScala.toSet.toDisplay.asScala.toSet,
26-
styles.asScala.toSet
27-
)
28-
).asJava
29-
case other => defaultConverter.buildContent(other, dci, sourceSets, styles, extra)
30-
}
37+
case class ExtraLinkAttributes(title: Option[String]) extends ExtraProperty[ContentNode] {
38+
def getKey() = LinkAttributesKey
39+
}
40+
41+
case object LinkAttributesKey extends ExtraProperty.Key[ContentNode, Null] {
42+
def mergeStrategyFor(left: Null, right: Null) = MergeStrategy.Fail(
43+
() => throw NotImplementedError(s"Property merging for $this is not implemented")
44+
).asInstanceOf[MergeStrategy[ContentNode]]
45+
}
46+
}

scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends SiteRenderer(ctx) {
158158
).toString
159159
}
160160

161+
override def buildResolvedLink(
162+
f: FlowContent,
163+
node: ContentResolvedLink,
164+
pageContext: ContentPage,
165+
sourceSetRestriction: JSet[DisplaySourceSet],
166+
): Unit = {
167+
import kotlinx.html.{Gen_consumer_tagsKt => dsl}
168+
val c = f.getConsumer
169+
val U = kotlin.Unit.INSTANCE
170+
dsl.a(c, node.getAddress, /*target*/ null, /*classes*/ null, { e =>
171+
import ScalaCommentToContentConverter._
172+
// node.getExtra.getMap.asScala.get(LinkAttributesKey)
173+
Option(node.get(LinkAttributesKey).asInstanceOf[ExtraLinkAttributes])
174+
.flatMap(_.title)
175+
.foreach(e.getAttributes.put("title", _))
176+
buildText(f, node.getChildren, pageContext, sourceSetRestriction)
177+
U
178+
})
179+
}
180+
161181
override def buildCodeBlock(
162182
f: FlowContent,
163183
code: ContentCodeBlock,

0 commit comments

Comments
 (0)