Skip to content

Commit 54cc175

Browse files
committed
Generate documentation from TASTY in sbt plugin
1 parent f66225c commit 54cc175

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Driver {
6161
}
6262

6363
/** Setup extra classpath and figure out class names for tasty file inputs */
64-
private def fromTastySetup(fileNames0: List[String], ctx0: Context) = {
64+
protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) = {
6565
if (ctx0.settings.fromTasty.value(ctx0)) {
6666
// Resolve classpath and class names of tasty files
6767
val (classPaths, classNames) = fileNames0.map { name =>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
package dotty.tools.dotc.fromtasty
22

33
import dotty.tools.dotc.CompilationUnit
4+
import dotty.tools.dotc.core.Contexts.Context
45
import dotty.tools.dotc.util.NoSource
6+
import dotty.tools.io.Path
57

68
class TASTYCompilationUnit(val className: String) extends CompilationUnit(NoSource) {
79
override def toString: String = s"class file $className"
810
}
11+
object TASTYCompilationUnit {
12+
def apply(className: String)(implicit ctx: Context): Option[TASTYCompilationUnit] = {
13+
if (Path(className).exists) {
14+
ctx.inform(s"Ignoring $className: cannot create a `TASTYCompilationUnit` for a source file.")
15+
None
16+
} else {
17+
Some(new TASTYCompilationUnit(className))
18+
}
19+
}
20+
}

compiler/src/dotty/tools/dotc/fromtasty/TASTYRun.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ package fromtasty
55
import core.Contexts._
66

77
class TASTYRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
8-
override def compile(classNames: List[String]): Unit = {
9-
val units = classNames.map(new TASTYCompilationUnit(_))
8+
override def compile(classNames: List[String]) = {
9+
val units = classNames.flatMap(TASTYCompilationUnit(_)(ictx))
1010
compileUnits(units)
1111
}
1212
}

doc-tool/src/dotty/tools/dottydoc/DocDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DocDriver extends Driver {
2727
ctx.setProperty(ContextDoc, new ContextDottydoc)
2828

2929
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx)
30-
(fileNames, ctx)
30+
fromTastySetup(fileNames, ctx)
3131
}
3232

3333
override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,19 @@ object DottyPlugin extends AutoPlugin {
216216
old.withCircularDependencyLevel(sbt.librarymanagement.ivy.CircularDependencyLevel.Ignore)
217217
} else old
218218
}
219-
)
219+
) ++ inConfig(Compile)(docSettings) ++ inConfig(Test)(docSettings)
220220
}
221221

222+
private val docSettings = inTask(doc)(Seq(
223+
sources := {
224+
val _ = compile.value // Ensure that everything is compiled, so TASTy is available.
225+
val prev = sources.value
226+
val tastyFiles = (classDirectory.value ** "*tasty").get.map(_.getAbsoluteFile)
227+
prev ++ tastyFiles
228+
},
229+
scalacOptions += "-from-tasty"
230+
))
231+
222232
/** Fetch artefacts for scalaOrganization.value %% moduleName % scalaVersion.value */
223233
private def fetchArtifactsOf(moduleName: String) = Def.task {
224234
val dependencyResolution = Keys.dependencyResolution.value

0 commit comments

Comments
 (0)