Skip to content

Commit

Permalink
chore: Adjust implementation to recent bsp protocol changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Oct 6, 2023
1 parent 227005e commit 4bb3aeb
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class BuildServerConnection private (
connection.flatMap { conn =>
if (conn.capabilities.getJvmRunEnvironmentProvider()) {
register(
server => server.jvmRunEnvironment(params),
server => server.buildTargetJvmRunEnvironment(params),
onFail = Some(
(
empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ final class ForwardingMetalsBuildClient(
@JsonNotification("build/taskStart")
def buildTaskStart(params: TaskStartParams): Unit = {
params.getDataKind match {
case TaskDataKind.COMPILE_TASK =>
case TaskStartDataKind.COMPILE_TASK =>
if (
params.getMessage != null && params.getMessage.startsWith("Compiling")
) {
Expand Down Expand Up @@ -159,7 +159,7 @@ final class ForwardingMetalsBuildClient(
@JsonNotification("build/taskFinish")
def buildTaskFinish(params: TaskFinishParams): Unit = {
params.getDataKind match {
case TaskDataKind.COMPILE_REPORT =>
case TaskFinishDataKind.COMPILE_REPORT =>
for {
report <- params.asCompileReport
compilation <- compilations.remove(report.getTarget)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ final class RunTestCodeLens(
className: String,
): List[l.Command] = {
val params = {
val dataKind = b.DebugSessionParamsDataKind.SCALA_TEST_SUITES
val dataKind = b.TestParamsDataKind.SCALA_TEST_SUITES
val data = singletonList(className).toJson
sessionParams(target, dataKind, data)
}
Expand Down Expand Up @@ -322,7 +322,10 @@ final class RunTestCodeLens(
dataKind: String,
data: JsonElement,
): b.DebugSessionParams = {
new b.DebugSessionParams(List(target).asJava, dataKind, data)
val params = new b.DebugSessionParams(List(target).asJava)
params.setDataKind(dataKind)
params.setData(data)
params
}

private def command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,10 @@ class DebugProvider(
)
envFromFile(envFile).map { envFromFile =>
main.setEnvironmentVariables((envFromFile ::: env).asJava)
new b.DebugSessionParams(
singletonList(target),
b.DebugSessionParamsDataKind.SCALA_MAIN_CLASS,
main.toJson,
)
val params = new b.DebugSessionParams(singletonList(target))
params.setDataKind(b.DebugSessionParamsDataKind.SCALA_MAIN_CLASS)
params.setData(main.toJson)
params
}
}

Expand Down Expand Up @@ -360,13 +359,13 @@ class DebugProvider(
if (mains.nonEmpty) {
verifyMain(buildTarget, mains.toList, params)
} else if (tests.nonEmpty) {
Future(
new b.DebugSessionParams(
singletonList(buildTarget),
b.DebugSessionParamsDataKind.SCALA_TEST_SUITES,
tests.asJava.toJson,
)
)
Future {
val params = new b.DebugSessionParams(singletonList(buildTarget))
params.setDataKind(b.TestParamsDataKind.SCALA_TEST_SUITES)
params.setData(tests.asJava.toJson)
params
}

} else {
Future.failed(NoRunOptionException)
}
Expand Down Expand Up @@ -498,23 +497,29 @@ class DebugProvider(
}
}
.map { tests =>
new b.DebugSessionParams(
singletonList(target),
b.DebugSessionParamsDataKind.SCALA_TEST_SUITES,
tests.asJava.toJson,
val params = new b.DebugSessionParams(
singletonList(target)
)
params.setDataKind(
b.TestParamsDataKind.SCALA_TEST_SUITES
)
params.setData(tests.asJava.toJson)
params
}
case (Some(TestTarget), Some(target)) =>
Future {
new b.DebugSessionParams(
singletonList(target),
b.DebugSessionParamsDataKind.SCALA_TEST_SUITES,
val params = new b.DebugSessionParams(
singletonList(target)
)
params.setDataKind(b.TestParamsDataKind.SCALA_TEST_SUITES)
params.setData(
testClasses(target).values
.map(_.fullyQualifiedName)
.toList
.asJava
.toJson,
.toJson
)
params
}
}

Expand Down Expand Up @@ -601,11 +606,14 @@ class DebugProvider(
Option(params.jvmOptions).getOrElse(Nil.asJava),
(envFromFile ::: env).asJava,
)
new b.DebugSessionParams(
singletonList(target.getId()),
b.DebugSessionParamsDataKind.SCALA_TEST_SUITES_SELECTION,
scalaTestSuite.toJson,
val debugParams = new b.DebugSessionParams(
singletonList(target.getId())
)
debugParams.setDataKind(
b.TestParamsDataKind.SCALA_TEST_SUITES_SELECTION
)
debugParams.setData(scalaTestSuite.toJson)
debugParams
}
// should not really happen due to
// `findMainClassAndItsBuildTarget` succeeding with non-empty list
Expand All @@ -618,13 +626,14 @@ class DebugProvider(
def createDebugSession(
target: b.BuildTargetIdentifier
): Future[DebugSessionParams] =
Future.successful(
new b.DebugSessionParams(
singletonList(target),
b.DebugSessionParamsDataKind.SCALA_ATTACH_REMOTE,
().toJson,
Future.successful {
val params = new b.DebugSessionParams(
singletonList(target)
)
)
params.setDataKind(b.DebugSessionParamsDataKind.SCALA_ATTACH_REMOTE)
params.setData(().toJson)
params
}

def startTestSuite(
buildTarget: b.BuildTarget,
Expand All @@ -642,17 +651,22 @@ class DebugProvider(
case _ => suite
}
})
new b.DebugSessionParams(
singletonList(buildTarget.getId),
DebugProvider.ScalaTestSelection,
testSuites.toJson,
val params = new b.DebugSessionParams(
singletonList(buildTarget.getId)
)
} else
new b.DebugSessionParams(
singletonList(buildTarget.getId),
b.DebugSessionParamsDataKind.SCALA_TEST_SUITES,
request.requestData.suites.map(_.className).toJson,
params.setDataKind(
b.TestParamsDataKind.SCALA_TEST_SUITES_SELECTION
)
params.setData(testSuites.toJson)
params
} else {
val params = new b.DebugSessionParams(
singletonList(buildTarget.getId)
)
params.setDataKind(b.TestParamsDataKind.SCALA_TEST_SUITES)
params.setData(request.requestData.suites.map(_.className).toJson)
params
}
Future.successful(debugSession)
}
for {
Expand Down Expand Up @@ -726,11 +740,11 @@ class DebugProvider(
parameters.getDataKind match {
case b.DebugSessionParamsDataKind.SCALA_MAIN_CLASS =>
json.as[b.ScalaMainClass].map(_.getClassName)
case b.DebugSessionParamsDataKind.SCALA_TEST_SUITES =>
case b.TestParamsDataKind.SCALA_TEST_SUITES =>
json.as[ju.List[String]].map(_.asScala.sorted.mkString(";"))
case b.DebugSessionParamsDataKind.SCALA_ATTACH_REMOTE =>
Success("attach-remote-debug-session")
case DebugProvider.ScalaTestSelection =>
case b.TestParamsDataKind.SCALA_TEST_SUITES_SELECTION =>
json.as[ScalaTestSuites].map { params =>
params.suites.asScala
.map(suite =>
Expand Down Expand Up @@ -908,8 +922,6 @@ object DebugProvider {
}
}

val ScalaTestSelection = "scala-test-suites-selection"

case object WorkspaceErrorsException
extends Exception(
s"Cannot run class, since the workspace has errors."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ final class TestSuitesProvider(
cases.asScala.flatMap { entry =>
val c = ScalaTestSuiteSelection(fqn, List(entry.name).asJava)
val params = new b.DebugSessionParams(
List(target).asJava,
b.DebugSessionParamsDataKind.SCALA_TEST_SUITES_SELECTION,
ScalaTestSuites(List(c).asJava, Nil.asJava, Nil.asJava).toJson,
List(target).asJava
)
params.setDataKind(
b.TestParamsDataKind.SCALA_TEST_SUITES_SELECTION
)
params.setData(
ScalaTestSuites(List(c).asJava, Nil.asJava, Nil.asJava).toJson
)
def lens(name: String, cmd: BaseCommand) = new l.CodeLens(
entry.location.getRange(),
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/src/main/scala/bill/Bill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object Bill {
private var sleepBeforePingResponse: Option[Duration] = None
val languages: util.List[String] = Collections.singletonList("scala")
var client: BuildClient = _
override def onConnectWithClient(server: BuildClient): Unit =
def onConnectWithClient(server: BuildClient): Unit =
client = server
var workspace: Path = Paths.get(".").toAbsolutePath.normalize()

Expand Down Expand Up @@ -126,7 +126,11 @@ object Bill {
scalaJars,
)
val id = new BuildTargetIdentifier("id")
val capabilities = new BuildTargetCapabilities(true, false, false)
val capabilities = new BuildTargetCapabilities()
capabilities.setCanCompile(true)
capabilities.setCanDebug(false)
capabilities.setCanRun(false)
capabilities.setCanTest(false)
val result = new BuildTarget(
id,
Collections.singletonList("tag"),
Expand Down Expand Up @@ -354,7 +358,9 @@ object Bill {
CompletableFuture.completedFuture {
val count = RecursivelyDelete(out)
val plural = if (count != 1) "s" else ""
new CleanCacheResult(s"deleted $count file$plural", true)
val result = new CleanCacheResult(true)
result.setMessage(s"deleted $count file$plural")
result
}
}

Expand Down
7 changes: 6 additions & 1 deletion tests/unit/src/main/scala/tests/MetalsTestEnrichments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ object MetalsTestEnrichments {
}
)
val bti = new BuildTargetIdentifier("workspace")
val capabilities = new BuildTargetCapabilities()
capabilities.setCanCompile(true)
capabilities.setCanDebug(true)
capabilities.setCanRun(true)
capabilities.setCanTest(true)
val buildTarget = new BuildTarget(
bti,
Nil.asJava,
Nil.asJava,
Nil.asJava,
new BuildTargetCapabilities(true, true, true),
capabilities,
)
val scalaTarget = new ScalaBuildTarget(
"org.scala-lang",
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/src/main/scala/tests/TestingServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,9 @@ final case class TestingServer(
assertSystemExit(parameter)
val targets = List(new b.BuildTargetIdentifier(buildTarget(target)))
val params =
new b.DebugSessionParams(targets.asJava, kind, parameter.toJson)

new b.DebugSessionParams(targets.asJava)
params.setDataKind(kind)
params.setData(parameter.toJson)
executeCommandUnsafe(ServerCommands.StartDebugAdapter.id, Seq(params))
.collect { case DebugSession(_, uri) =>
scribe.info(s"Starting debug session for $uri")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,18 @@ class ProblemResolverSuite extends FunSuite {
val scalaBinaryVersion =
ScalaVersions.scalaBinaryVersionFromFullVersion(scalaVersion)
val buildId = new BuildTargetIdentifier(id)
val capabilities = new BuildTargetCapabilities()
capabilities.setCanCompile(true)
capabilities.setCanDebug(true)
capabilities.setCanRun(true)
capabilities.setCanTest(true)
val buildTarget =
new BuildTarget(
buildId,
/* tags = */ Nil.asJava,
/* languageIds = */ Nil.asJava,
/* dependencies = */ Nil.asJava,
/* capabilities = */ new BuildTargetCapabilities(true, true, true),
/* capabilities = */ capabilities,
)
buildTarget.setDisplayName(id)
val scalaBuildTarget = new ScalaBuildTarget(
Expand Down

0 comments on commit 4bb3aeb

Please sign in to comment.