Skip to content

Commit c576382

Browse files
committed
Cook comments before displaying in the IDE
1 parent e2c4368 commit c576382

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,16 @@ class DottyLanguageServer extends LanguageServer
347347
if (tpw == NoType) new Hover
348348
else {
349349
val symbol = Interactive.enclosingSourceSymbol(trees, pos)
350-
val docComment = ctx.docCtx.flatMap(_.docstring(symbol))
350+
val docComment = ctx.docCtx.flatMap(_.docstring(symbol)).map {
351+
case comment if !comment.isExpanded =>
352+
val typer = new Typer()
353+
val owner = symbol.owner
354+
val cookingCtx = ctx.withOwner(owner)
355+
typer.cookComment(symbol, owner)(cookingCtx)
356+
ctx.docCtx.get.docstring(symbol).get
357+
case comment =>
358+
comment
359+
}
351360
val markedStrings = docMarkedStrings(docComment, tpw.show.toString)
352361
new Hover(markedStrings.map(JEither.forRight(_)).asJava, null)
353362
}
@@ -468,9 +477,11 @@ object DottyLanguageServer {
468477

469478
private def docMarkedStrings(comment: Option[Comment], typeInfo: String): List[lsp4j.MarkedString] = {
470479

471-
val docHover = comment.map { comment =>
472-
new lsp4j.MarkedString("scala", comment.raw)
473-
}
480+
val docHover =
481+
for {
482+
cmt <- comment
483+
body <- cmt.expandedBody
484+
} yield new lsp4j.MarkedString("scala", body)
474485

475486
val typeInfoHover = new lsp4j.MarkedString()
476487
typeInfoHover.setValue(typeInfo)

language-server/test/dotty/tools/languageserver/HoverTest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,16 @@ class HoverTest {
7878
.hover(m6 to m7, "Int" :: Nil)
7979
}
8080

81+
@Test def documentationIsCooked: Unit = {
82+
code"""/** A class: $$Variable
83+
| * @define Variable Test
84+
| */
85+
|class ${m1}Foo${m2}
86+
|/** $$Variable */
87+
|class ${m3}Bar${m4} extends Foo
88+
""".withSource
89+
.hover(m1 to m2, "Foo" :: "/** A class: Test\n * */" :: Nil)
90+
.hover(m3 to m4, "Bar" :: "/** Test */" :: Nil)
91+
}
92+
8193
}

0 commit comments

Comments
 (0)