Skip to content

Commit e7ddeb0

Browse files
committed
Generate documentation from TASTY in sbt plugin
1 parent e02c785 commit e7ddeb0

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
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 = 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import core.Contexts._
66

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

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,21 @@ object DottyPlugin extends AutoPlugin {
194194
} else {
195195
Def.task { si }
196196
}
197-
}.value
198-
)
197+
}.value,
198+
) ++ inConfig(Compile)(docSettings) ++ inConfig(Test)(docSettings)
199199
}
200200

201+
private val docSettings = inTask(doc)(Seq(
202+
scalacOptions := {
203+
val prev = scalacOptions.value
204+
val classNames = compile.value match { case analysis: sbt.internal.inc.Analysis => analysis.relations.classes._2s.toSeq }
205+
"-from-tasty" +: (classNames ++ prev)
206+
},
207+
// `doc` normally uses `dependencyClasspath`. However, we need the products for this project
208+
// to be on the classpath so that we can unpickle the doc from TASTY.
209+
dependencyClasspath := fullClasspath.value
210+
))
211+
201212
/** Fetch artefacts for scalaOrganization.value %% moduleName % scalaVersion.value */
202213
private def fetchArtifactsOf(moduleName: String) = Def.task {
203214
val dependencyResolution = Keys.dependencyResolution.value

0 commit comments

Comments
 (0)