Skip to content

Commit c2d665e

Browse files
committed
Cook comments before displaying in the IDE
1 parent f1da1e1 commit c2d665e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import core._, core.Decorators.{sourcePos => _, _}
2222
import Comments._, Contexts._, Flags._, Names._, NameOps._, Symbols._, SymDenotations._, Trees._, Types._
2323
import classpath.ClassPathEntries
2424
import reporting._, reporting.diagnostic.MessageContainer
25+
import typer.Typer
2526
import util._
2627
import interactive._, interactive.InteractiveDriver._
2728
import Interactive.Include
@@ -347,7 +348,16 @@ class DottyLanguageServer extends LanguageServer
347348
if (tpw == NoType) new Hover
348349
else {
349350
val symbol = Interactive.enclosingSourceSymbol(trees, pos)
350-
val docComment = ctx.docCtx.flatMap(_.docstring(symbol))
351+
val docComment = ctx.docCtx.flatMap(_.docstring(symbol)).map {
352+
case comment if !comment.isExpanded =>
353+
val typer = new Typer()
354+
val owner = symbol.owner
355+
val cookingCtx = ctx.withOwner(owner)
356+
typer.cookComment(symbol, owner)(cookingCtx)
357+
ctx.docCtx.get.docstring(symbol).get
358+
case comment =>
359+
comment
360+
}
351361
val markedStrings = docMarkedStrings(docComment, tpw.show.toString)
352362
new Hover(markedStrings.map(JEither.forRight(_)).asJava, null)
353363
}
@@ -468,9 +478,11 @@ object DottyLanguageServer {
468478

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

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

475487
val typeInfoHover = new lsp4j.MarkedString()
476488
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)