Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): Update bsp4s from 2.1.0-M5 to 2.1.0-M6 #2159

Merged
merged 2 commits into from
Sep 27, 2023
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
4 changes: 2 additions & 2 deletions backend/src/main/scala/bloop/io/ParallelOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import java.nio.file.attribute.BasicFileAttributes
import java.util.concurrent.ConcurrentHashMap

import scala.concurrent.Promise
import scala.util.control.NonFatal

import bloop.logging.Logger
import bloop.task.Task

import monix.eval.{Task => MonixTask}
Expand All @@ -22,8 +24,6 @@ import monix.execution.cancelables.CompositeCancelable
import monix.reactive.Consumer
import monix.reactive.MulticastStrategy
import monix.reactive.Observable
import bloop.logging.Logger
import scala.util.control.NonFatal

object ParallelOps {

Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/scala/bloop/task/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sealed trait Task[+A] { self =>
}

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

final def doOnFinish(f: Option[Throwable] => Task[Unit]): Task[A] =
self.materialize.flatMap { v =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

import scala.util.control.NonFatal

import _root_.bloop.io.AbsolutePath
import _root_.bloop.logging.DebugFilter
import _root_.bloop.logging.{Logger => BloopLogger}
Expand All @@ -27,7 +29,6 @@ import xsbti.ComponentProvider
import xsbti.Logger
import xsbti.compile.ClasspathOptionsUtil
import xsbti.compile.CompilerBridgeProvider
import scala.util.control.NonFatal

object BloopComponentCompiler {
import xsbti.compile.ScalaInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import java.io.File
import java.nio.file.Path
import java.{util => ju}

import scala.collection.JavaConverters._

import sbt.internal.inc.Analysis
import sbt.internal.inc.Compilation
import sbt.internal.inc.Incremental
Expand All @@ -15,6 +17,9 @@ import sbt.util.InterfaceUtil
import xsbt.api.APIUtil
import xsbt.api.HashAPI
import xsbt.api.NameHashing
import xsbti.Action
import xsbti.DiagnosticCode
import xsbti.DiagnosticRelatedInformation
import xsbti.Position
import xsbti.Problem
import xsbti.Severity
Expand All @@ -35,9 +40,6 @@ import xsbti.compile.ClassFileManager
import xsbti.compile.IncOptions
import xsbti.compile.Output
import xsbti.compile.analysis.ReadStamps
import xsbti.{Action, DiagnosticCode, DiagnosticRelatedInformation}

import collection.JavaConverters._

trait IBloopAnalysisCallback extends xsbti.AnalysisCallback2 {
def get: Analysis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import java.io.File
import java.nio.file.Path
import java.{util => ju}

import scala.collection.JavaConverters._

import sbt.internal.inc.Analysis
import sbt.internal.inc.Compilation
import sbt.internal.inc.Incremental
Expand All @@ -15,6 +17,9 @@ import sbt.util.InterfaceUtil
import xsbt.api.APIUtil
import xsbt.api.HashAPI
import xsbt.api.NameHashing
import xsbti.Action
import xsbti.DiagnosticCode
import xsbti.DiagnosticRelatedInformation
import xsbti.Position
import xsbti.Problem
import xsbti.Severity
Expand All @@ -35,9 +40,6 @@ import xsbti.compile.ClassFileManager
import xsbti.compile.IncOptions
import xsbti.compile.Output
import xsbti.compile.analysis.ReadStamps
import xsbti.{Action, DiagnosticCode, DiagnosticRelatedInformation}

import collection.JavaConverters._

/**
* This class provides a thread-safe implementation of `xsbti.AnalysisCallback` which is required to compile with the
Expand Down
85 changes: 49 additions & 36 deletions frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ final class BloopBspServices(
.requestAsync(endpoints.BuildTarget.run)(p => schedule(run(p)))
.requestAsync(endpoints.BuildTarget.cleanCache)(p => schedule(clean(p)))
.requestAsync(endpoints.BuildTarget.scalaMainClasses)(p => schedule(scalaMainClasses(p)))
.requestAsync(ScalaTestClasses.endpoint)(p => schedule(scalaTestClasses(p)))
.requestAsync(endpoints.BuildTarget.scalaTestClasses)(p => schedule(scalaTestClasses(p)))
.requestAsync(endpoints.BuildTarget.dependencySources)(p => schedule(dependencySources(p)))
.requestAsync(endpoints.DebugSession.start)(p => schedule(startDebugSession(p)))
.requestAsync(endpoints.BuildTarget.jvmTestEnvironment)(p => schedule(jvmTestEnvironment(p)))
Expand Down Expand Up @@ -316,6 +316,7 @@ final class BloopBspServices(
jvmRunEnvironmentProvider = Some(true),
canReload = Some(false)
),
None,
None
)
)
Expand Down Expand Up @@ -567,12 +568,12 @@ final class BloopBspServices(

def scalaTestClasses(
params: bsp.ScalaTestClassesParams
): BspEndpointResponse[ScalaTestClassesResult] =
): BspEndpointResponse[bsp.ScalaTestClassesResult] =
ifInitialized(params.originId) { (state: State, logger: BspServerLogger) =>
mapToProjects(params.targets, state) match {
case Left(error) =>
logger.error(error)
Task.now((state, Right(ScalaTestClassesResult(Nil))))
Task.now((state, Right(bsp.ScalaTestClassesResult(Nil))))

case Right(projects) =>
val subTasks = projects.toList.filter(p => TestTask.isTestProject(p._2)).map {
Expand All @@ -583,15 +584,15 @@ final class BloopBspServices(
.groupBy(_.framework)
.map {
case (framework, classes) =>
ScalaTestClassesItem(id, classes.flatMap(_.classes), Some(framework))
bsp.ScalaTestClassesItem(id, Some(framework), classes.flatMap(_.classes))
}
.toList
}
item
}

Task.sequence(subTasks).map { items =>
val result = ScalaTestClassesResult(items.flatten)
val result = bsp.ScalaTestClassesResult(items.flatten)
(state, Right(result))
}
}
Expand All @@ -608,33 +609,43 @@ final class BloopBspServices(
def convert[A: JsonValueCodec](
f: A => Either[String, Debuggee]
): Either[Response.Error, Debuggee] = {
Try(readFromArray[A](params.data.value)) match {
case Failure(error) =>
Left(Response.invalidRequest(error.getMessage()))
case Success(params) =>
f(params) match {
case Right(adapter) => Right(adapter)
case Left(error) => Left(Response.invalidRequest(error))
params.data match {
case Some(data) =>
Try(readFromArray[A](data.value)) match {
case Failure(error) =>
Left(Response.invalidRequest(error.getMessage()))
case Success(params) =>
f(params) match {
case Right(adapter) => Right(adapter)
case Left(error) => Left(Response.invalidRequest(error))
}
}
case None =>
Left(Response.invalidRequest("No debug data available"))
}

}

params.dataKind match {
case bsp.DebugSessionParamsDataKind.ScalaMainClass =>
case Some(bsp.DebugSessionParamsDataKind.ScalaMainClass) =>
convert[bsp.ScalaMainClass](main =>
BloopDebuggeeRunner.forMainClass(projects, main, state, ioScheduler)
)
case bsp.DebugSessionParamsDataKind.ScalaTestSuites =>
case Some(bsp.TestParamsDataKind.ScalaTestSuites) =>
implicit val codec = JsonCodecMaker.make[List[String]]
convert[List[String]](classNames => {
val testClasses = ScalaTestSuites(classNames)
val testClasses = bsp.ScalaTestSuites(
classNames.map(className => bsp.ScalaTestSuiteSelection(className, Nil)),
Nil,
Nil
)
BloopDebuggeeRunner.forTestSuite(projects, testClasses, state, ioScheduler)
})
case "scala-test-suites-selection" =>
convert[ScalaTestSuites](testClasses => {
case Some(bsp.TestParamsDataKind.ScalaTestSuitesSelection) =>
convert[bsp.ScalaTestSuites](testClasses => {
BloopDebuggeeRunner.forTestSuite(projects, testClasses, state, ioScheduler)
})
case bsp.DebugSessionParamsDataKind.ScalaAttachRemote =>
case Some(bsp.DebugSessionParamsDataKind.ScalaAttachRemote) =>
Right(BloopDebuggeeRunner.forAttachRemote(state, ioScheduler, projects))
case dataKind => Left(Response.invalidRequest(s"Unsupported data kind: $dataKind"))
}
Expand Down Expand Up @@ -684,7 +695,9 @@ final class BloopBspServices(
.map(_ => backgroundDebugServers -= handler.uri)
.runAsync(ioScheduler)
backgroundDebugServers += handler.uri -> listenAndUnsubscribe
Task.now((state, Right(new bsp.DebugSessionAddress(handler.uri.toString))))
Task.now(
(state, Right(new bsp.DebugSessionAddress(bsp.Uri(handler.uri.toString()))))
)

case Left(error) =>
Task.now((state, Left(error)))
Expand All @@ -704,7 +717,7 @@ final class BloopBspServices(
List(project),
Nil,
testFilter,
ScalaTestSuites.empty,
bsp.ScalaTestSuites(Nil, Nil, Nil),
handler,
mode = RunMode.Normal
)
Expand Down Expand Up @@ -804,21 +817,21 @@ final class BloopBspServices(
def findMainClasses(state: State, project: Project): List[bsp.ScalaMainClass] =
for {
className <- Tasks.findMainClasses(state, project)
} yield bsp.ScalaMainClass(className, Nil, Nil, Nil)
} yield bsp.ScalaMainClass(className, Nil, Nil, None)

ifInitialized(params.originId) { (state: State, logger: BspServerLogger) =>
mapToProjects(params.targets, state) match {
case Left(error) =>
logger.error(error)
Task.now((state, Right(bsp.ScalaMainClassesResult(Nil))))
Task.now((state, Right(bsp.ScalaMainClassesResult(Nil, params.originId))))

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

val result = new bsp.ScalaMainClassesResult(items)
val result = new bsp.ScalaMainClassesResult(items, params.originId)
Task.now((state, Right(result)))
}
}
Expand All @@ -843,7 +856,7 @@ final class BloopBspServices(
val cmd = Commands.Run(List(project.name))
Interpreter.getMainClass(state, project, cmd.main) match {
case Right(name) =>
Right(new bsp.ScalaMainClass(name, cmd.args, Nil, Nil))
Right(new bsp.ScalaMainClass(name, cmd.args, Nil, None))
case Left(_) =>
Left(new IllegalStateException(s"Main class for project $project not found"))
}
Expand Down Expand Up @@ -871,16 +884,16 @@ final class BloopBspServices(
project,
config,
cwd,
mainClass.`class`,
mainClass.className,
mainArgs,
skipJargs = false,
mainClass.environmentVariables,
mainClass.environmentVariables.getOrElse(Nil),
RunMode.Normal
)
case platform @ Platform.Native(config, _, _) =>
val cmd = Commands.Run(List(project.name))
val target = ScalaNativeToolchain.linkTargetFrom(project, config)
linkMainWithNative(cmd, project, state, mainClass.`class`, target, platform)
linkMainWithNative(cmd, project, state, mainClass.className, target, platform)
.flatMap { state =>
val args = (target.syntax +: cmd.args).toArray
if (!state.status.isOk) Task.now(state)
Expand All @@ -889,7 +902,7 @@ final class BloopBspServices(
case platform @ Platform.Js(config, _, _) =>
val cmd = Commands.Run(List(project.name))
val target = ScalaJsToolchain.linkTargetFrom(project, config)
linkMainWithJs(cmd, project, state, mainClass.`class`, target, platform)
linkMainWithJs(cmd, project, state, mainClass.className, target, platform)
.flatMap { state =>
// We use node to run the program (is this a special case?)
val args = ("node" +: target.syntax +: cmd.args).toArray
Expand Down Expand Up @@ -1040,10 +1053,10 @@ final class BloopBspServices(
}

val capabilities = bsp.BuildTargetCapabilities(
canCompile = true,
canTest = true,
canRun = true,
canDebug = true
canCompile = Some(true),
canTest = Some(true),
canRun = Some(true),
canDebug = Some(true)
)
val isJavaOnly = p.scalaInstance.isEmpty
val languageIds =
Expand Down Expand Up @@ -1256,8 +1269,8 @@ final class BloopBspServices(
bsp.ScalacOptionsItem(
target = target,
options = project.scalacOptions.toList,
classpath = classpath,
classDirectory = classesDir
classpath = classpath.map(_.value),
classDirectory = classesDir.value
)
}.toList
)
Expand Down Expand Up @@ -1290,8 +1303,8 @@ final class BloopBspServices(
bsp.JavacOptionsItem(
target = target,
options = project.javacOptions.toList,
classpath = classpath,
classDirectory = classesDir
classpath = classpath.map(_.value),
classDirectory = classesDir.value
)
}.toList
)
Expand Down
32 changes: 26 additions & 6 deletions frontend/src/main/scala/bloop/bsp/BloopLanguageClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ class BloopLanguageClient(

def notify[A](
endpoint: Endpoint[A, Unit],
params: A,
headers: Map[String, String] = Map.empty
params: A
): Future[Ack] = notify(endpoint, Some(params), Map.empty)

def notify[A](
endpoint: Endpoint[A, Unit],
params: Option[A]
): Future[Ack] = notify(endpoint, params, Map.empty)

def notify[A](
endpoint: Endpoint[A, Unit],
params: Option[A],
headers: Map[String, String]
): Future[Ack] = {
import endpoint.codecA
val msg = Notification(endpoint.method, Some(toJson(params)), headers)
val msg = Notification(endpoint.method, params.map(toJson(_)), headers)

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

def request[A, B](
endpoint: Endpoint[A, B],
params: A,
headers: Map[String, String] = Map.empty
params: A
): Task[RpcResponse[B]] = request(endpoint, Some(params), Map.empty)

def request[A, B](
endpoint: Endpoint[A, B],
params: Option[A]
): Task[RpcResponse[B]] = request(endpoint, params, Map.empty)

def request[A, B](
endpoint: Endpoint[A, B],
params: Option[A],
headers: Map[String, String]
): Task[RpcResponse[B]] = {
import endpoint.{codecA, codecB}
val reqId = RequestId(counter.incrementAndGet())
val response = Task.create[Response] { (s, cb) =>
val scheduled = s.scheduleOnce(Duration(0, "s")) {
val json = Request(endpoint.method, Some(toJson(params)), reqId, headers)
val json = Request(endpoint.method, params.map(toJson(_)), reqId, headers)
activeServerRequests.put(reqId, cb)
out.onNext(json)
()
Expand Down
Loading
Loading