Skip to content

Commit 28023b4

Browse files
committed
Support for -from-tasty in Dottydoc
Dottydoc can now be used in one of two ways: - By receiving a list of source files that will be parsed, typed, and for which the documentation will be generated - When `-from-tasty` is set, by receiving a list of fully qualified class names. The trees will be unpickled and the documentation will be generated.
1 parent 86c4e72 commit 28023b4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
3333
}
3434

3535
def alreadyLoaded(): None.type = {
36-
ctx.warning(s"sclass $className cannot be unpickled because it is already loaded")
36+
ctx.warning(s"class $className cannot be unpickled because it is already loaded")
3737
None
3838
}
3939

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ package dottydoc
33

44
import core._
55
import core.transform._
6+
import dotc.core.Contexts.Context
67
import dotc.core.Phases.Phase
7-
import dotc.Compiler
8+
import dotc.core.Mode
9+
import dotc.{Compiler, Run}
10+
11+
import dotty.tools.dotc.fromtasty.{ReadTastyTreesFromClasses, TASTYRun}
812

913
/** Custom Compiler with phases for the documentation tool
1014
*
@@ -20,6 +24,15 @@ import dotc.Compiler
2024
*/
2125
class DocCompiler extends Compiler {
2226

27+
override def newRun(implicit ctx: Context): Run = {
28+
if (ctx.settings.fromTasty.value) {
29+
reset()
30+
new TASTYRun(this, ctx.addMode(Mode.ReadPositions).addMode(Mode.ReadComments))
31+
} else {
32+
super.newRun
33+
}
34+
}
35+
2336
override protected def frontendPhases: List[List[Phase]] =
2437
List(new DocFrontEnd) :: Nil
2538

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools
22
package dottydoc
33

4+
import dotc.fromtasty.ReadTastyTreesFromClasses
45
import dotc.typer.FrontEnd
56
import dotc.core.Contexts.Context
67
import dotc.CompilationUnit
@@ -12,6 +13,16 @@ import dotc.CompilationUnit
1213
* `discardAfterTyper`.
1314
*/
1415
class DocFrontEnd extends FrontEnd {
16+
17+
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
18+
if (ctx.settings.fromTasty.value) {
19+
val fromTastyFrontend = new ReadTastyTreesFromClasses
20+
fromTastyFrontend.runOn(units)
21+
} else {
22+
super.runOn(units)
23+
}
24+
}
25+
1526
override protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) =
1627
unit.isJava
1728
}

0 commit comments

Comments
 (0)