Skip to content

Commit 7a2b0d6

Browse files
committed
Fixes and optimization
- Cache dri -> path transformations - compute graphs on demand not on initialization - change writter to writer
1 parent b94b597 commit 7a2b0d6

File tree

12 files changed

+46
-36
lines changed

12 files changed

+46
-36
lines changed

scala3doc/src/dotty/dokka/DRI.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ final case class DRI(
1717

1818
def isStaticFile = symbolUUID == staticFileSymbolUUID
1919

20+
def asFileLocation: String = location.replace(".","/")
21+
2022
object DRI:
21-
def forPath(path: Path) = DRI(location = path.toString, symbolUUID = staticFileSymbolUUID)
23+
def forPath(path: Path) =
24+
DRI(location = path.toString, symbolUUID = staticFileSymbolUUID)

scala3doc/src/dotty/dokka/SourceLinks.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ object SourceLinks:
156156
revision: Option[String],
157157
projectRoot: Path)(
158158
using Context): SourceLinks =
159-
// TODO ...
160159
val mappings = configs.map(str => str -> SourceLink.parse(str, revision))
161160

162161
val errors = mappings.collect {

scala3doc/src/dotty/dokka/model/api/api.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ extension (s: Signature)
129129

130130
case class LinkToType(signature: Signature, dri: DRI, kind: Kind)
131131
case class HierarchyGraph(edges: Seq[(LinkToType, LinkToType)]):
132-
def vertecies: Seq[LinkToType] = edges.flatten((a, b) => Seq(a, b)).distinct
133-
val verteciesWithId: Map[LinkToType, Int] = vertecies.zipWithIndex.toMap
132+
private def vertecies: Seq[LinkToType] = edges.flatten((a, b) => Seq(a, b)).distinct
133+
def verteciesWithId: Map[LinkToType, Int] = vertecies.zipWithIndex.toMap
134134
def +(edge: (LinkToType, LinkToType)): HierarchyGraph = HierarchyGraph((edges :+ edge).distinct)
135135
def ++(edges: Seq[(LinkToType, LinkToType)]): HierarchyGraph = edges.foldLeft(this) {
136136
case (acc, edge) => acc + edge

scala3doc/src/dotty/dokka/site/StaticSiteContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class StaticSiteContext(
143143
val strippedIndexes = trySuffix("index.html") ++ trySuffix("index.md")
144144

145145
(Seq(baseFile, mdFile) ++ strippedIndexes).filter(Files.exists(_)).map(driFor)
146-
}.toOption
146+
}.toOption.filter(_.nonEmpty)
147147
pathsDri.getOrElse(memberLinkResolver(link).toList)
148148

149149
def driFor(dest: Path): DRI =

scala3doc/src/dotty/dokka/tasty/TastyParser.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ case class DokkaTastyInspector()(using ctx: DocContext) extends DocTastyInspecto
8383
import symOps._
8484
Try(QueryParser(link).readQuery()).toOption.flatMap(q =>
8585
MemberLookup.lookupOpt(q, None).map{ case (sym, _) => sym.dri}
86-
)
86+
)
87+
8788
ctx.staticSiteContext.foreach(_.memberLinkResolver = driFor)
8889

8990
var alreadyProcessed = false

scala3doc/src/dotty/renderers/HtmlRenderer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ case class Page(link: Link, content: Member | ResolvedTemplate | String, childre
2525
case _ => true
2626

2727
class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx: DocContext)
28-
extends SiteRenderer, Resources, Locations, Writter:
28+
extends SiteRenderer, Resources, Locations, Writer:
2929
private val args = summon[DocContext].args
3030
val staticSite = summon[DocContext].staticSiteContext
3131

scala3doc/src/dotty/renderers/Locations.scala

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,28 @@ val UnresolvedLocationLink = "#"
2020
trait Locations(using ctx: DocContext):
2121
def members: Map[DRI, Member]
2222

23+
var cache = new JHashMap[DRI, Seq[String]]()
24+
2325
// TODO verify if location exisits
2426
def rawLocation(dri: DRI): Seq[String] =
25-
dri match
26-
case `docsDRI` => List("docs", "index")
27-
case `docsRootDRI` => List("index")
28-
case `apiPageDRI` => List("api", "index")
29-
case dri if dri.isStaticFile =>
30-
Paths.get(dri.location).iterator.asScala.map(_.toString).toList
31-
case dri =>
32-
val loc = dri.location
33-
val fqn = loc.split(Array('.')).toList match
34-
case List("<empty>") => List("index")
35-
case other => other
36-
37-
Seq("api") ++ fqn
27+
cache.get(dri) match
28+
case null =>
29+
val path = dri match
30+
case `docsDRI` => List("docs", "index")
31+
case `docsRootDRI` => List("index")
32+
case `apiPageDRI` => List("api", "index")
33+
case dri if dri.isStaticFile =>
34+
Paths.get(dri.location).iterator.asScala.map(_.toString).toList
35+
case dri =>
36+
val loc = dri.location
37+
val fqn = loc.split(Array('.')).toList match
38+
case List("<empty>") => List("index")
39+
case other => other
40+
41+
Seq("api") ++ fqn
42+
cache.put(dri, path)
43+
path
44+
case cached => cached
3845

3946
private def unknownPage(dri: DRI): String =
4047
// TODO we should switch that to warning probably or has dedicated setting
@@ -93,17 +100,12 @@ trait Locations(using ctx: DocContext):
93100
}
94101

95102
//TODO #263: Add anchor support
96-
def constructPathForScaladoc(dri: DRI): String = {
97-
val location = dri.location.replace(".","/")
98-
val anchor = dri.anchor
99-
docURL + location + extension
100-
}
103+
def constructPathForScaladoc(dri: DRI): String =
104+
docURL + dri.asFileLocation + extension
101105

102-
def constructPathForScala3doc(dri: DRI): String = {
103-
val location = dri.location.replace(".","/")
104-
val anchor = dri.anchor
105-
docURL + location + extension
106-
}
106+
// TODO Add tests for it!
107+
def constructPathForScala3doc(dri: DRI): String =
108+
docURL + dri.asFileLocation + extension + "#" + dri.anchor
107109

108110
link.kind match {
109111
case DocumentationKind.Javadoc => constructPathForJavadoc(dri)

scala3doc/src/dotty/renderers/Resources.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum Resource(val path: String):
2222
case File(override val path: String, file: Path) extends Resource(path)
2323
case URL(url: String) extends Resource(url)
2424

25-
trait Resources(using ctx: DocContext) extends Locations, Writter:
25+
trait Resources(using ctx: DocContext) extends Locations, Writer:
2626
private def dynamicJsData =
2727
// If data at any point will become more complex we should use a proper mapping
2828
val data: Map[String, Map[String, String]] =
@@ -109,7 +109,7 @@ trait Resources(using ctx: DocContext) extends Locations, Writter:
109109
def processPage(page: Page): Seq[PageEntry] =
110110
val res = page.content match
111111
case m: Member =>
112-
val descr = m.dri.location.replace("/", ".")
112+
val descr = m.dri.asFileLocation
113113
def processMember(member: Member): Seq[PageEntry] =
114114
val signatureBuilder = ScalaSignatureProvider.rawSignature(member, InlineSignatureBuilder()).asInstanceOf[InlineSignatureBuilder]
115115
val sig = Signature(member.kind.name, " ") ++ Seq(Link(member.name, member.dri)) ++ signatureBuilder.names.reverse

scala3doc/src/dotty/renderers/SiteRenderer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait SiteRenderer(using DocContext) extends Locations:
2929

3030
def siteContent(pageDri: DRI, content: ResolvedTemplate): AppliedTag =
3131
import content.ctx
32-
def tryAsDri(str: String) = // TODO Does not seem to work with links to API :(
32+
def tryAsDri(str: String) =
3333
val (path, prefix) = str match
3434
case HashRegex(path, prefix) => (path, prefix)
3535
case _ => (str, "")
@@ -51,5 +51,5 @@ trait SiteRenderer(using DocContext) extends Locations:
5151
Try(new URL(link)).getOrElse {
5252
if(link.startsWith("/")) element.attr("src", resolveLink(pageDri, link.drop(1)))
5353
}
54-
}// forrach does not work here
54+
}// foreach does not work here
5555
raw(document.outerHtml())

scala3doc/src/dotty/renderers/Writter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.io.File
99
import HTML._
1010

1111
// TODO be more clever about writting - make it much faster!
12-
trait Writter(using ctx: DocContext) extends Locations:
12+
trait Writer(using ctx: DocContext) extends Locations:
1313
private val args = summon[DocContext].args
1414

1515
private def dest(path: String) =

scala3doc/test-documentations/basic/docs/Adoc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ title: Adoc
33
---
44
# Header in Adoc
55

6+
[[tests.site.SomeClass]]
7+
68
And a text!

scala3doc/test/dotty/dokka/site/SiteGeneratationTest.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class SiteGeneratationTest extends BaseHtmlTest:
3232
}
3333

3434
def testDocPages()(using ProjectContext) =
35-
checkFile("docs/Adoc.html")(title = "Adoc", header = "Header in Adoc", parents = Seq(projectName))
3635
checkFile("docs/Adoc.html")(title = "Adoc", header = "Header in Adoc", parents = Seq(projectName))
3736
checkFile("docs/dir/index.html")(title = "A directory", header = "A directory", parents = Seq(projectName))
3837
checkFile("docs/dir/nested.html")(
@@ -69,6 +68,10 @@ class SiteGeneratationTest extends BaseHtmlTest:
6968
testDocIndexPage()
7069
testMainIndexPage()
7170
testApiPages()
71+
72+
withHtmlFile("docs/Adoc.html"){ content =>
73+
content.assertAttr("p a","href", "../api/tests/site/SomeClass.html")
74+
}
7275
}
7376

7477
@Test

0 commit comments

Comments
 (0)