Skip to content

Show docs in the IDE #4648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
override def sourcesRequired = false

private val myInitCtx: Context = {
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive)
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive).addMode(Mode.ReadComments)
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
val ctx = setup(settings.toArray, rootCtx)._2
ctx.initialize()(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,17 @@ class DottyLanguageServer extends LanguageServer
implicit val ctx = driver.currentCtx

val pos = sourcePosition(driver, uri, params.getPosition)
val tp = Interactive.enclosingType(driver.openedTrees(uri), pos)
val trees = driver.openedTrees(uri)
val tp = Interactive.enclosingType(trees, pos)
val tpw = tp.widenTermRefExpr

if (tpw == NoType) new Hover
else {
import dotty.tools.dotc.core.Comments._
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the import at the top of the file.

val symbol = Interactive.enclosingSourceSymbol(trees, pos)
val doc = ctx.docCtx.flatMap(_.docstring(symbol)).map(_.raw + " / ").getOrElse("")
val str = tpw.show.toString
new Hover(List(JEither.forLeft(str)).asJava, null)
new Hover(List(JEither.forLeft(doc + str)).asJava, null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class HoverTest {
@Test def hoverOnWhiteSpace0: Unit =
code"$m1 $m2".withSource.hover(m1 to m2, "")

@Test def hoverOnClassShowsDoc: Unit = {
code"""$m1 /** foo */ ${m2}class Foo $m3 $m4""".withSource
.hover(m1 to m2, "")
.hover(m2 to m3, "/** foo */ / Foo")
.hover(m3 to m4, "")
}

@Test def hoverOnClass0: Unit = {
code"""$m1 ${m2}class Foo $m3 $m4""".withSource
.hover(m1 to m2, "")
Expand Down