File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed
compiler/src/dotty/tools/dotc/interactive
src/dotty/tools/languageserver
test/dotty/tools/languageserver Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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, " " )
You can’t perform that action at this time.
0 commit comments