Skip to content

Commit f343e44

Browse files
committed
IDE: Show documentation for symbol on hover
1 parent 1dce677 commit f343e44

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
3131
override def sourcesRequired = false
3232

3333
private val myInitCtx: Context = {
34-
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive)
34+
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive).addMode(Mode.ReadComments)
3535
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
3636
val ctx = setup(settings.toArray, rootCtx)._2
3737
ctx.initialize()(ctx)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,17 @@ class DottyLanguageServer extends LanguageServer
340340
implicit val ctx = driver.currentCtx
341341

342342
val pos = sourcePosition(driver, uri, params.getPosition)
343-
val tp = Interactive.enclosingType(driver.openedTrees(uri), pos)
343+
val trees = driver.openedTrees(uri)
344+
val tp = Interactive.enclosingType(trees, pos)
344345
val tpw = tp.widenTermRefExpr
345346

346347
if (tpw == NoType) new Hover
347348
else {
349+
import dotty.tools.dotc.core.Comments._
350+
val symbol = Interactive.enclosingSourceSymbol(trees, pos)
351+
val doc = ctx.docCtx.flatMap(_.docstring(symbol)).map(_.raw + " / ").getOrElse("")
348352
val str = tpw.show.toString
349-
new Hover(List(JEither.forLeft(str)).asJava, null)
353+
new Hover(List(JEither.forLeft(doc + str)).asJava, null)
350354
}
351355
}
352356

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ class HoverTest {
99
@Test def hoverOnWhiteSpace0: Unit =
1010
code"$m1 $m2".withSource.hover(m1 to m2, "")
1111

12+
@Test def hoverOnClassShowsDoc: Unit = {
13+
code"""$m1 /** foo */ ${m2}class Foo $m3 $m4""".withSource
14+
.hover(m1 to m2, "")
15+
.hover(m2 to m3, "/** foo */ / Foo")
16+
.hover(m3 to m4, "")
17+
}
18+
1219
@Test def hoverOnClass0: Unit = {
1320
code"""$m1 ${m2}class Foo $m3 $m4""".withSource
1421
.hover(m1 to m2, "")

0 commit comments

Comments
 (0)