Skip to content

Commit b2fe7cb

Browse files
committed
Cook comments before displaying in the IDE
1 parent 10de931 commit b2fe7cb

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
@@ -367,7 +368,16 @@ class DottyLanguageServer extends LanguageServer
367368
if (tpw == NoType) null // null here indicates that no response should be sent
368369
else {
369370
val symbol = Interactive.enclosingSourceSymbol(trees, pos)
370-
val docComment = ctx.docCtx.flatMap(_.docstring(symbol))
371+
val docComment = ctx.docCtx.flatMap(_.docstring(symbol)).map {
372+
case comment if !comment.isExpanded =>
373+
val typer = new Typer()
374+
val owner = symbol.owner
375+
val cookingCtx = ctx.withOwner(owner)
376+
typer.cookComment(symbol, owner)(cookingCtx)
377+
ctx.docCtx.get.docstring(symbol).get
378+
case comment =>
379+
comment
380+
}
371381
val content = hoverContent(tpw.show, docComment)
372382
new Hover(content, null)
373383
}
@@ -490,7 +500,7 @@ object DottyLanguageServer {
490500
val markup = new lsp4j.MarkupContent
491501
markup.setKind("markdown")
492502
markup.setValue((
493-
comment.map(_.raw) match {
503+
comment.flatMap(_.expandedBody) match {
494504
case Some(comment) =>
495505
s"""```scala
496506
|$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)