Skip to content

Commit f041a7a

Browse files
committed
chore: Adjust to recent bsp changes
1 parent ab059a9 commit f041a7a

24 files changed

+176
-192
lines changed

backend/src/main/scala/bloop/io/ParallelOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import java.nio.file.attribute.BasicFileAttributes
1010
import java.util.concurrent.ConcurrentHashMap
1111

1212
import scala.concurrent.Promise
13+
import scala.util.control.NonFatal
1314

15+
import bloop.logging.Logger
1416
import bloop.task.Task
1517

1618
import monix.eval.{Task => MonixTask}
@@ -22,8 +24,6 @@ import monix.execution.cancelables.CompositeCancelable
2224
import monix.reactive.Consumer
2325
import monix.reactive.MulticastStrategy
2426
import monix.reactive.Observable
25-
import bloop.logging.Logger
26-
import scala.util.control.NonFatal
2727

2828
object ParallelOps {
2929

backend/src/main/scala/bloop/task/Task.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sealed trait Task[+A] { self =>
5454
}
5555

5656
final def doOnCancel(f: => Task[Unit]): Task[A] =
57-
applyCancel(() => f.runAsync(monix.execution.Scheduler.Implicits.global))
57+
applyCancel { () => f.runAsync(monix.execution.Scheduler.Implicits.global); () }
5858

5959
final def doOnFinish(f: Option[Throwable] => Task[Unit]): Task[A] =
6060
self.materialize.flatMap { v =>

backend/src/main/scala/sbt/internal/inc/BloopComponentCompiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import java.nio.file.Files
1414
import java.nio.file.Path
1515
import java.nio.file.Paths
1616

17+
import scala.util.control.NonFatal
18+
1719
import _root_.bloop.io.AbsolutePath
1820
import _root_.bloop.logging.DebugFilter
1921
import _root_.bloop.logging.{Logger => BloopLogger}
@@ -27,7 +29,6 @@ import xsbti.ComponentProvider
2729
import xsbti.Logger
2830
import xsbti.compile.ClasspathOptionsUtil
2931
import xsbti.compile.CompilerBridgeProvider
30-
import scala.util.control.NonFatal
3132

3233
object BloopComponentCompiler {
3334
import xsbti.compile.ScalaInstance

backend/src/main/scala/sbt/internal/inc/bloop/internal/BloopAnalysisCallback.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import java.nio.file.FileSystems
66
import java.nio.file.Path
77
import java.{util => ju}
88

9+
import scala.collection.JavaConverters._
10+
911
import sbt.internal.inc.Analysis
1012
import sbt.internal.inc.Compilation
1113
import sbt.internal.inc.Incremental
@@ -17,6 +19,9 @@ import sbt.util.InterfaceUtil
1719
import xsbt.api.APIUtil
1820
import xsbt.api.HashAPI
1921
import xsbt.api.NameHashing
22+
import xsbti.Action
23+
import xsbti.DiagnosticCode
24+
import xsbti.DiagnosticRelatedInformation
2025
import xsbti.Position
2126
import xsbti.Problem
2227
import xsbti.Severity
@@ -37,9 +42,6 @@ import xsbti.compile.ClassFileManager
3742
import xsbti.compile.IncOptions
3843
import xsbti.compile.Output
3944
import xsbti.compile.analysis.ReadStamps
40-
import xsbti.{Action, DiagnosticCode, DiagnosticRelatedInformation}
41-
42-
import collection.JavaConverters._
4345

4446
trait IBloopAnalysisCallback extends xsbti.AnalysisCallback2 {
4547
def get: Analysis

backend/src/main/scala/sbt/internal/inc/bloop/internal/ConcurrentAnalysisCallback.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import java.io.File
44
import java.nio.file.Path
55
import java.{util => ju}
66

7+
import scala.collection.JavaConverters._
8+
79
import sbt.internal.inc.Analysis
810
import sbt.internal.inc.Compilation
911
import sbt.internal.inc.Incremental
@@ -15,6 +17,9 @@ import sbt.util.InterfaceUtil
1517
import xsbt.api.APIUtil
1618
import xsbt.api.HashAPI
1719
import xsbt.api.NameHashing
20+
import xsbti.Action
21+
import xsbti.DiagnosticCode
22+
import xsbti.DiagnosticRelatedInformation
1823
import xsbti.Position
1924
import xsbti.Problem
2025
import xsbti.Severity
@@ -35,9 +40,6 @@ import xsbti.compile.ClassFileManager
3540
import xsbti.compile.IncOptions
3641
import xsbti.compile.Output
3742
import xsbti.compile.analysis.ReadStamps
38-
import xsbti.{Action, DiagnosticCode, DiagnosticRelatedInformation}
39-
40-
import collection.JavaConverters._
4143

4244
/**
4345
* This class provides a thread-safe implementation of `xsbti.AnalysisCallback` which is required to compile with the

frontend/src/main/scala/bloop/bsp/BloopBspServices.scala

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ final class BloopBspServices(
137137
.requestAsync(endpoints.BuildTarget.run)(p => schedule(run(p)))
138138
.requestAsync(endpoints.BuildTarget.cleanCache)(p => schedule(clean(p)))
139139
.requestAsync(endpoints.BuildTarget.scalaMainClasses)(p => schedule(scalaMainClasses(p)))
140-
.requestAsync(ScalaTestClasses.endpoint)(p => schedule(scalaTestClasses(p)))
140+
.requestAsync(endpoints.BuildTarget.scalaTestClasses)(p => schedule(scalaTestClasses(p)))
141141
.requestAsync(endpoints.BuildTarget.dependencySources)(p => schedule(dependencySources(p)))
142142
.requestAsync(endpoints.DebugSession.start)(p => schedule(startDebugSession(p)))
143143
.requestAsync(endpoints.BuildTarget.jvmTestEnvironment)(p => schedule(jvmTestEnvironment(p)))
@@ -316,6 +316,7 @@ final class BloopBspServices(
316316
jvmRunEnvironmentProvider = Some(true),
317317
canReload = Some(false)
318318
),
319+
None,
319320
None
320321
)
321322
)
@@ -567,12 +568,12 @@ final class BloopBspServices(
567568

568569
def scalaTestClasses(
569570
params: bsp.ScalaTestClassesParams
570-
): BspEndpointResponse[ScalaTestClassesResult] =
571+
): BspEndpointResponse[bsp.ScalaTestClassesResult] =
571572
ifInitialized(params.originId) { (state: State, logger: BspServerLogger) =>
572573
mapToProjects(params.targets, state) match {
573574
case Left(error) =>
574575
logger.error(error)
575-
Task.now((state, Right(ScalaTestClassesResult(Nil))))
576+
Task.now((state, Right(bsp.ScalaTestClassesResult(Nil))))
576577

577578
case Right(projects) =>
578579
val subTasks = projects.toList.filter(p => TestTask.isTestProject(p._2)).map {
@@ -583,15 +584,15 @@ final class BloopBspServices(
583584
.groupBy(_.framework)
584585
.map {
585586
case (framework, classes) =>
586-
ScalaTestClassesItem(id, classes.flatMap(_.classes), Some(framework))
587+
bsp.ScalaTestClassesItem(id, Some(framework), classes.flatMap(_.classes))
587588
}
588589
.toList
589590
}
590591
item
591592
}
592593

593594
Task.sequence(subTasks).map { items =>
594-
val result = ScalaTestClassesResult(items.flatten)
595+
val result = bsp.ScalaTestClassesResult(items.flatten)
595596
(state, Right(result))
596597
}
597598
}
@@ -608,33 +609,43 @@ final class BloopBspServices(
608609
def convert[A: JsonValueCodec](
609610
f: A => Either[String, Debuggee]
610611
): Either[Response.Error, Debuggee] = {
611-
Try(readFromArray[A](params.data.value)) match {
612-
case Failure(error) =>
613-
Left(Response.invalidRequest(error.getMessage()))
614-
case Success(params) =>
615-
f(params) match {
616-
case Right(adapter) => Right(adapter)
617-
case Left(error) => Left(Response.invalidRequest(error))
612+
params.data match {
613+
case Some(data) =>
614+
Try(readFromArray[A](data.value)) match {
615+
case Failure(error) =>
616+
Left(Response.invalidRequest(error.getMessage()))
617+
case Success(params) =>
618+
f(params) match {
619+
case Right(adapter) => Right(adapter)
620+
case Left(error) => Left(Response.invalidRequest(error))
621+
}
618622
}
623+
case None =>
624+
Left(Response.invalidRequest("No debug data available"))
619625
}
626+
620627
}
621628

622629
params.dataKind match {
623-
case bsp.DebugSessionParamsDataKind.ScalaMainClass =>
630+
case Some(bsp.DebugSessionParamsDataKind.ScalaMainClass) =>
624631
convert[bsp.ScalaMainClass](main =>
625632
BloopDebuggeeRunner.forMainClass(projects, main, state, ioScheduler)
626633
)
627-
case bsp.DebugSessionParamsDataKind.ScalaTestSuites =>
634+
case Some(bsp.TestParamsDataKind.ScalaTestSuites) =>
628635
implicit val codec = JsonCodecMaker.make[List[String]]
629636
convert[List[String]](classNames => {
630-
val testClasses = ScalaTestSuites(classNames)
637+
val testClasses = bsp.ScalaTestSuites(
638+
classNames.map(className => bsp.ScalaTestSuiteSelection(className, Nil)),
639+
Nil,
640+
Nil
641+
)
631642
BloopDebuggeeRunner.forTestSuite(projects, testClasses, state, ioScheduler)
632643
})
633-
case "scala-test-suites-selection" =>
634-
convert[ScalaTestSuites](testClasses => {
644+
case Some(bsp.TestParamsDataKind.ScalaTestSuitesSelection) =>
645+
convert[bsp.ScalaTestSuites](testClasses => {
635646
BloopDebuggeeRunner.forTestSuite(projects, testClasses, state, ioScheduler)
636647
})
637-
case bsp.DebugSessionParamsDataKind.ScalaAttachRemote =>
648+
case Some(bsp.DebugSessionParamsDataKind.ScalaAttachRemote) =>
638649
Right(BloopDebuggeeRunner.forAttachRemote(state, ioScheduler, projects))
639650
case dataKind => Left(Response.invalidRequest(s"Unsupported data kind: $dataKind"))
640651
}
@@ -684,7 +695,9 @@ final class BloopBspServices(
684695
.map(_ => backgroundDebugServers -= handler.uri)
685696
.runAsync(ioScheduler)
686697
backgroundDebugServers += handler.uri -> listenAndUnsubscribe
687-
Task.now((state, Right(new bsp.DebugSessionAddress(handler.uri.toString))))
698+
Task.now(
699+
(state, Right(new bsp.DebugSessionAddress(bsp.Uri(handler.uri.toString()))))
700+
)
688701

689702
case Left(error) =>
690703
Task.now((state, Left(error)))
@@ -704,7 +717,7 @@ final class BloopBspServices(
704717
List(project),
705718
Nil,
706719
testFilter,
707-
ScalaTestSuites.empty,
720+
bsp.ScalaTestSuites(Nil, Nil, Nil),
708721
handler,
709722
mode = RunMode.Normal
710723
)
@@ -804,21 +817,21 @@ final class BloopBspServices(
804817
def findMainClasses(state: State, project: Project): List[bsp.ScalaMainClass] =
805818
for {
806819
className <- Tasks.findMainClasses(state, project)
807-
} yield bsp.ScalaMainClass(className, Nil, Nil, Nil)
820+
} yield bsp.ScalaMainClass(className, Nil, Nil, None)
808821

809822
ifInitialized(params.originId) { (state: State, logger: BspServerLogger) =>
810823
mapToProjects(params.targets, state) match {
811824
case Left(error) =>
812825
logger.error(error)
813-
Task.now((state, Right(bsp.ScalaMainClassesResult(Nil))))
826+
Task.now((state, Right(bsp.ScalaMainClassesResult(Nil, params.originId))))
814827

815828
case Right(projects) =>
816829
val items = for {
817830
(id, project) <- projects.toList
818831
mainClasses = findMainClasses(state, project)
819832
} yield bsp.ScalaMainClassesItem(id, mainClasses)
820833

821-
val result = new bsp.ScalaMainClassesResult(items)
834+
val result = new bsp.ScalaMainClassesResult(items, params.originId)
822835
Task.now((state, Right(result)))
823836
}
824837
}
@@ -843,7 +856,7 @@ final class BloopBspServices(
843856
val cmd = Commands.Run(List(project.name))
844857
Interpreter.getMainClass(state, project, cmd.main) match {
845858
case Right(name) =>
846-
Right(new bsp.ScalaMainClass(name, cmd.args, Nil, Nil))
859+
Right(new bsp.ScalaMainClass(name, cmd.args, Nil, None))
847860
case Left(_) =>
848861
Left(new IllegalStateException(s"Main class for project $project not found"))
849862
}
@@ -871,16 +884,16 @@ final class BloopBspServices(
871884
project,
872885
config,
873886
cwd,
874-
mainClass.`class`,
887+
mainClass.className,
875888
mainArgs,
876889
skipJargs = false,
877-
mainClass.environmentVariables,
890+
mainClass.environmentVariables.getOrElse(Nil),
878891
RunMode.Normal
879892
)
880893
case platform @ Platform.Native(config, _, _) =>
881894
val cmd = Commands.Run(List(project.name))
882895
val target = ScalaNativeToolchain.linkTargetFrom(project, config)
883-
linkMainWithNative(cmd, project, state, mainClass.`class`, target, platform)
896+
linkMainWithNative(cmd, project, state, mainClass.className, target, platform)
884897
.flatMap { state =>
885898
val args = (target.syntax +: cmd.args).toArray
886899
if (!state.status.isOk) Task.now(state)
@@ -889,7 +902,7 @@ final class BloopBspServices(
889902
case platform @ Platform.Js(config, _, _) =>
890903
val cmd = Commands.Run(List(project.name))
891904
val target = ScalaJsToolchain.linkTargetFrom(project, config)
892-
linkMainWithJs(cmd, project, state, mainClass.`class`, target, platform)
905+
linkMainWithJs(cmd, project, state, mainClass.className, target, platform)
893906
.flatMap { state =>
894907
// We use node to run the program (is this a special case?)
895908
val args = ("node" +: target.syntax +: cmd.args).toArray
@@ -1040,10 +1053,10 @@ final class BloopBspServices(
10401053
}
10411054

10421055
val capabilities = bsp.BuildTargetCapabilities(
1043-
canCompile = true,
1044-
canTest = true,
1045-
canRun = true,
1046-
canDebug = true
1056+
canCompile = Some(true),
1057+
canTest = Some(true),
1058+
canRun = Some(true),
1059+
canDebug = Some(true)
10471060
)
10481061
val isJavaOnly = p.scalaInstance.isEmpty
10491062
val languageIds =
@@ -1256,8 +1269,8 @@ final class BloopBspServices(
12561269
bsp.ScalacOptionsItem(
12571270
target = target,
12581271
options = project.scalacOptions.toList,
1259-
classpath = classpath,
1260-
classDirectory = classesDir
1272+
classpath = classpath.map(_.value),
1273+
classDirectory = classesDir.value
12611274
)
12621275
}.toList
12631276
)
@@ -1290,8 +1303,8 @@ final class BloopBspServices(
12901303
bsp.JavacOptionsItem(
12911304
target = target,
12921305
options = project.javacOptions.toList,
1293-
classpath = classpath,
1294-
classDirectory = classesDir
1306+
classpath = classpath.map(_.value),
1307+
classDirectory = classesDir.value
12951308
)
12961309
}.toList
12971310
)

frontend/src/main/scala/bloop/bsp/BloopLanguageClient.scala

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,21 @@ class BloopLanguageClient(
3939

4040
def notify[A](
4141
endpoint: Endpoint[A, Unit],
42-
params: A,
43-
headers: Map[String, String] = Map.empty
42+
params: A
43+
): Future[Ack] = notify(endpoint, Some(params), Map.empty)
44+
45+
def notify[A](
46+
endpoint: Endpoint[A, Unit],
47+
params: Option[A]
48+
): Future[Ack] = notify(endpoint, params, Map.empty)
49+
50+
def notify[A](
51+
endpoint: Endpoint[A, Unit],
52+
params: Option[A],
53+
headers: Map[String, String]
4454
): Future[Ack] = {
4555
import endpoint.codecA
46-
val msg = Notification(endpoint.method, Some(toJson(params)), headers)
56+
val msg = Notification(endpoint.method, params.map(toJson(_)), headers)
4757

4858
// Send notifications in the order they are sent by the caller
4959
notificationsLock.synchronized {
@@ -53,14 +63,24 @@ class BloopLanguageClient(
5363

5464
def request[A, B](
5565
endpoint: Endpoint[A, B],
56-
params: A,
57-
headers: Map[String, String] = Map.empty
66+
params: A
67+
): Task[RpcResponse[B]] = request(endpoint, Some(params), Map.empty)
68+
69+
def request[A, B](
70+
endpoint: Endpoint[A, B],
71+
params: Option[A]
72+
): Task[RpcResponse[B]] = request(endpoint, params, Map.empty)
73+
74+
def request[A, B](
75+
endpoint: Endpoint[A, B],
76+
params: Option[A],
77+
headers: Map[String, String]
5878
): Task[RpcResponse[B]] = {
5979
import endpoint.{codecA, codecB}
6080
val reqId = RequestId(counter.incrementAndGet())
6181
val response = Task.create[Response] { (s, cb) =>
6282
val scheduled = s.scheduleOnce(Duration(0, "s")) {
63-
val json = Request(endpoint.method, Some(toJson(params)), reqId, headers)
83+
val json = Request(endpoint.method, params.map(toJson(_)), reqId, headers)
6484
activeServerRequests.put(reqId, cb)
6585
out.onNext(json)
6686
()

0 commit comments

Comments
 (0)