Skip to content
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
5 changes: 1 addition & 4 deletions frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,7 @@ final class BloopBspServices(
}
)
case bsp.DebugSessionParamsDataKind.ScalaAttachRemote =>
BloopDebuggeeRunner.forAttachRemote(state, ioScheduler, projects) match {
case Right(adapter) => Right(adapter)
case Left(error) => Left(JsonRpcResponse.invalidRequest(error))
}
Right(BloopDebuggeeRunner.forAttachRemote(state, ioScheduler, projects))
case dataKind => Left(JsonRpcResponse.invalidRequest(s"Unsupported data kind: $dataKind"))
}
}
Expand Down
143 changes: 63 additions & 80 deletions frontend/src/main/scala/bloop/dap/BloopDebuggeeRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ import bloop.testing.TestInternals
import monix.eval.Task
import monix.execution.Scheduler

abstract class BloopDebuggeeRunner(initialState: State, ioScheduler: Scheduler)
extends DebuggeeRunner {
abstract class BloopDebuggeeRunner(
initialState: State,
ioScheduler: Scheduler,
debugeeScalaVersion: Option[String]
) extends DebuggeeRunner {

// The version doesn't matter for project without Scala version (Java only)
val scalaVersion = debugeeScalaVersion.getOrElse("2.13.8")

override def run(listener: DebuggeeListener): CancelableFuture[Unit] = {
val debugSessionLogger = new DebuggeeLogger(listener, initialState.logger)
Expand All @@ -52,8 +58,8 @@ private final class MainClassDebugAdapter(
initialState: State,
ioScheduler: Scheduler,
override val classPath: Seq[Path],
val scalaVersion: String
) extends BloopDebuggeeRunner(initialState, ioScheduler) {
val debugeeScalaVersion: Option[String]
) extends BloopDebuggeeRunner(initialState, ioScheduler, debugeeScalaVersion) {
val javaRuntime: Option[JavaRuntime] = JavaRuntime(env.javaHome.underlying)
def name: String = s"${getClass.getSimpleName}(${project.name}, ${mainClass.`class`})"
def start(state: State, listener: DebuggeeListener): Task[ExitStatus] = {
Expand Down Expand Up @@ -86,8 +92,8 @@ private final class TestSuiteDebugAdapter(
initialState: State,
ioScheduler: Scheduler,
override val classPath: Seq[Path],
val scalaVersion: String
) extends BloopDebuggeeRunner(initialState, ioScheduler) {
val debugeeScalaVersion: Option[String]
) extends BloopDebuggeeRunner(initialState, ioScheduler, debugeeScalaVersion) {
override def name: String = {
val projectsStr = projects.map(_.bspUri).mkString("[", ", ", "]")
val selectedTests = testClasses.suites
Expand Down Expand Up @@ -123,8 +129,8 @@ private final class AttachRemoteDebugAdapter(
initialState: State,
ioScheduler: Scheduler,
override val classPath: Seq[Path],
val scalaVersion: String
) extends BloopDebuggeeRunner(initialState, ioScheduler) {
val debugeeScalaVersion: Option[String]
) extends BloopDebuggeeRunner(initialState, ioScheduler, debugeeScalaVersion) {
override def name: String = s"${getClass.getSimpleName}(${initialState.build.origin})"
override def start(state: State, listener: DebuggeeListener): Task[ExitStatus] = Task(
ExitStatus.Ok
Expand All @@ -133,10 +139,6 @@ private final class AttachRemoteDebugAdapter(

object BloopDebuggeeRunner {

private def noScalaVersion: Left[String, DebuggeeRunner] = Left(
"No scala version specified for the project"
)

def forMainClass(
projects: Seq[Project],
mainClass: ScalaMainClass,
Expand All @@ -146,8 +148,8 @@ object BloopDebuggeeRunner {
projects match {
case Seq() => Left(s"No projects specified for main class: [$mainClass]")
case Seq(project) =>
(project.platform, project.scalaInstance) match {
case (jvm: Platform.Jvm, Some(scalaInstance)) =>
project.platform match {
case jvm: Platform.Jvm =>
val classPathEntries = getClassPathEntries(state, project)
val evaluationClassLoader = getEvaluationClassLoader(project, state)
val classpath = getClasspath(state, project)
Expand All @@ -161,12 +163,10 @@ object BloopDebuggeeRunner {
state,
ioScheduler,
classpath,
scalaInstance.version
project.scalaInstance.map(_.version)
)
)
case (_, None) =>
noScalaVersion
case (platform, _) =>
case platform =>
Left(s"Unsupported platform: ${platform.getClass.getSimpleName}")
}
case projects => Left(s"Multiple projects specified for main class [$mainClass]: $projects")
Expand All @@ -188,86 +188,69 @@ object BloopDebuggeeRunner {
val javaRuntime = JavaRuntime(config.javaHome.underlying)
val evaluationClassLoader = getEvaluationClassLoader(project, state)
val classpath = getClasspath(state, project)
project.scalaInstance.fold[Either[String, DebuggeeRunner]](
noScalaVersion
) { scalaInstance =>
Right(
new TestSuiteDebugAdapter(
projects,
testClasses,
classPathEntries,
javaRuntime,
evaluationClassLoader,
state,
ioScheduler,
classpath,
scalaInstance.version
)
Right(
new TestSuiteDebugAdapter(
projects,
testClasses,
classPathEntries,
javaRuntime,
evaluationClassLoader,
state,
ioScheduler,
classpath,
project.scalaInstance.map(_.version)
)
}
)

case project :: _ =>
project.scalaInstance.fold[Either[String, DebuggeeRunner]](
noScalaVersion
) { scalaInstance =>
Right(
new TestSuiteDebugAdapter(
projects,
testClasses,
Seq.empty,
None,
None,
state,
ioScheduler,
Seq.empty,
scalaInstance.version
)
Right(
new TestSuiteDebugAdapter(
projects,
testClasses,
Seq.empty,
None,
None,
state,
ioScheduler,
Seq.empty,
project.scalaInstance.map(_.version)
)
}
)

}
}

def forAttachRemote(
state: State,
ioScheduler: Scheduler,
projects: Seq[Project]
): Either[String, DebuggeeRunner] = {
): DebuggeeRunner = {
projects match {
case Seq(project) if project.platform.isInstanceOf[Platform.Jvm] =>
val Platform.Jvm(config, _, _, _, _, _) = project.platform
val classPathEntries = getClassPathEntries(state, project)
val javaRuntime = JavaRuntime(config.javaHome.underlying)
val evaluationClassLoader = getEvaluationClassLoader(project, state)
val classpath = getClasspath(state, project)
project.scalaInstance.fold[Either[String, DebuggeeRunner]](noScalaVersion) {
scalaInstance =>
Right(
new AttachRemoteDebugAdapter(
classPathEntries,
javaRuntime,
evaluationClassLoader,
state,
ioScheduler,
classpath,
scalaInstance.version
)
)
}
new AttachRemoteDebugAdapter(
classPathEntries,
javaRuntime,
evaluationClassLoader,
state,
ioScheduler,
classpath,
project.scalaInstance.map(_.version)
)
case projects =>
projects.headOption
.flatMap(_.scalaInstance)
.fold[Either[String, DebuggeeRunner]](noScalaVersion) { scalaInstance =>
Right(
new AttachRemoteDebugAdapter(
Seq.empty,
None,
None,
state,
ioScheduler,
Seq.empty,
scalaInstance.version
)
)
}
new AttachRemoteDebugAdapter(
Seq.empty,
None,
None,
state,
ioScheduler,
Seq.empty,
projects.headOption.flatMap(_.scalaInstance).map(_.version)
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/test/scala/bloop/dap/DebugServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ object DebugServerSpec extends DebugBspBaseSuite {
val `Main.scala` = srcFor("Main.scala")
val breakpoints = breakpointsArgs(`Main.scala`, 3)

val Right(attachRemoteProcessRunner) =
val attachRemoteProcessRunner =
BloopDebuggeeRunner.forAttachRemote(
state.compile(project).toTestState.state,
defaultScheduler,
Expand Down Expand Up @@ -755,7 +755,7 @@ object DebugServerSpec extends DebugBspBaseSuite {
val `Main.scala` = srcFor("Main.scala")
val breakpoints = breakpointsArgs(`Main.scala`, 4)

val Right(attachRemoteProcessRunner) =
val attachRemoteProcessRunner =
BloopDebuggeeRunner.forAttachRemote(
testState.state,
defaultScheduler,
Expand Down