Skip to content

Commit f5b63ce

Browse files
committed
Cook comments before displaying in the IDE
1 parent ea9d9ad commit f5b63ce

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 12 additions & 2 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) null // null here indicates that no response should be sent
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 content = hoverContent(tpw.show, docComment)
352362
new Hover(content, null)
353363
}
@@ -470,7 +480,7 @@ object DottyLanguageServer {
470480
val markup = new lsp4j.MarkupContent
471481
markup.setKind("markdown")
472482
markup.setValue((
473-
comment.map(_.raw) match {
483+
comment.flatMap(_.expandedBody) match {
474484
case Some(comment) =>
475485
s"""```scala
476486
|$typeInfo

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,16 @@ class HoverTest {
8989
.hover(m6 to m7, hoverContent("Int"))
9090
}
9191

92+
@Test def documentationIsCooked: Unit = {
93+
code"""/** A class: $$Variable
94+
| * @define Variable Test
95+
| */
96+
|class ${m1}Foo${m2}
97+
|/** $$Variable */
98+
|class ${m3}Bar${m4} extends Foo
99+
""".withSource
100+
.hover(m1 to m2, hoverContent("Foo", "/** A class: Test\n * */"))
101+
.hover(m3 to m4, hoverContent("Bar", "/** Test */"))
102+
}
103+
92104
}

0 commit comments

Comments
 (0)