Skip to content

Commit a2b24a9

Browse files
committed
Implement working docs requiring manually specifying resources and template for html docs
1 parent 3dcc177 commit a2b24a9

File tree

9 files changed

+63
-98
lines changed

9 files changed

+63
-98
lines changed

bridge/src/main/scala/xsbt/ScaladocInterface.scala

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,39 @@ class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter)
2020
template.fold(writeJson(index, outputFolder)) { tpl =>
2121
buildDocs(outputFolder, tpl, resources, index)
2222
}
23+
} getOrElse {
24+
delegate.log(
25+
NoPosition,
26+
"No output folder set for API documentation (\"-d\" parameter should be passed to the documentation tool)",
27+
xsbti.Severity.Error
28+
)
2329
}
2430

31+
private[this] val NoPosition = new xsbti.Position {
32+
val line = xsbti.Maybe.nothing[Integer]
33+
val lineContent = ""
34+
val offset = xsbti.Maybe.nothing[Integer]
35+
val sourcePath = xsbti.Maybe.nothing[String]
36+
val sourceFile = xsbti.Maybe.nothing[java.io.File]
37+
val pointer = xsbti.Maybe.nothing[Integer]
38+
val pointerSpace = xsbti.Maybe.nothing[String]
39+
}
40+
41+
private def getStringSetting(name: String): Option[String] =
42+
args find (_.startsWith(name)) map (_.drop(name.length))
43+
2544
private def getOutputFolder(args: Array[String]): Option[String] =
26-
args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head)
45+
args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head.trim)
46+
47+
private def getTemplate(args: Array[String]): Option[String] =
48+
getStringSetting("-template:")
2749

28-
private def getTemplate(args: Array[String]): Option[String] = None
50+
private def getResources(args: Array[String]): List[String] =
51+
getStringSetting("-resources:").map { path =>
52+
val dir = new java.io.File(path)
53+
if (dir.exists && dir.isDirectory)
54+
dir.listFiles.filter(_.isFile).map(_.getAbsolutePath).toList
55+
else Nil
56+
}.getOrElse(Nil)
2957

30-
private def getResources(args: Array[String]): List[String] = Nil
3158
}

dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import _root_.java.util.{ Map => JMap }
2626
* 2. Create an AST that is serializable
2727
* 3. Serialize to JS object
2828
*/
29-
class DottyDocCompiler extends Compiler {
29+
class DocCompiler extends Compiler {
3030
override def phases: List[List[Phase]] = List(
3131
List(new DocFrontEnd),
3232
List(new DocImplicitsPhase),
@@ -36,38 +36,14 @@ class DottyDocCompiler extends Compiler {
3636
new LinkImplicitlyAddedTypes,
3737
new SortMembers))
3838
)
39-
40-
override def newRun(implicit ctx: Context): Run = {
41-
reset()
42-
new DocRun(this)(rootContext)
43-
}
4439
}
4540

4641
class DocFrontEnd extends FrontEnd {
4742
override protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) =
4843
unit.isJava
4944
}
5045

51-
class DocRun(comp: Compiler)(implicit ctx: Context) extends Run(comp)(ctx) {
52-
def fromDirectory(f: String): List[String] = {
53-
val file = new PlainFile(f)
54-
55-
if (!file.isDirectory && f.endsWith(".scala")) List(f)
56-
else if (!file.isDirectory) Nil
57-
else file.iterator.flatMap {
58-
case x if x.isDirectory => fromDirectory(x.canonicalPath)
59-
case x => List(x.canonicalPath)
60-
}.toList
61-
}
62-
63-
/** If DocRecursive is set, then try to find all scala files! */
64-
override def compile(fileNames: List[String]): Unit = super.compile(
65-
if (ctx.settings.DocRecursive.value) fileNames flatMap fromDirectory
66-
else fileNames
67-
)
68-
}
69-
70-
abstract class DottyDocDriver extends Driver {
46+
abstract class DocDriver extends Driver {
7147
import scala.collection.JavaConverters._
7248

7349
override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
@@ -81,7 +57,7 @@ abstract class DottyDocDriver extends Driver {
8157
(fileNames, ctx)
8258
}
8359

84-
override def newCompiler(implicit ctx: Context): Compiler = new DottyDocCompiler
60+
override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler
8561

8662

8763
def compiledDocs(args: Array[String]): collection.Map[String, Package] = {

dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dotty.tools.dottydoc.api.java;
22

3-
import dotty.tools.dottydoc.DottyDocDriver;
3+
import dotty.tools.dottydoc.DocDriver;
44
import dotty.tools.dottydoc.model.Package;
55
import dotty.tools.dottydoc.util.OutputWriter;
66
import java.util.Map;
77
import java.util.List;
88

99
/** FIXME: document me! */
10-
public class Dottydoc extends DottyDocDriver {
10+
public class Dottydoc extends DocDriver {
1111
public Map<String, Package> createIndex(String[] args) {
1212
return compiledDocsJava(args);
1313
}

dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dotty.tools.dottydoc.api.scala
22

3-
import dotty.tools.dottydoc.DottyDocDriver
3+
import dotty.tools.dottydoc.DocDriver
44
import dotty.tools.dottydoc.model.Package
55
import dotty.tools.dottydoc.util.OutputWriter
66

77
import scala.collection.Map
88

99
/** FIXME: document this class plz */
10-
trait Dottydoc extends DottyDocDriver {
10+
trait Dottydoc extends DocDriver {
1111
def createIndex(args: Array[String]): Map[String, Package] =
1212
compiledDocs(args)
1313

dottydoc/src/dotty/tools/dottydoc/core/OutputJsonPhase.scala

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

dottydoc/src/dotty/tools/dottydoc/core/PrintPhase.scala

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

dottydoc/test/BaseTest.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ trait DottyTest {
1717
val ctx = base.initialCtx.fresh
1818
ctx.setSetting(ctx.settings.language, List("Scala2"))
1919
ctx.setSetting(ctx.settings.YkeepComments, true)
20-
ctx.setSetting(ctx.settings.YDocNoWrite, true)
2120
base.initialize()(ctx)
2221
ctx
2322
}
2423

25-
private def compilerWithChecker(assertion: DocASTPhase => Unit) = new DottyDocCompiler {
24+
private def compilerWithChecker(assertion: DocASTPhase => Unit) = new DocCompiler {
2625
private[this] val docPhase = new DocASTPhase
2726

2827
override def phases =

dottydoc/test/WhitelistedStdLibMain.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object WhitelistedStandardLib extends dottydoc.api.java.Dottydoc {
77
import scala.collection.JavaConverters._
88

99
val files: List[String] = {
10-
val whitelist = "../test/dotc/scala-collections.whitelist"
10+
val whitelist = "./test/dotc/scala-collections.whitelist"
1111

1212
Source.fromFile(whitelist, "UTF8")
1313
.getLines()
@@ -21,20 +21,20 @@ object WhitelistedStandardLib extends dottydoc.api.java.Dottydoc {
2121
}
2222

2323
private val resources = List(
24-
"../../dottydoc-client/resources/MaterialIcons-Regular.eot",
25-
"../../dottydoc-client/resources/MaterialIcons-Regular.ijmap",
26-
"../../dottydoc-client/resources/MaterialIcons-Regular.svg",
27-
"../../dottydoc-client/resources/MaterialIcons-Regular.ttf",
28-
"../../dottydoc-client/resources/MaterialIcons-Regular.woff",
29-
"../../dottydoc-client/resources/MaterialIcons-Regular.woff2",
30-
"../../dottydoc-client/resources/codepoints",
31-
"../../dottydoc-client/resources/github.css",
32-
"../../dottydoc-client/resources/highlight.pack.js",
33-
"../../dottydoc-client/resources/index.css",
34-
"../../dottydoc-client/resources/material-icons.css",
35-
"../../dottydoc-client/resources/material.min.css",
36-
"../../dottydoc-client/resources/material.min.js",
37-
"../../dottydoc-client/target/scala-2.11/dottydoc-client-fastopt.js"
24+
"../dottydoc-client/resources/MaterialIcons-Regular.eot",
25+
"../dottydoc-client/resources/MaterialIcons-Regular.ijmap",
26+
"../dottydoc-client/resources/MaterialIcons-Regular.svg",
27+
"../dottydoc-client/resources/MaterialIcons-Regular.ttf",
28+
"../dottydoc-client/resources/MaterialIcons-Regular.woff",
29+
"../dottydoc-client/resources/MaterialIcons-Regular.woff2",
30+
"../dottydoc-client/resources/codepoints",
31+
"../dottydoc-client/resources/github.css",
32+
"../dottydoc-client/resources/highlight.pack.js",
33+
"../dottydoc-client/resources/index.css",
34+
"../dottydoc-client/resources/material-icons.css",
35+
"../dottydoc-client/resources/material.min.css",
36+
"../dottydoc-client/resources/material.min.js",
37+
"../dottydoc-client/target/scala-2.11/dottydoc-client-fastopt.js"
3838
)
3939

4040
override def main(args: Array[String]) = {

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,16 @@ class ScalaSettings extends Settings.SettingGroup {
197197
val YpresentationReplay = StringSetting("-Ypresentation-replay", "file", "Replay presentation compiler events from file", "")
198198
val YpresentationDelay = IntSetting("-Ypresentation-delay", "Wait number of ms after typing before starting typechecking", 0, 0 to 999)
199199

200-
/** Dottydoc specific settings */
201-
val YDocNoWrite = BooleanSetting("-Ydoc-nowrite", "Doesn't write HTML files if set", false)
200+
/** Doc specific settings */
201+
val template = OptionSetting[String](
202+
"-template",
203+
"A mustache template for rendering each top-level entity in the API"
204+
)
205+
206+
val resources = OptionSetting[String](
207+
"-resources",
208+
"A directory containing static resources needed for the API documentation"
209+
)
202210

203211
val DocTitle = StringSetting (
204212
"-Ydoc-title",
@@ -235,8 +243,6 @@ class ScalaSettings extends Settings.SettingGroup {
235243
""
236244
)
237245

238-
val DocRecursive = BooleanSetting("-Ydoc-recursive", "Get all files from supplied directory")
239-
240246
//def DocUncompilableFiles(implicit ctx: Context) = DocUncompilable.value match {
241247
// case "" => Nil
242248
// case path => io.Directory(path).deepFiles.filter(_ hasExtension "scala").toList

0 commit comments

Comments
 (0)