Skip to content

Commit d78e48f

Browse files
committed
Scaladoc: Fix locations of members with slashes
1 parent 7dffdb1 commit d78e48f

File tree

8 files changed

+47
-8
lines changed

8 files changed

+47
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package tests.externalStubs
2+
3+
trait \/
4+
5+
trait /\

scaladoc-testcases/src/tests/externalLocations/scaladoc2.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
package tests.externalScaladoc2
1+
package tests
2+
package externalScaladoc2
23

34
import scala.util.matching.*
5+
import externalStubs._
46

57
class Test {
68
def a: String = ???
@@ -10,5 +12,7 @@ class Test {
1012
def c: Regex.Match = ???
1113
}
1214

15+
class Test2 extends \/ with /\
16+
1317
abstract class MySeq[T] extends scala.collection.immutable.Seq[T]
1418

scaladoc-testcases/src/tests/externalLocations/scaladoc3.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
package tests.externalScaladoc3
1+
package tests
2+
package externalScaladoc3
23

34
import scala.util.matching.*
5+
import externalStubs._
46

57
class Test {
68
def a: String = ???
@@ -10,3 +12,5 @@ class Test {
1012
def c: Regex.Match = ???
1113
}
1214

15+
class Test2 extends \/ with /\
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package tests
2+
package slashMembers
3+
4+
class A
5+
6+
trait \/
7+
8+
trait /\

scaladoc/src/dotty/tools/scaladoc/renderers/Locations.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.nio.file.Path
1313
import java.nio.file.Files
1414
import java.io.File
1515
import scala.util.matching._
16+
import dotty.tools.scaladoc.util.Escape._
1617

1718
val UnresolvedLocationLink = "#"
1819

scaladoc/src/dotty/tools/scaladoc/tasty/SymOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class SymOpsWithLinkCache:
261261
else
262262
(sym.className, sym.anchor)
263263

264-
val location = sym.packageNameSplitted ++ className
264+
val location = (sym.packageNameSplitted ++ className).map(escapeFilename(_))
265265

266266
val externalLink = {
267267
import reflect._
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
package dotty.tools.scaladoc.util
22

33
object Escape:
4-
def escapeUrl(url: String) = url.replace("#","%23")
4+
def escapeUrl(url: String) = url
5+
.replace("#","%23")
6+
7+
def escapeFilename(filename: String) =
8+
val escaped = filename
9+
.replace("/", "$div")
10+
.replace("\\", "$bslash")
11+
if escaped != filename then escaped + "$" else escaped

scaladoc/test/dotty/tools/scaladoc/ExternalLocationProviderIntegrationTest.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,33 @@ class JavadocExternalLocationProviderIntegrationTest extends ExternalLocationPro
2525

2626
class Scaladoc2ExternalLocationProviderIntegrationTest extends ExternalLocationProviderIntegrationTest(
2727
"externalScaladoc2",
28-
List(".*scala.*::scaladoc2::https://www.scala-lang.org/api/current/"),
28+
List(
29+
".*scala/.*::scaladoc2::https://www.scala-lang.org/api/current/",
30+
".*externalStubs.*::scaladoc2::https://external.stubs/api/"
31+
),
2932
List(
3033
"https://www.scala-lang.org/api/current/scala/util/matching/Regex$$Match.html",
3134
"https://www.scala-lang.org/api/current/scala/Predef$.html#String",
3235
"https://www.scala-lang.org/api/current/scala/collection/immutable/Map.html",
3336
"https://www.scala-lang.org/api/current/scala/collection/IterableOnceOps.html#addString(b:StringBuilder,start:String,sep:String,end:String):StringBuilder",
34-
"https://www.scala-lang.org/api/current/scala/collection/IterableOnceOps.html#mkString(start:String,sep:String,end:String):String"
37+
"https://www.scala-lang.org/api/current/scala/collection/IterableOnceOps.html#mkString(start:String,sep:String,end:String):String",
38+
"https://external.stubs/api/tests/externalStubs/$div$bslash$.html",
39+
"https://external.stubs/api/tests/externalStubs/$bslash$div$.html"
3540
)
3641
)
3742

3843
class Scaladoc3ExternalLocationProviderIntegrationTest extends ExternalLocationProviderIntegrationTest(
3944
"externalScaladoc3",
40-
List(".*scala.*::scaladoc3::https://dotty.epfl.ch/api/"),
45+
List(
46+
".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/",
47+
".*externalStubs.*::scaladoc3::https://external.stubs/api/"
48+
),
4149
List(
4250
"https://dotty.epfl.ch/api/scala/collection/immutable/Map.html",
4351
"https://dotty.epfl.ch/api/scala/Predef$.html#String-0",
44-
"https://dotty.epfl.ch/api/scala/util/matching/Regex$$Match.html"
52+
"https://dotty.epfl.ch/api/scala/util/matching/Regex$$Match.html",
53+
"https://external.stubs/api/tests/externalStubs/$div$bslash$.html",
54+
"https://external.stubs/api/tests/externalStubs/$bslash$div$.html"
4555
)
4656
)
4757

0 commit comments

Comments
 (0)