Skip to content

Upgrade IDE dependencies, release vscode-dotty 0.1.5 #4828

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 2 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -222,7 +222,7 @@ class DottyLanguageServer extends LanguageServer


// FIXME: share code with messages.NotAMember
override def completion(params: TextDocumentPositionParams) = computeAsync { cancelToken =>
override def completion(params: CompletionParams) = computeAsync { cancelToken =>
val uri = new URI(params.getTextDocument.getUri)
val driver = driverFor(uri)
implicit val ctx = driver.currentCtx
Expand Down Expand Up @@ -344,12 +344,12 @@ class DottyLanguageServer extends LanguageServer
val tp = Interactive.enclosingType(trees, pos)
val tpw = tp.widenTermRefExpr

if (tpw == NoType) new Hover
if (tpw == NoType) null // null here indicates that no response should be sent
else {
val symbol = Interactive.enclosingSourceSymbol(trees, pos)
val docComment = ctx.docCtx.flatMap(_.docstring(symbol))
val markedStrings = docMarkedStrings(docComment, tpw.show.toString)
new Hover(markedStrings.map(JEither.forRight(_)).asJava, null)
val content = hoverContent(tpw.show, docComment)
new Hover(content, null)
}
}

Expand Down Expand Up @@ -459,26 +459,31 @@ object DottyLanguageServer {
CIK.Field
}

val label = sym.name.show.toString
val label = sym.name.show
val item = new lsp4j.CompletionItem(label)
item.setDetail(sym.info.widenTermRefExpr.show.toString)
item.setDetail(sym.info.widenTermRefExpr.show)
item.setKind(completionItemKind(sym))
item
}

private def docMarkedStrings(comment: Option[Comment], typeInfo: String): List[lsp4j.MarkedString] = {

val docHover = comment.map { comment =>
new lsp4j.MarkedString("scala", comment.raw)
}

val typeInfoHover = new lsp4j.MarkedString()
typeInfoHover.setValue(typeInfo)

typeInfoHover :: docHover.toList
private def hoverContent(typeInfo: String, comment: Option[Comment]): lsp4j.MarkupContent = {
val markup = new lsp4j.MarkupContent
markup.setKind("markdown")
markup.setValue((
comment.map(_.raw) match {
case Some(comment) =>
s"""```scala
|$typeInfo
|$comment
|```"""
Copy link
Contributor

Choose a reason for hiding this comment

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

There used to be a thin line that separated the type info from the comment. It would be nice to re-introduce it, since it makes the hover information easier to read:

case Some(comment) =>
  s"""```scala
     |$typeInfo
     |```
     |---
     |```scala
     |$comment
     |```"""

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried that but that's not equivalent to the thin line we had before: it adds a really thick line which I find distracting

Copy link
Member Author

Choose a reason for hiding this comment

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

There's an issue for this: microsoft/language-server-protocol#518

case None =>
s"""```scala
|$typeInfo
|```"""
}).stripMargin)
markup
}


/** Create an lsp4j.SymbolInfo from a Symbol and a SourcePosition */
def symbolInfo(sym: Symbol, pos: SourcePosition)(implicit ctx: Context): lsp4j.SymbolInformation = {
def symbolKind(sym: Symbol)(implicit ctx: Context): lsp4j.SymbolKind = {
Expand All @@ -498,10 +503,10 @@ object DottyLanguageServer {
SK.Field
}

val name = sym.name.show.toString
val name = sym.name.show
val containerName =
if (sym.owner.exists && !sym.owner.isEmptyPackage)
sym.owner.name.show.toString
sym.owner.name.show
else
null

Expand Down
57 changes: 34 additions & 23 deletions language-server/test/dotty/tools/languageserver/HoverTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,73 @@ import org.junit.Test
import dotty.tools.languageserver.util.Code._

class HoverTest {
def hoverContent(typeInfo: String, comment: String = ""): Option[String] =
Some((
if (comment == "")
s"""```scala
|$typeInfo
|```"""
else
s"""```scala
|$typeInfo
|$comment
|```""").stripMargin)

@Test def hoverOnWhiteSpace0: Unit =
code"$m1 $m2".withSource.hover(m1 to m2, Nil)
code"$m1 $m2".withSource.hover(m1 to m2, None)

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

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

@Test def hoverOnClass1: Unit = {
code"""$m1 ${m2}class Foo { } $m3 $m4""".withSource
.hover(m1 to m2, Nil)
.hover(m2 to m3, "Foo" :: Nil)
.hover(m3 to m4, Nil)
.hover(m1 to m2, None)
.hover(m2 to m3, hoverContent("Foo"))
.hover(m3 to m4, None)
}

@Test def hoverOnValDef0: Unit = {
code"""class Foo {
| ${m1}val x = ${m2}8$m3; ${m4}x$m5
|}""".withSource
.hover(m1 to m2, "Int" :: Nil)
.hover(m2 to m3, "Int(8)" :: Nil)
.hover(m4 to m5, "Int" :: Nil)
.hover(m1 to m2, hoverContent("Int"))
.hover(m2 to m3, hoverContent("Int(8)"))
.hover(m4 to m5, hoverContent("Int"))
}

@Test def hoverOnValDef1: Unit = {
code"""class Foo {
| ${m1}final val x = 8$m2; ${m3}x$m4
|}""".withSource
.hover(m1 to m2, "Int(8)" :: Nil)
.hover(m3 to m4, "Int(8)" :: Nil)
.hover(m1 to m2, hoverContent("Int(8)"))
.hover(m3 to m4, hoverContent("Int(8)"))
}

@Test def hoverOnDefDef0: Unit = {
code"""class Foo {
| ${m1}def x = ${m2}8$m3; ${m4}x$m5
|}""".withSource
.hover(m1 to m2, "Int" :: Nil)
.hover(m2 to m3, "Int(8)" :: Nil)
.hover(m4 to m5, "Int" :: Nil)
.hover(m1 to m2, hoverContent("Int"))
.hover(m2 to m3, hoverContent("Int(8)"))
.hover(m4 to m5, hoverContent("Int"))
}

@Test def hoverMissingRef0: Unit = {
code"""class Foo {
| ${m1}x$m2
|}""".withSource
.hover(m1 to m2, "<error not found: x>" :: Nil)
.hover(m1 to m2, hoverContent("<error not found: x>" ))
}

@Test def hoverFun0: Unit = {
Expand All @@ -72,10 +83,10 @@ class HoverTest {
| ${m5}y($m6)$m7
|}
""".withSource
.hover(m1 to m2, "String(\"abc\")" :: Nil)
.hover(m3 to m4, "String" :: Nil)
.hover(m5 to m6, "(): Int" :: Nil)
.hover(m6 to m7, "Int" :: Nil)
.hover(m1 to m2, hoverContent("String(\"abc\")" ))
.hover(m3 to m4, hoverContent("String"))
.hover(m5 to m6, hoverContent("(): Int"))
.hover(m6 to m7, hoverContent("Int"))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class CodeTester(sources: List[SourceWithPositions], actions: List[Action]) {
* Perform a hover over `range`, verifies that result matches `expected`.
*
* @param range The range over which to hover.
* @param expected The expected results.
* @param expected The expected result.
*
* @see dotty.tools.languageserver.util.actions.CodeHover
*/
def hover(range: CodeRange, expected: List[String]): this.type =
def hover(range: CodeRange, expected: Option[String]): this.type =
doAction(new CodeHover(range, expected))

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CodeCompletion(override val marker: CodeMarker,
expected: Set[(String, CompletionItemKind, String)]) extends ActionOnMarker {

override def execute(): Exec[Unit] = {
val result = server.completion(marker.toTextDocumentPositionParams).get()
val result = server.completion(marker.toCompletionParams).get()
assertTrue(s"Completion results were not 'right': $result", result.isRight)
assertFalse(s"Completion results were 'incomplete': $result", result.getRight.isIncomplete)
val completionResults = result.getRight.getItems.asScala.toSet.map { item =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import scala.collection.JavaConverters._
* An action requesting for the info shown when `range` is hovered.
* This action corresponds to the `textDocument/hover` method of the Language Server Protocol.
*
* @param range The range of positions that should be hovered.
* @param expected The expected result.
* @param range The range of positions that should be hovered.
* @param expected None if no response is expected, the expected Markdown string otherwise.
*/
class CodeHover(override val range: CodeRange, expected: List[String]) extends ActionOnRange {
class CodeHover(override val range: CodeRange, expectedOpt: Option[String]) extends ActionOnRange {

override def onMarker(marker: CodeMarker): Exec[Unit] = {
val result = server.hover(marker.toTextDocumentPositionParams).get()
assertNull(result.getRange)
if (expected.isEmpty) assertNull(result.getContents)
else {
assertEquals(expected.size, result.getContents.size)
expected.zip(result.getContents.asScala).foreach { case (expected, actual) =>
assertTrue(actual.isRight)
assertEquals(expected, actual.getRight.getValue)
}
expectedOpt match {
case None =>
assertNull(result)
case Some(expected) =>
assertNull(result.getRange)
val contents = result.getContents.getRight
assertEquals(contents.getKind, "markdown")
assertEquals(expected, contents.getValue)
}
}

override def show: PositionContext.PosCtx[String] =
s"CodeHover(${range.show}, $expected)"
s"CodeHover(${range.show}, $expectedOpt)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class CodeMarker(val name: String) extends Embedded {
def toDocumentSymbolParams: PosCtx[DocumentSymbolParams] =
new DocumentSymbolParams(toTextDocumentIdentifier)

def toCompletionParams: PosCtx[CompletionParams] =
new CompletionParams(toTextDocumentIdentifier, toPosition)

def toRenameParams(newName: String): PosCtx[RenameParams] =
new RenameParams(toTextDocumentIdentifier, toPosition, newName)

Expand Down
4 changes: 2 additions & 2 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ object Build {
fork in run := true,
fork in Test := true,
libraryDependencies ++= Seq(
"org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.3.0",
"org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.4.1",
Dependencies.`jackson-databind`
),
javaOptions := (javaOptions in `dotty-compiler-bootstrapped`).value,
Expand Down Expand Up @@ -891,7 +891,7 @@ object Build {
settings(commonSettings).
settings(
EclipseKeys.skipProject := true,
version := "0.1.4", // Keep in sync with package.json
version := "0.1.5", // Keep in sync with package.json
autoScalaLibrary := false,
publishArtifact := false,
includeFilter in unmanagedSources := NothingFilter | "*.ts" | "**.json",
Expand Down
Loading