Skip to content

Commit 6b59ea1

Browse files
committed
IDE: Show documentation for symbol on hover
1 parent deb9dc8 commit 6b59ea1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

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

340340
val pos = sourcePosition(driver, uri, params.getPosition)
341-
val tp = Interactive.enclosingType(driver.openedTrees(uri), pos)
341+
val trees = driver.openedTrees(uri)
342+
val tp = Interactive.enclosingType(trees, pos)
342343
val tpw = tp.widenTermRefExpr
343344

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

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)