diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-05-04 09:56:32 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-08-19 15:37:21 +0200 |
commit | 80b027f88ac86539ba0a51558564c6694cbfac9a (patch) | |
tree | 9cdc8237a8c576aad88de04a8571960648e15f80 /dottydoc | |
parent | cb42a04bfcd7548261cda15c489671b8ca09cd7e (diff) | |
download | dotty-80b027f88ac86539ba0a51558564c6694cbfac9a.tar.gz dotty-80b027f88ac86539ba0a51558564c6694cbfac9a.tar.bz2 dotty-80b027f88ac86539ba0a51558564c6694cbfac9a.zip |
Break out commentCache to CommentParser
Diffstat (limited to 'dottydoc')
-rw-r--r-- | dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala | 40 | ||||
-rw-r--r-- | dottydoc/jvm/src/dotty/tools/dottydoc/model/CommentParsers.scala | 39 |
2 files changed, 52 insertions, 27 deletions
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala index 1670313e1..7d97fab5e 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala @@ -13,11 +13,11 @@ import dotc.core.Symbols.Symbol object Phases { class DocPhase extends Phase { - import model.comment.Comment - import model.CommentParsers.wikiParser - import model.factories._ + import model.CommentParsers.WikiParser import model._ + import model.factories._ import model.internal._ + import model.comment.Comment import dotty.tools.dotc.core.Flags import dotty.tools.dotc.ast.tpd._ import util.traversing._ @@ -25,19 +25,15 @@ object Phases { def phaseName = "docphase" - private[this] var commentCache: Map[String, (Entity, Map[String, Package]) => Option[Comment]] = Map.empty + private[this] val commentParser = new WikiParser /** Saves the commentParser function for later evaluation, for when the AST has been filled */ def track(symbol: Symbol, ctx: Context)(op: => Entity) = { val entity = op - if (entity != NonEntity) { - val commentParser = { (entity: Entity, packs: Map[String, Package]) => - wikiParser.parseHtml(symbol, entity, packs)(ctx) - } + if (entity != NonEntity) + commentParser += (entity, symbol, ctx) - commentCache = commentCache + (entity.path.mkString(".") -> commentParser) - } entity } @@ -113,7 +109,7 @@ object Phases { override def run(implicit ctx: Context): Unit = { currentRun += 1 - println(s"Generating schema for ($currentRun/$totalRuns): ${ctx.compilationUnit.source.file.name}") + println(s"Compiling ($currentRun/$totalRuns): ${ctx.compilationUnit.source.file.name}") collect(ctx.compilationUnit.tpdTree) // Will put packages in `packages` var } @@ -123,17 +119,19 @@ object Phases { val compUnits = super.runOn(units) // (2) Set parent of all package children - println("Connecting parents to children, finding companions...") - for { - parent <- packages.values - child <- parent.children - } setParent(child, to = parent) + // + // This step is unnecessary for now - member `parent` is not being used + // + //println("Connecting parents to children, finding companions...") + //for { + // parent <- packages.values + // child <- parent.children + //} setParent(child, to = parent) // (3) Create documentation template from docstrings, with internal links - for { - pack <- packages.values - } mutateEntities(pack) { e => - val comment = commentCache(e.path.mkString("."))(e, packages) + println("Creating documentation...") + for (pack <- packages.values) mutateEntities(pack) { e => + val comment = commentParser.parse(e, packages) setComment(e, to = comment) } @@ -141,7 +139,7 @@ object Phases { util.IndexWriters.writeJs(packages, "../js/out") // (5) Clear caches - commentCache = Map.empty + commentParser.clear() // Return super's result compUnits diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/CommentParsers.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/CommentParsers.scala index e6adba977..029e6a9d6 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/CommentParsers.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/CommentParsers.scala @@ -10,19 +10,46 @@ object CommentParsers { import BodyParsers._ import model.internal._ - sealed class WikiParser - extends CommentCleaner with CommentParser with CommentExpander { - def parseHtml(sym: Symbol, entity: Entity, packages: Map[String, Package])(implicit ctx: Context): Option[Comment] = - ctx.base.docstring(sym).map { d => + class WikiParser extends CommentCleaner with CommentParser with CommentExpander { + private[this] var commentCache: Map[String, (Entity, Map[String, Package]) => Option[Comment]] = Map.empty + + /** Parses comment and returns the path to the entity with an optional comment + * + * The idea here is to use this fact to create `Future[Seq[(String, Option[Comment]]]` + * which can then be awaited near the end of the run - before the pickling. + */ + def parseHtml(sym: Symbol, entity: Entity, packages: Map[String, Package])(implicit ctx: Context): (String, Option[Comment]) = { + val cmt = ctx.base.docstring(sym).map { d => val expanded = expand(sym) val body = parse(entity, packages, clean(expanded), expanded, d.pos) val summary = body.summary.map(_.toHtml(entity)).getOrElse("") - body.toHtml(entity) match { + body.toHtml(entity) match { case "" => None case x => Some(Comment(x, summary)) } }.flatten + + (entity.path.mkString("."), cmt) } - val wikiParser = new WikiParser + + def add(entity: Entity, symbol: Symbol, ctx: Context): Unit = { + val commentParser = { (entity: Entity, packs: Map[String, Package]) => + parseHtml(symbol, entity, packs)(ctx)._2 + } + + val path = entity.path.mkString(".") + if (!commentCache.contains(path) || ctx.base.docstring(symbol).isDefined) + commentCache = commentCache + (path -> commentParser) + } + + def +=(entity: Entity, symbol: Symbol, ctx: Context) = add(entity, symbol, ctx) + + def parse(entity: Entity, packs: Map[String, Package]): Option[Comment] = + commentCache(entity.path.mkString("."))(entity, packs) + + def clear(): Unit = commentCache = Map.empty + + def size: Int = commentCache.size + } } |