Skip to content

Commit 8411a66

Browse files
committed
Cook documentation when displaying in REPL
1 parent b489a0b commit 8411a66

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
@@ -14,11 +13,10 @@ import dotty.tools.dotc.core.Phases.Phase
1413
import dotty.tools.dotc.core.StdNames._
1514
import dotty.tools.dotc.core.Symbols._
1615
import dotty.tools.dotc.reporting.diagnostic.messages
17-
import dotty.tools.dotc.typer.{FrontEnd, ImportInfo}
16+
import dotty.tools.dotc.typer.{FrontEnd, ImportInfo, Typer}
1817
import dotty.tools.dotc.util.Positions._
1918
import dotty.tools.dotc.util.SourceFile
2019
import dotty.tools.dotc.{CompilationUnit, Compiler, Run}
21-
import dotty.tools.io._
2220
import dotty.tools.repl.results._
2321

2422
import scala.collection.mutable
@@ -186,13 +184,18 @@ class ReplCompiler extends Compiler {
186184
val stat = stats.last.asInstanceOf[tpd.Tree]
187185
if (stat.tpe.isError) stat.tpe.show
188186
else {
189-
val docCtx = ctx.docCtx.get
190187
val symbols = extractSymbols(stat)
191-
val doc = symbols.collectFirst {
192-
case sym if docCtx.docstrings.contains(sym) =>
193-
docCtx.docstrings(sym).raw
194-
}
195-
doc.getOrElse(s"// No doc for `${expr}`")
188+
val typer = new Typer()
189+
val doc = for {
190+
sym <- symbols
191+
owner = sym.owner
192+
cookingCtx = ctx.withOwner(owner)
193+
cooked <- typer.cookComment(sym, owner)(cookingCtx)
194+
body <- cooked.expandedBody
195+
} yield body
196+
197+
if (doc.hasNext) doc.next()
198+
else s"// No doc for `$expr`"
196199
}
197200

198201
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)