Skip to content

Commit 8be7177

Browse files
committed
Move docstring parser to dottydoc miniphase
1 parent 5463b7a commit 8be7177

File tree

4 files changed

+70
-141
lines changed

4 files changed

+70
-141
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class DocCompiler extends Compiler {
3232
List(new DocImplicitsPhase),
3333
List(new DocASTPhase),
3434
List(DocMiniTransformations(new UsecasePhase,
35+
new DocstringPhase,
3536
new LinkReturnTypes,
3637
new LinkParamListTypes,
3738
new LinkImplicitlyAddedTypes,

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

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class DocASTPhase extends Phase {
1414
import model._
1515
import model.factories._
1616
import model.internal._
17-
import model.parsers.WikiParser
1817
import model.comment.Comment
1918
import dotty.tools.dotc.core.Flags
2019
import dotty.tools.dotc.ast.tpd._
@@ -23,20 +22,8 @@ class DocASTPhase extends Phase {
2322

2423
def phaseName = "docphase"
2524

26-
private[this] val commentParser = new WikiParser
27-
28-
/** Saves the commentParser function for later evaluation, for when the AST has been filled */
29-
def track(symbol: Symbol, ctx: Context, parent: Symbol = NoSymbol)(op: => Entity) = {
30-
val entity = op
31-
32-
if (entity != NonEntity)
33-
commentParser += (entity, symbol, parent, ctx)
34-
35-
entity
36-
}
37-
3825
/** Build documentation hierarchy from existing tree */
39-
def collect(tree: Tree, prev: List[String] = Nil)(implicit ctx: Context): Entity = track(tree.symbol, ctx) {
26+
def collect(tree: Tree, prev: List[String] = Nil)(implicit ctx: Context): Entity = {
4027
val implicitConversions = ctx.docbase.defs(tree.symbol)
4128

4229
def collectList(xs: List[Tree], ps: List[String]): List[Entity] =
@@ -58,30 +45,26 @@ class DocASTPhase extends Phase {
5845
val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private)
5946
.filterNot(_.symbol.owner.name.show == "Any")
6047
.map { meth =>
61-
track(meth.symbol, ctx, tree.symbol) {
62-
DefImpl(
63-
meth.symbol,
64-
meth.symbol.name.show,
65-
Nil,
66-
path(meth.symbol),
67-
returnType(meth.info),
68-
typeParams(meth.symbol),
69-
paramLists(meth.info),
70-
implicitlyAddedFrom = Some(returnType(meth.symbol.owner.info))
71-
)
72-
}
48+
DefImpl(
49+
meth.symbol,
50+
meth.symbol.name.show,
51+
Nil,
52+
path(meth.symbol),
53+
returnType(meth.info),
54+
typeParams(meth.symbol),
55+
paramLists(meth.info),
56+
implicitlyAddedFrom = Some(returnType(meth.symbol.owner.info))
57+
)
7358
}.toList
7459

7560
val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value =>
76-
track(value.symbol, ctx, tree.symbol) {
77-
ValImpl(
78-
value.symbol,
79-
value.symbol.name.show,
80-
Nil, path(value.symbol),
81-
returnType(value.info),
82-
implicitlyAddedFrom = Some(returnType(value.symbol.owner.info))
83-
)
84-
}
61+
ValImpl(
62+
value.symbol,
63+
value.symbol.name.show,
64+
Nil, path(value.symbol),
65+
returnType(value.info),
66+
implicitlyAddedFrom = Some(returnType(value.symbol.owner.info))
67+
)
8568
}
8669

8770
defs ++ vals
@@ -177,14 +160,7 @@ class DocASTPhase extends Phase {
177160
child <- parent.children
178161
} setParent(child, to = parent)
179162

180-
// (3) Create documentation template from docstrings, with internal links
181-
println("Generating documentation, this might take a while...")
182-
commentParser.parse(packages)
183-
184-
// (4) Clear caches
185-
commentParser.clear()
186-
187-
// (5) Update Doc AST in ctx.base
163+
// (3) Update Doc AST in ctx.base
188164
for (kv <- packages) ctx.docbase.packages += kv
189165

190166
// Return super's result
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package dotty.tools
2+
package dottydoc
3+
package core
4+
5+
import dotc.core.Contexts.Context
6+
import dotc.ast.tpd
7+
8+
import transform.DocMiniPhase
9+
import model._
10+
import model.internal._
11+
import model.factories._
12+
import model.comment._
13+
import dotty.tools.dotc.core.Symbols.Symbol
14+
import BodyParsers._
15+
16+
class DocstringPhase extends DocMiniPhase with CommentParser with CommentCleaner {
17+
private def parsedComment[E <: Entity](ent: E)(implicit ctx: Context): Option[Comment] =
18+
ctx.docbase.docstring(ent.symbol).map { cmt =>
19+
parse(ent, ctx.docbase.packages[Package].toMap, clean(cmt.raw), cmt.raw, cmt.pos)
20+
.toComment(_.toHtml(ent))
21+
}
22+
23+
override def transformPackage(implicit ctx: Context) = { case ent: PackageImpl =>
24+
ent.copy(comment = parsedComment(ent))
25+
}
26+
27+
override def transformClass(implicit ctx: Context) = { case ent: ClassImpl =>
28+
ent.copy(comment = parsedComment(ent))
29+
}
30+
31+
override def transformCaseClass(implicit ctx: Context) = { case ent: CaseClassImpl =>
32+
ent.copy(comment = parsedComment(ent))
33+
}
34+
35+
override def transformTrait(implicit ctx: Context) = { case ent: TraitImpl =>
36+
ent.copy(comment = parsedComment(ent))
37+
}
38+
39+
override def transformObject(implicit ctx: Context) = { case ent: ObjectImpl =>
40+
ent.copy(comment = parsedComment(ent))
41+
}
42+
43+
override def transformDef(implicit ctx: Context) = { case ent: DefImpl =>
44+
ent.copy(comment = parsedComment(ent))
45+
}
46+
47+
override def transformVal(implicit ctx: Context) = { case ent: ValImpl =>
48+
ent.copy(comment = parsedComment(ent))
49+
}
50+
}

dottydoc/src/dotty/tools/dottydoc/model/parsers.scala

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

0 commit comments

Comments
 (0)