Skip to content

Commit 2127e9f

Browse files
Varunramfelixmulder
authored andcommitted
Prevent mismatches on members named md (#2526)
* Prevent mismatches on members name md * Minor fixes in spacing and indentation
1 parent 3d00bd6 commit 2127e9f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

doc-tool/src/dotty/tools/dottydoc/staticsite/MarkdownLinkVisitor.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,28 @@ import com.vladsch.flexmark.util.sequence.CharSubSequence
77
import model.{ Package, NonEntity, Val, Def, TypeAlias }
88
import dottydoc.util.MemberLookup
99

10+
import dotty.tools.dotc.core.Contexts.Context
11+
import dotty.tools.dotc.core.Decorators._
12+
1013
object MarkdownLinkVisitor {
1114
private val EntityLink = """([^\.]+)(\.[^\.]+)*""".r
12-
def apply(node: Node, docs: Map[String, Package], params: Map[String, AnyRef]): Unit =
15+
def apply(node: Node, docs: Map[String, Package], params: Map[String, AnyRef])(implicit ctx: Context): Unit =
1316
(new NodeVisitor(
1417
new VisitHandler(classOf[Link], new Visitor[Link] with MemberLookup {
1518
override def visit(node: Link): Unit = {
1619
val url = node.getUrl
17-
if (url.endsWith(".md")) node.setUrl {
18-
url.subSequence(0, url.lastIndexOf('.')).append(".html")
20+
21+
if (url.endsWith(".md")) {
22+
if (url.subSequence(0, url.lastIndexOf('.')).indexOf("/") < 0) {
23+
val method = url.subSequence(0, url.lastIndexOf('.')).toString.toTypeName
24+
if (ctx.getClassIfDefined(method).exists) node.setUrl {
25+
url.subSequence(0, url.lastIndexOf('.')).append(".html")
26+
} else {
27+
ctx.error(s"""Ambiguous reference to "$url"""")
28+
}
29+
} else node.setUrl {
30+
url.subSequence(0, url.lastIndexOf('.')).append(".html")
31+
}
1932
}
2033
else if (EntityLink.unapplySeq(url.toString).isDefined) {
2134
lookup(NonEntity, docs, url.toString).foreach { ent =>

0 commit comments

Comments
 (0)