From 887759eb35f58a2b0ba3986322caa4939630da3b Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 26 Apr 2016 16:11:52 +0200 Subject: Add recursive CLI args, move other doc args --- .../jvm/src/dotty/tools/dottydoc/DottyDoc.scala | 36 ++++++++++++-- .../jvm/src/dotty/tools/dottydoc/Settings.scala | 58 ---------------------- src/dotty/tools/dotc/config/ScalaSettings.scala | 50 +++++++++++++++++++ 3 files changed, 81 insertions(+), 63 deletions(-) delete mode 100644 dottydoc/jvm/src/dotty/tools/dottydoc/Settings.scala diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala index 394bd0195..61c49eaf0 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala @@ -7,7 +7,10 @@ import dotc.config.Printers.dottydoc import dotc.core.Contexts._ import dotc.core.Phases.Phase import dotc.typer.FrontEnd -import dotc.{Compiler, Driver} +import dotc.{Compiler, Driver, Run} +import io.PlainFile + +import scala.util.control.NonFatal /** Custom Compiler with phases for the documentation tool * @@ -27,17 +30,40 @@ case object DottyDocCompiler extends Compiler { List(new FrontEnd) :: List(new DocPhase) :: Nil + + override def newRun(implicit ctx: Context): Run = { + reset() + new DocRun(this)(rootContext) + } } -object DottyDoc extends Driver { - override protected def initCtx = - new InitialContext(new ContextBase, new DottyDocSettings) +class DocRun(comp: Compiler)(implicit ctx: Context) extends Run(comp)(ctx) { + def fromDirectory(f: String): List[String] = { + val file = new PlainFile(f) + + if (!file.isDirectory && f.endsWith(".scala")) List(f) + else if (!file.isDirectory) Nil + else file.iterator.flatMap { + case x if x.isDirectory => fromDirectory(x.canonicalPath) + case x => List(x.canonicalPath) + }.toList + } + /** If DocRecursive is set, then try to find all scala files! */ + override def compile(fileNames: List[String]): Unit = super.compile( + if (ctx.settings.DocRecursive.value) fileNames flatMap fromDirectory + else fileNames + ) +} + +object DottyDoc extends Driver { override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = { - val ctx = rootCtx.fresh + val ctx = rootCtx.fresh val summary = CompilerCommand.distill(args)(ctx) + ctx.setSettings(summary.sstate) ctx.setSetting(ctx.settings.YkeepComments, true) + val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx) (fileNames, ctx) } diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/Settings.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/Settings.scala deleted file mode 100644 index ac614f62e..000000000 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/Settings.scala +++ /dev/null @@ -1,58 +0,0 @@ -package dotty.tools -package dottydoc - -import dotc.core.Contexts.Context -import dotc.config.{ScalaSettings, Settings} -import Settings._ - -class DottyDocSettings extends ScalaSettings { - /** A setting that defines the overall title of the documentation, typically the name of the library being - * documented. */ - val doctitle = StringSetting ( - "-doc-title", - "title", - "The overall name of the Scaladoc site", - "" - ) - - /** A setting that defines the overall version number of the documentation, typically the version of the library being - * documented. */ - val docversion = StringSetting ( - "-doc-version", - "version", - "An optional version number, to be appended to the title", - "" - ) - - val docfooter = StringSetting ( - "-doc-footer", - "footer", - "A footer on every Scaladoc page, by default the EPFL/Lightbend copyright notice. Can be overridden with a custom footer.", - "" - ) - - val docUncompilable = StringSetting ( - "-doc-no-compile", - "path", - "A directory containing sources which should be parsed, no more (e.g. AnyRef.scala)", - "" - ) - - def uncompilableFiles(implicit ctx: Context) = docUncompilable.value match { - case "" => Nil - case path => io.Directory(path).deepFiles.filter(_ hasExtension "scala").toList - } - - val docExternalDoc = MultiStringSetting ( - "-doc-external-doc", - "external-doc", - "comma-separated list of classpath_entry_path#doc_URL pairs describing external dependencies." - ) - - val docAuthor = BooleanSetting("-author", "Include authors.", true) - - val docGroups = BooleanSetting ( - "-groups", - "Group similar functions together (based on the @group annotation)" - ) -} diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index d0c4cc02c..5af871189 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -196,4 +196,54 @@ class ScalaSettings extends Settings.SettingGroup { val YpresentationLog = StringSetting("-Ypresentation-log", "file", "Log presentation compiler events into file", "") val YpresentationReplay = StringSetting("-Ypresentation-replay", "file", "Replay presentation compiler events from file", "") val YpresentationDelay = IntSetting("-Ypresentation-delay", "Wait number of ms after typing before starting typechecking", 0, 0 to 999) + + /** Dottydoc specific settings */ + + val DocTitle = StringSetting ( + "-Ydoc-title", + "title", + "The overall name of the Scaladoc site", + "" + ) + + val DocVersion = StringSetting ( + "-Ydoc-version", + "version", + "An optional version number, to be appended to the title", + "" + ) + + val DocFooter = StringSetting ( + "-Ydoc-footer", + "footer", + "A footer on every Scaladoc page, by default the EPFL/Lightbend copyright notice. Can be overridden with a custom footer.", + "" + ) + + val DocUncompilable = StringSetting ( + "-Ydoc-no-compile", + "path", + "A directory containing sources which should be parsed, no more (e.g. AnyRef.scala)", + "" + ) + + val DocRecursive = BooleanSetting("-Ydoc-recursive", "Get all files from supplied directory") + + //def DocUncompilableFiles(implicit ctx: Context) = DocUncompilable.value match { + // case "" => Nil + // case path => io.Directory(path).deepFiles.filter(_ hasExtension "scala").toList + //} + + val DocExternalDoc = MultiStringSetting ( + "-Ydoc-external-doc", + "external-doc", + "comma-separated list of classpath_entry_path#doc_URL pairs describing external dependencies." + ) + + val DocAuthor = BooleanSetting("-Ydoc-author", "Include authors.", true) + + val DocGroups = BooleanSetting ( + "-Ydoc:groups", + "Group similar functions together (based on the @group annotation)" + ) } -- cgit v1.2.3