File tree 3 files changed +14
-3
lines changed
compiler/src/dotty/tools/dotc/interactive
src/dotty/tools/languageserver
test/dotty/tools/languageserver
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 {
31
31
override def sourcesRequired = false
32
32
33
33
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 )
35
35
rootCtx.setSetting(rootCtx.settings.YretainTrees , true )
36
36
val ctx = setup(settings.toArray, rootCtx)._2
37
37
ctx.initialize()(ctx)
Original file line number Diff line number Diff line change @@ -340,13 +340,17 @@ class DottyLanguageServer extends LanguageServer
340
340
implicit val ctx = driver.currentCtx
341
341
342
342
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)
344
345
val tpw = tp.widenTermRefExpr
345
346
346
347
if (tpw == NoType ) new Hover
347
348
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(" " )
348
352
val str = tpw.show.toString
349
- new Hover (List (JEither .forLeft(str)).asJava, null )
353
+ new Hover (List (JEither .forLeft(doc + str)).asJava, null )
350
354
}
351
355
}
352
356
Original file line number Diff line number Diff line change @@ -9,6 +9,13 @@ class HoverTest {
9
9
@ Test def hoverOnWhiteSpace0 : Unit =
10
10
code " $m1 $m2" .withSource.hover(m1 to m2, " " )
11
11
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
+
12
19
@ Test def hoverOnClass0 : Unit = {
13
20
code """ $m1 ${m2}class Foo $m3 $m4""" .withSource
14
21
.hover(m1 to m2, " " )
You can’t perform that action at this time.
0 commit comments