Skip to content

Commit c58a4fd

Browse files
committed
Cook documentation when displaying in REPL
1 parent 66d44a2 commit c58a4fd

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dotty.tools.repl
22

3-
import dotty.tools.backend.jvm.GenBCode
43
import dotty.tools.dotc.ast.Trees._
54
import dotty.tools.dotc.ast.{tpd, untpd}
65
import dotty.tools.dotc.ast.tpd.TreeOps
@@ -15,11 +14,10 @@ import dotty.tools.dotc.core.StdNames._
1514
import dotty.tools.dotc.core.Symbols._
1615
import dotty.tools.dotc.reporting.diagnostic.messages
1716
import dotty.tools.dotc.transform.PostTyper
18-
import dotty.tools.dotc.typer.{FrontEnd, ImportInfo}
17+
import dotty.tools.dotc.typer.{FrontEnd, ImportInfo, Typer}
1918
import dotty.tools.dotc.util.Positions._
2019
import dotty.tools.dotc.util.SourceFile
2120
import dotty.tools.dotc.{CompilationUnit, Compiler, Run}
22-
import dotty.tools.io._
2321
import dotty.tools.repl.results._
2422

2523
import scala.collection.mutable
@@ -196,13 +194,18 @@ class ReplCompiler extends Compiler {
196194
val stat = stats.last.asInstanceOf[tpd.Tree]
197195
if (stat.tpe.isError) stat.tpe.show
198196
else {
199-
val docCtx = ctx.docCtx.get
200197
val symbols = extractSymbols(stat)
201-
val doc = symbols.collectFirst {
202-
case sym if docCtx.docstrings.contains(sym) =>
203-
docCtx.docstrings(sym).raw
204-
}
205-
doc.getOrElse(s"// No doc for `${expr}`")
198+
val typer = new Typer()
199+
val doc = for {
200+
sym <- symbols
201+
owner = sym.owner
202+
cookingCtx = ctx.withOwner(owner)
203+
cooked <- typer.cookComment(sym, owner)(cookingCtx)
204+
body <- cooked.expandedBody
205+
} yield body
206+
207+
if (doc.hasNext) doc.next()
208+
else s"// No doc for `$expr`"
206209
}
207210

208211
case _ =>

compiler/test/dotty/tools/repl/DocTests.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ class DocTests extends ReplTest {
146146
assertEquals("/** doc0 */", doc("O.foo.bar"))
147147
}
148148

149+
@Test def docIsCooked =
150+
eval(
151+
"""/**
152+
| * An object
153+
| * @define Variable some-value
154+
| */
155+
|object Foo {
156+
| /** Expansion: $Variable */
157+
| def hello = "world"
158+
|}
159+
""".stripMargin).andThen { implicit s =>
160+
assertEquals("/** Expansion: some-value */", doc("Foo.hello"))
161+
}
162+
149163
private def eval(code: String): State =
150164
fromInitialState { implicit s => run(code) }
151165

0 commit comments

Comments
 (0)