diff --git a/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala b/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala index 6a9ba6622a8..b07c8d1cc63 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala @@ -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, diff --git a/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala b/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala index a7238847985..9a8c29178f8 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala @@ -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") ) { @@ -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) diff --git a/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala b/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala index c06b64af864..ac5cf3e3b01 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/codelenses/RunTestCodeLens.scala @@ -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) } @@ -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( diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala index c2c0e39ae37..9e59e89376e 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala @@ -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 } } @@ -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) } @@ -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 } } @@ -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 @@ -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, @@ -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 { @@ -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 => @@ -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." diff --git a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala index 5f4fbccea55..766764b8241 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/testProvider/TestSuitesProvider.scala @@ -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(), diff --git a/tests/unit/src/main/scala/bill/Bill.scala b/tests/unit/src/main/scala/bill/Bill.scala index e2ab884d344..276eb293ebf 100644 --- a/tests/unit/src/main/scala/bill/Bill.scala +++ b/tests/unit/src/main/scala/bill/Bill.scala @@ -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() @@ -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"), @@ -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 } } diff --git a/tests/unit/src/main/scala/tests/MetalsTestEnrichments.scala b/tests/unit/src/main/scala/tests/MetalsTestEnrichments.scala index 135dc5b66b5..06cb7f64e54 100644 --- a/tests/unit/src/main/scala/tests/MetalsTestEnrichments.scala +++ b/tests/unit/src/main/scala/tests/MetalsTestEnrichments.scala @@ -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", diff --git a/tests/unit/src/main/scala/tests/TestingServer.scala b/tests/unit/src/main/scala/tests/TestingServer.scala index 096fd07d616..c189bcb29b9 100644 --- a/tests/unit/src/main/scala/tests/TestingServer.scala +++ b/tests/unit/src/main/scala/tests/TestingServer.scala @@ -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") diff --git a/tests/unit/src/test/scala/tests/troubleshoot/ProblemResolverSuite.scala b/tests/unit/src/test/scala/tests/troubleshoot/ProblemResolverSuite.scala index 05f989726a9..7f954a3b987 100644 --- a/tests/unit/src/test/scala/tests/troubleshoot/ProblemResolverSuite.scala +++ b/tests/unit/src/test/scala/tests/troubleshoot/ProblemResolverSuite.scala @@ -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(