Skip to content

Commit 242563e

Browse files
committed
Add support for backticks in scaladoc links
1 parent 1a3e63c commit 242563e

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/scaladoc/scala/tools/nsc/doc/base/MemberLookupBase.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ trait MemberLookupBase {
154154
result
155155
}
156156

157+
private def removeBackticks(member: String): String =
158+
if (member.matches("(`).+\\1"))
159+
member.substring(1, member.length() - 1)
160+
else member
161+
157162
private def lookupInTemplate(pos: Position, member: String, container: Symbol, strategy: SearchStrategy): List[Symbol] = {
158-
val name = member.stripSuffix("$").stripSuffix("!").stripSuffix("*")
163+
val name = removeBackticks(member.stripSuffix("$").stripSuffix("!").stripSuffix("*"))
159164
def signatureMatch(sym: Symbol): Boolean = externalSignature(sym).startsWith(name)
160165

161166
// We need to cleanup the bogus classes created by the .class file parser. For example, [[scala.Predef]] resolves

test/scaladoc/run/t12628.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Done.

test/scaladoc/run/t12628.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import scala.tools.nsc.doc.base._
2+
import scala.tools.nsc.doc.base.comment._
3+
import scala.tools.nsc.doc.model._
4+
import scala.tools.partest.ScaladocModelTest
5+
6+
object Test extends ScaladocModelTest {
7+
8+
override def code = """
9+
10+
package org.foo
11+
12+
class `Foo-Bar`
13+
14+
object Foo {
15+
/**
16+
* This returns [[org.foo.`Foo-Bar`]]
17+
*/
18+
def test(): `Foo-Bar` = ???
19+
}
20+
"""
21+
22+
def scaladocSettings = ""
23+
24+
def testModel(rootPackage: Package) = {
25+
import access._
26+
27+
val body = rootPackage._package("org")._package("foo")._object("Foo")._method("test").comment.get.body
28+
29+
val links = countLinksInBody(body, _.link.isInstanceOf[LinkToTpl[_]])
30+
assert(links == 1, links + " == 1 (links to Foo-Bar)")
31+
}
32+
}

0 commit comments

Comments
 (0)