mirror of https://github.com/sbt/sbt.git
Merge pull request #6007 from adpi2/fix-bsp-reporter
Fix #6006: BuildServerReporter on Dotty
This commit is contained in:
commit
8c3ea7d470
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
package sbt.internal.server
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
import sbt.StandardMain
|
||||
import sbt.internal.bsp._
|
||||
import sbt.internal.util.ManagedLogger
|
||||
|
|
@ -69,7 +71,7 @@ final class BuildServerReporterImpl(
|
|||
import sbt.internal.inc.JavaInterfaceUtil._
|
||||
|
||||
private lazy val exchange = StandardMain.exchange
|
||||
private val problemsByFile = mutable.Map[VirtualFileRef, Vector[Diagnostic]]()
|
||||
private val problemsByFile = mutable.Map[Path, Vector[Diagnostic]]()
|
||||
|
||||
override def sendSuccessReport(analysis: CompileAnalysis): Unit = {
|
||||
for {
|
||||
|
|
@ -90,9 +92,8 @@ final class BuildServerReporterImpl(
|
|||
|
||||
override def sendFailureReport(sources: Array[VirtualFile]): Unit = {
|
||||
for (source <- sources) {
|
||||
val ref = VirtualFileRef.of(source.id())
|
||||
val diagnostics = problemsByFile.getOrElse(ref, Vector())
|
||||
val filePath = converter.toPath(source)
|
||||
val diagnostics = problemsByFile.getOrElse(filePath, Vector())
|
||||
val params = PublishDiagnosticsParams(
|
||||
textDocument = TextDocumentIdentifier(filePath.toUri),
|
||||
buildTarget,
|
||||
|
|
@ -106,14 +107,13 @@ final class BuildServerReporterImpl(
|
|||
|
||||
protected override def publishDiagnostic(problem: Problem): Unit = {
|
||||
for {
|
||||
path <- problem.position().sourcePath.toOption
|
||||
source <- problem.position.sourceFile.toOption
|
||||
id <- problem.position.sourcePath.toOption
|
||||
diagnostic <- toDiagnostic(problem)
|
||||
} {
|
||||
val fileId = VirtualFileRef.of(path)
|
||||
problemsByFile(fileId) = problemsByFile.getOrElse(fileId, Vector()) :+ diagnostic
|
||||
val filePath = converter.toPath(VirtualFileRef.of(id))
|
||||
problemsByFile(filePath) = problemsByFile.getOrElse(filePath, Vector()) :+ diagnostic
|
||||
val params = PublishDiagnosticsParams(
|
||||
TextDocumentIdentifier(source.toURI),
|
||||
TextDocumentIdentifier(filePath.toUri),
|
||||
buildTarget,
|
||||
originId = None,
|
||||
Vector(diagnostic),
|
||||
|
|
|
|||
|
|
@ -2,13 +2,17 @@ ThisBuild / scalaVersion := "2.13.1"
|
|||
|
||||
Global / serverLog / logLevel := Level.Debug
|
||||
|
||||
lazy val root = (project in file("."))
|
||||
.aggregate(foo, util)
|
||||
|
||||
lazy val foo = project.in(file("foo"))
|
||||
lazy val runAndTest = project.in(file("run-and-test"))
|
||||
.settings(
|
||||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test",
|
||||
)
|
||||
.dependsOn(util)
|
||||
|
||||
lazy val reportError = project.in(file("report-error"))
|
||||
|
||||
lazy val reportWarning = project.in(file("report-warning"))
|
||||
.settings(
|
||||
scalacOptions += "-deprecation"
|
||||
)
|
||||
|
||||
lazy val util = project
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
package foo
|
||||
|
||||
import org.scalatest.FreeSpec
|
||||
|
||||
class FooTest extends FreeSpec {
|
||||
"test message" in {
|
||||
assert(FooMain.message == "Hello World!")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package reportertests
|
||||
|
||||
object Error {
|
||||
val version: String = 5
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package reportertests
|
||||
|
||||
object Warning {
|
||||
def print() {
|
||||
prtinln("bar")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package foo
|
||||
package main
|
||||
|
||||
object FooMain extends App {
|
||||
object Main extends App {
|
||||
lazy val message = "Hello World!"
|
||||
|
||||
println(message)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package foo
|
||||
package tests
|
||||
|
||||
import org.scalatest.FreeSpec
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package tests
|
||||
|
||||
import org.scalatest.FreeSpec
|
||||
|
||||
class PassingTest extends FreeSpec {
|
||||
"test message" in {
|
||||
assert(main.Main.message == "Hello World!")
|
||||
}
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ object BuildServerTest extends AbstractServerTest {
|
|||
}
|
||||
|
||||
test("buildTarget/scalaMainClasses") { _ =>
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#foo/Compile"
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#runAndTest/Compile"
|
||||
svr.sendJsonRpc(
|
||||
s"""{ "jsonrpc": "2.0", "id": "16", "method": "buildTarget/scalaMainClasses", "params": {
|
||||
| "targets": [{ "uri": "$x" }]
|
||||
|
|
@ -95,17 +95,17 @@ object BuildServerTest extends AbstractServerTest {
|
|||
assert(svr.waitForString(30.seconds) { s =>
|
||||
println(s)
|
||||
(s contains """"id":"16"""") &&
|
||||
(s contains """"class":"foo.FooMain"""")
|
||||
(s contains """"class":"main.Main"""")
|
||||
})
|
||||
}
|
||||
|
||||
test("buildTarget/run") { _ =>
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#foo/Compile"
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#runAndTest/Compile"
|
||||
svr.sendJsonRpc(
|
||||
s"""{ "jsonrpc": "2.0", "id": "17", "method": "buildTarget/run", "params": {
|
||||
| "target": { "uri": "$x" },
|
||||
| "dataKind": "scala-main-class",
|
||||
| "data": { "class": "foo.FooMain" }
|
||||
| "data": { "class": "main.Main" }
|
||||
|} }""".stripMargin
|
||||
)
|
||||
assert(svr.waitForString(10.seconds) { s =>
|
||||
|
|
@ -121,7 +121,7 @@ object BuildServerTest extends AbstractServerTest {
|
|||
}
|
||||
|
||||
test("buildTarget/scalaTestClasses") { _ =>
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#foo/Test"
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#runAndTest/Test"
|
||||
svr.sendJsonRpc(
|
||||
s"""{ "jsonrpc": "2.0", "id": "18", "method": "buildTarget/scalaTestClasses", "params": {
|
||||
| "targets": [{ "uri": "$x" }]
|
||||
|
|
@ -130,12 +130,13 @@ object BuildServerTest extends AbstractServerTest {
|
|||
assert(svr.waitForString(10.seconds) { s =>
|
||||
println(s)
|
||||
(s contains """"id":"18"""") &&
|
||||
(s contains """"classes":["foo.FailingTest","foo.FooTest"]""")
|
||||
(s contains """"tests.FailingTest"""") &&
|
||||
(s contains """"tests.PassingTest"""")
|
||||
})
|
||||
}
|
||||
|
||||
test("buildTarget/test: run all tests") { _ =>
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#foo/Test"
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#runAndTest/Test"
|
||||
svr.sendJsonRpc(
|
||||
s"""{ "jsonrpc": "2.0", "id": "19", "method": "buildTarget/test", "params": {
|
||||
| "targets": [{ "uri": "$x" }]
|
||||
|
|
@ -149,7 +150,7 @@ object BuildServerTest extends AbstractServerTest {
|
|||
}
|
||||
|
||||
test("buildTarget/test: run one test class") { _ =>
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#foo/Test"
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#runAndTest/Test"
|
||||
svr.sendJsonRpc(
|
||||
s"""{ "jsonrpc": "2.0", "id": "20", "method": "buildTarget/test", "params": {
|
||||
| "targets": [{ "uri": "$x" }],
|
||||
|
|
@ -158,7 +159,7 @@ object BuildServerTest extends AbstractServerTest {
|
|||
| "testClasses": [
|
||||
| {
|
||||
| "target": { "uri": "$x" },
|
||||
| "classes": ["foo.FooTest"]
|
||||
| "classes": ["tests.PassingTest"]
|
||||
| }
|
||||
| ]
|
||||
| }
|
||||
|
|
@ -171,6 +172,36 @@ object BuildServerTest extends AbstractServerTest {
|
|||
})
|
||||
}
|
||||
|
||||
test("buildTarget/compile: report error") { _ =>
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#reportError/Compile"
|
||||
svr.sendJsonRpc(
|
||||
s"""{ "jsonrpc": "2.0", "id": "21", "method": "buildTarget/compile", "params": {
|
||||
| "targets": [{ "uri": "$x" }]
|
||||
|} }""".stripMargin
|
||||
)
|
||||
assert(svr.waitForString(10.seconds) { s =>
|
||||
println(s)
|
||||
(s contains s""""buildTarget":{"uri":"$x"}""") &&
|
||||
(s contains """"severity":1""") &&
|
||||
(s contains """"reset":true""")
|
||||
})
|
||||
}
|
||||
|
||||
test("buildTarget/compile: report warning") { _ =>
|
||||
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#reportWarning/Compile"
|
||||
svr.sendJsonRpc(
|
||||
s"""{ "jsonrpc": "2.0", "id": "22", "method": "buildTarget/compile", "params": {
|
||||
| "targets": [{ "uri": "$x" }]
|
||||
|} }""".stripMargin
|
||||
)
|
||||
assert(svr.waitForString(10.seconds) { s =>
|
||||
println(s)
|
||||
(s contains s""""buildTarget":{"uri":"$x"}""") &&
|
||||
(s contains """"severity":2""") &&
|
||||
(s contains """"reset":true""")
|
||||
})
|
||||
}
|
||||
|
||||
def initializeRequest(): Unit = {
|
||||
svr.sendJsonRpc(
|
||||
"""{ "jsonrpc": "2.0", "id": "10", "method": "build/initialize",
|
||||
|
|
|
|||
Loading…
Reference in New Issue