Skip to content

Commit 8685409

Browse files
committed
Propage Doc cotnext aross codebsae
1 parent efd1596 commit 8685409

18 files changed

+137
-143
lines changed
Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,70 @@
11
package dotty.dokka
22

3+
import org.jetbrains.dokka._
4+
import org.jetbrains.dokka.DokkaSourceSetImpl
5+
import org.jetbrains.dokka.plugability.DokkaContext
6+
import java.io.File
7+
import collection.JavaConverters._
8+
import dotty.dokka.site.StaticSiteContext
39
import dotty.tools.dotc.core.Contexts._
410

5-
type DocContext = Context
11+
given compilerContext(using docContext: DocContext) as Context =
12+
docContext.compilerContext
13+
14+
given docContextFromDokka(using dokkaContext: DokkaContext) as DocContext =
15+
dokkaContext.getConfiguration.asInstanceOf[DocContext]
16+
17+
case class DocContext(args: Scala3doc.Args, compilerContext: Context)
18+
extends DokkaConfiguration:
19+
override def getOutputDir: File = args.output
20+
override def getCacheRoot: File = null
21+
override def getOfflineMode: Boolean = false
22+
override def getFailOnWarning: Boolean = false
23+
override def getSourceSets: JList[DokkaSourceSet] = JList(mkSourceSet)
24+
override def getModules: JList[DokkaConfiguration.DokkaModuleDescription] = JList()
25+
override def getPluginsClasspath: JList[File] = JList()
26+
override def getModuleName(): String = "ModuleName"
27+
override def getModuleVersion(): String = ""
28+
29+
lazy val sourceLinks: SourceLinks = SourceLinks.load(args)
30+
31+
lazy val displaySourceSets = getSourceSets.toDisplaySourceSet
32+
33+
val logger = new Scala3DocDokkaLogger(using compilerContext)
34+
35+
lazy val staticSiteContext = args.docsRoot.map(path => StaticSiteContext(
36+
File(path).getAbsoluteFile(),
37+
Set(mkSourceSet.asInstanceOf[SourceSetWrapper]),
38+
args,
39+
sourceLinks
40+
))
41+
42+
override def getPluginsConfiguration: JList[DokkaConfiguration.PluginConfiguration] =
43+
JList()
44+
45+
lazy val mkSourceSet: DokkaSourceSet =
46+
new DokkaSourceSetImpl(
47+
/*displayName=*/ args.name,
48+
/*sourceSetID=*/ new DokkaSourceSetID(args.name, "main"),
49+
/*classpath=*/ JList(),
50+
/*sourceRoots=*/ JSet(),
51+
/*dependentSourceSets=*/ JSet(),
52+
/*samples=*/ JSet(),
53+
/*includes=*/ JSet(),
54+
/*includeNonPublic=*/ true,
55+
/* changed because of exception in reportUndocumentedTransformer - there's 'when' which doesnt match because it contains only KotlinVisbility cases */
56+
/*reportUndocumented=*/ false,
57+
// Now all our packages are empty from dokka perspective
58+
/*skipEmptyPackages=*/ false,
59+
/*skipDeprecated=*/ true,
60+
/*jdkVersion=*/ 8,
61+
/*sourceLinks=*/ JSet(),
62+
/*perPackageOptions=*/ JList(),
63+
/*externalDocumentationLinks=*/ JSet(),
64+
/*languageVersion=*/ null,
65+
/*apiVersion=*/ null,
66+
/*noStdlibLink=*/ true,
67+
/*noJdkLink=*/ true,
68+
/*suppressedFiles=*/ JSet(),
69+
/*suppressedFiles=*/ Platform.jvm
70+
).asInstanceOf[DokkaSourceSet] // Why I do need to cast here? Kotlin magic?

scala3doc/src/dotty/dokka/DottyDokkaConfig.scala

Lines changed: 0 additions & 57 deletions
This file was deleted.

scala3doc/src/dotty/dokka/DottyDokkaPlugin.scala

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
4949
// Just turn off another translator since multiple overrides does not work
5050
val disableDescriptorTranslator = extend(
5151
_.extensionPoint(CoreExtensions.INSTANCE.getSourceToDocumentableTranslator)
52-
.fromRecipe(ctx => new ScalaModuleProvider(using ctx.config.docContext))
52+
.fromRecipe { case ctx as given DokkaContext => new ScalaModuleProvider }
5353
.overrideExtension(dokkaBase.getDescriptorToDocumentableTranslator)
5454
.name("disableDescriptorTranslator")
5555
)
@@ -63,14 +63,14 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
6363

6464
val ourSignatureProvider = extend(
6565
_.extensionPoint(dokkaBase.getSignatureProvider)
66-
.fromRecipe(ctx =>
67-
new ScalaSignatureProvider(ctx.single(dokkaBase.getCommentsToContentConverter), ctx.getLogger)
68-
).overrideExtension(dokkaBase.getKotlinSignatureProvider)
66+
.fromRecipe{ case ctx as given DokkaContext =>
67+
new ScalaSignatureProvider(ctx.single(dokkaBase.getCommentsToContentConverter))
68+
}.overrideExtension(dokkaBase.getKotlinSignatureProvider)
6969
)
7070

7171
val scalaResourceInstaller = extend(
7272
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
73-
.fromRecipe(ctx => new ScalaResourceInstaller(ctx.config.args))
73+
.fromRecipe{ case ctx as given DokkaContext => new ScalaResourceInstaller }
7474
.after(dokkaBase.getCustomResourceInstaller)
7575
)
7676

@@ -83,17 +83,14 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
8383

8484
val scalaDocumentableToPageTranslator = extend(
8585
_.extensionPoint(CoreExtensions.INSTANCE.getDocumentableToPageTranslator)
86-
.fromRecipe(ctx =>
86+
.fromRecipe { case ctx as given DokkaContext =>
8787
new DocumentableToPageTranslator {
8888
override def invoke(module: DModule): ModulePageNode = ScalaPageCreator(
8989
ctx.single(dokkaBase.getCommentsToContentConverter),
90-
ctx.single(dokkaBase.getSignatureProvider),
91-
ctx.getConfiguration.asInstanceOf[DottyDokkaConfig].sourceLinks,
92-
ctx.getLogger
90+
ctx.single(dokkaBase.getSignatureProvider)
9391
).pageForModule(module)
9492
}
95-
)
96-
.overrideExtension(dokkaBase.getDocumentableToPageTranslator)
93+
}.overrideExtension(dokkaBase.getDocumentableToPageTranslator)
9794
)
9895

9996
val packageHierarchyTransformer = extend(
@@ -111,7 +108,7 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
111108

112109
val ourRenderer = extend(
113110
_.extensionPoint(CoreExtensions.INSTANCE.getRenderer)
114-
.fromRecipe(ctx => ScalaHtmlRenderer(ctx, ctx.config.args))
111+
.fromRecipe { case ctx as given DokkaContext => new ScalaHtmlRenderer }
115112
.overrideExtension(dokkaBase.getHtmlRenderer)
116113
)
117114

@@ -129,7 +126,7 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
129126

130127
val customDocumentationProvider = extend(
131128
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
132-
.fromRecipe(c => SitePagesCreator(c.config.staticSiteContext))
129+
.fromRecipe{ case c as given DokkaContext => new SitePagesCreator }
133130
.name("customDocumentationProvider")
134131
.ordered(
135132
before = Seq(
@@ -144,7 +141,7 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
144141

145142
val customNavigation = extend(
146143
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
147-
.fromRecipe(c => NavigationCreator(c.config)) // Adding a parameter to constuctor to NavigationCreator failed inc compilation
144+
.fromRecipe{ case c as given DokkaContext => new NavigationCreator }
148145
.name("customNavigation")
149146
.ordered(
150147
before = Seq(
@@ -158,7 +155,7 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
158155

159156
val customDocumentationResources = extend(
160157
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
161-
.fromRecipe(c => SiteResourceManager(c.config.staticSiteContext))
158+
.fromRecipe{ case c as given DokkaContext => new SiteResourceManager }
162159
.name("customDocumentationResources")
163160
.after(
164161
scalaEmbeddedResourceAppender.getValue,
@@ -168,13 +165,10 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
168165

169166
val locationProvider = extend(
170167
_.extensionPoint(dokkaBase.getLocationProviderFactory)
171-
.fromRecipe(StaticSiteLocationProviderFactory(_))
168+
.fromRecipe { case c as given DokkaContext => new StaticSiteLocationProviderFactory }
172169
.overrideExtension(dokkaBase.getLocationProvider)
173170
)
174171

175-
extension (ctx: DokkaContext):
176-
def config = ctx.getConfiguration.asInstanceOf[DottyDokkaConfig]
177-
178172
// TODO (https://github.com/lampepfl/scala3doc/issues/232): remove once problem is fixed in Dokka
179173
extension [T] (builder: ExtensionBuilder[T]):
180174
def ordered(before: Seq[Extension[_, _, _]], after: Seq[Extension[_, _, _]]): ExtensionBuilder[T] =

scala3doc/src/dotty/dokka/Main.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import dotty.tools.dotc.core.Contexts._
2525
*
2626
* - [](package.DottyDokkaPlugin) is our class that Dokka calls back and which
2727
* actually generates the documentation.
28-
* - [](package.DottyDokkaConfig) is our config for Dokka.
28+
* - [](package.DocContext) is our config for Dokka
2929
*/
3030
object Main:
3131
def main(args: Array[String]): Unit =

scala3doc/src/dotty/dokka/Scala3doc.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import collection.immutable.ArraySeq
1111

1212
import java.nio.file.Files
1313

14+
import dotty.tools.dotc.core.Contexts._
1415
import dotty.tools.dotc.config.Settings._
1516
import dotty.tools.dotc.config.CommonScalaSettings
1617
import dotty.tools.dotc.report
1718
import dotty.tools.dotc.reporting.Reporter
1819

19-
class Scala3DocDokkaLogger(using DocContext) extends DokkaLogger:
20+
21+
class Scala3DocDokkaLogger(using Context) extends DokkaLogger:
2022
def debug(msg: String): Unit = report.debuglog(msg)
2123

2224
// We do not want errors from dokka (that are) not critical to fail our runs
@@ -67,7 +69,7 @@ object Scala3doc:
6769
revision: Option[String] = None
6870
)
6971

70-
def run(args: Array[String])(using DocContext): Reporter =
72+
def run(args: Array[String])(using ctx: Context): Reporter =
7173
val parsedArgs = Scala3docArgs.extract(args.toList)
7274

7375
def listTastyFiles(f: File): Seq[File] =
@@ -77,18 +79,19 @@ object Scala3doc:
7779
)
7880
val tastyFiles = parsedArgs.tastyFiles ++ parsedArgs.tastyDirs.flatMap(listTastyFiles)
7981

80-
val reporter = summon[DocContext].reporter
81-
if !reporter.hasErrors then
82+
if !ctx.reporter.hasErrors then
8283
val updatedArgs = parsedArgs.copy(tastyDirs = Nil, tastyFiles = tastyFiles)
8384

8485
if (parsedArgs.output.exists()) IO.delete(parsedArgs.output)
8586

8687
run(updatedArgs)
8788
report.inform("Done")
8889
else report.error("Failure")
89-
reporter
90+
ctx.reporter
91+
9092

91-
private [dokka] def run(args: Args)(using DocContext) =
92-
new DokkaGenerator(new DottyDokkaConfig(args, summon[DocContext]), new Scala3DocDokkaLogger).generate()
93+
private [dokka] def run(args: Args)(using ctx: Context) =
94+
val docContext = new DocContext(args, ctx)
95+
new DokkaGenerator(docContext, docContext.logger).generate()
9396

9497

scala3doc/src/dotty/dokka/ScalaModuleCreator.scala

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,21 @@ import collection.JavaConverters._
1515
import kotlin.coroutines.Continuation
1616
import dotty.tools.dotc.core.Contexts._
1717

18-
class ScalaModuleProvider(using DocContext) extends SourceToDocumentableTranslator:
18+
class ScalaModuleProvider(using ctx: DocContext) extends SourceToDocumentableTranslator:
1919
override def invoke(sourceSet: DokkaSourceSet, cxt: DokkaContext, unused: Continuation[? >: DModule]) =
20-
cxt.getConfiguration match
21-
case dottyConfig: DottyDokkaConfig =>
22-
val parser = new MarkdownParser(_ => null)
23-
val result = DokkaTastyInspector(sourceSet, parser, dottyConfig).result()
20+
val parser = new MarkdownParser(_ => null)
21+
val result = DokkaTastyInspector(sourceSet, parser).result()
2422

25-
def flattenMember(m: Member): Seq[(DRI, Member)] = (m.dri -> m) +: m.allMembers.flatMap(flattenMember)
23+
def flattenMember(m: Member): Seq[(DRI, Member)] = (m.dri -> m) +: m.allMembers.flatMap(flattenMember)
2624

27-
new DModule(
28-
sourceSet.getDisplayName,
29-
result.asJava,
30-
JMap(),
31-
null,
32-
sourceSet.toSet,
33-
PropertyContainer.Companion.empty() plus ModuleExtension(result.flatMap(flattenMember).toMap)
34-
)
35-
case _ =>
36-
???
25+
new DModule(
26+
sourceSet.getDisplayName,
27+
result.asJava,
28+
JMap(),
29+
null,
30+
sourceSet.toSet,
31+
PropertyContainer.Companion.empty() plus ModuleExtension(result.flatMap(flattenMember).toMap)
32+
)
3733

3834
object EmptyModuleProvider extends SourceToDocumentableTranslator:
3935
override def invoke(sourceSet: DokkaSourceSet, cxt: DokkaContext, unused: Continuation[? >: DModule]) =

scala3doc/src/dotty/dokka/preprocessors/ScalaResourceInstaller.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
77
import dotty.dokka.translators.FilterAttributes
88
import java.nio.file.Paths
99

10-
class ScalaResourceInstaller(args: Scala3doc.Args) extends PageTransformer:
10+
class ScalaResourceInstaller(using ctx: DocContext) extends PageTransformer:
1111
private def dottyRes(resourceName: String) =
1212
new RendererSpecificResourcePage(resourceName, java.util.ArrayList(), RenderingStrategy$Copy(s"/dotty_res/$resourceName"))
1313

@@ -23,7 +23,7 @@ class ScalaResourceInstaller(args: Scala3doc.Args) extends PageTransformer:
2323

2424
new RendererSpecificResourcePage("scripts/data.js", java.util.ArrayList(), RenderingStrategy$Write(s"var scala3DocData = $str"))
2525

26-
private def projectLogo = args.projectLogo.toSeq.map { path =>
26+
private def projectLogo = ctx.args.projectLogo.toSeq.map { path =>
2727
val fileName = Paths.get(path).getFileName()
2828
val strategy = new RenderingStrategy$Copy(path)
2929
new RendererSpecificResourcePage(s"project-logo/$fileName", JList(), strategy)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.jetbrains.dokka.transformers.pages.PageTransformer
99

1010
import scala.collection.JavaConverters._
1111

12-
class NavigationCreator(ctx: DottyDokkaConfig) extends PageTransformer:
12+
class NavigationCreator(using ctx: DocContext) extends PageTransformer:
1313

1414
private def processApiPages(pages: List[PageNode]): JList[NavigationNode] =
1515
def flatMapPackages(pn: PageNode): List[NavigationNode] =

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import org.jetbrains.dokka.model.Documentable
99
import org.jetbrains.dokka.pages._
1010

1111
import scala.collection.JavaConverters._
12-
import dotty.dokka.model.api._
1312

14-
15-
class SitePagesCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSiteProcessor(ctx):
13+
class SitePagesCreator(using ctx: DocContext) extends BaseStaticSiteProcessor:
1614
private def mkRootPage(input: RootPageNode, children: List[PageNode]): AContentPage =
1715
input match
1816
case input: ContentPage =>

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import org.jetbrains.dokka.pages._
1010
import scala.collection.JavaConverters._
1111
import dotty.dokka.model.api._
1212

13-
class SiteResourceManager(ctx: Option[StaticSiteContext])
14-
extends BaseStaticSiteProcessor(ctx):
13+
class SiteResourceManager(using ctx: DocContext) extends BaseStaticSiteProcessor:
1514
private def listResources(nodes: Seq[PageNode]): Set[String] =
1615
nodes.flatMap {
1716
case it: AContentPage =>
@@ -32,7 +31,7 @@ class SiteResourceManager(ctx: Option[StaticSiteContext])
3231
files.map(p => rootPath.relativize(p).toString).toList
3332

3433
val resources = images ++ listResources(input.getChildren.asScala.toList)
35-
println(s"#### $resources")
34+
3635
val resourcePages = resources.map { path =>
3736
val strategy = new RenderingStrategy.Copy(rootPath.resolve(path).toString)
3837
new RendererSpecificResourcePage(path, JList(), strategy)

0 commit comments

Comments
 (0)