diff --git a/modules/bloop-rifle/src/main/scala/scala/build/bloop/BuildServer.scala b/modules/bloop-rifle/src/main/scala/scala/build/bloop/BuildServer.scala index baeed691a7..ae0eb793f5 100644 --- a/modules/bloop-rifle/src/main/scala/scala/build/bloop/BuildServer.scala +++ b/modules/bloop-rifle/src/main/scala/scala/build/bloop/BuildServer.scala @@ -3,4 +3,3 @@ package scala.build.bloop import ch.epfl.scala.bsp4j trait BuildServer extends bsp4j.BuildServer with bsp4j.ScalaBuildServer with bsp4j.JavaBuildServer - with ScalaDebugServer diff --git a/modules/bloop-rifle/src/main/scala/scala/build/bloop/ScalaDebugServer.scala b/modules/bloop-rifle/src/main/scala/scala/build/bloop/ScalaDebugServer.scala deleted file mode 100644 index 8f54089aa8..0000000000 --- a/modules/bloop-rifle/src/main/scala/scala/build/bloop/ScalaDebugServer.scala +++ /dev/null @@ -1,11 +0,0 @@ -package scala.build.bloop; - -import ch.epfl.scala.bsp4j.{DebugSessionAddress, DebugSessionParams} -import org.eclipse.lsp4j.jsonrpc.services.JsonRequest - -import java.util.concurrent.CompletableFuture; - -trait ScalaDebugServer { - @JsonRequest("debugSession/start") - def buildTargetDebugSession(params: DebugSessionParams): CompletableFuture[DebugSessionAddress] -} diff --git a/modules/bloop-rifle/src/main/scala/scala/build/bloop/ScalaDebugServerForwardStubs.scala b/modules/bloop-rifle/src/main/scala/scala/build/bloop/ScalaDebugServerForwardStubs.scala deleted file mode 100644 index b964048d41..0000000000 --- a/modules/bloop-rifle/src/main/scala/scala/build/bloop/ScalaDebugServerForwardStubs.scala +++ /dev/null @@ -1,13 +0,0 @@ -package scala.build.bloop - -import ch.epfl.scala.{bsp4j => b} - -import java.util.concurrent.CompletableFuture - -trait ScalaDebugServerForwardStubs extends ScalaDebugServer { - protected def forwardTo: ScalaDebugServer - override def buildTargetDebugSession( - params: b.DebugSessionParams - ): CompletableFuture[b.DebugSessionAddress] = - forwardTo.buildTargetDebugSession(params) -} diff --git a/modules/build/src/main/scala/scala/build/bsp/BspClient.scala b/modules/build/src/main/scala/scala/build/bsp/BspClient.scala index f5c6ed18dc..22a9ed9268 100644 --- a/modules/build/src/main/scala/scala/build/bsp/BspClient.scala +++ b/modules/build/src/main/scala/scala/build/bsp/BspClient.scala @@ -199,7 +199,7 @@ class BspClient( diag.relatedInformation.foreach { relatedInformation => val location = new Location(path.toNIO.toUri.toASCIIString, range) val related = new b.DiagnosticRelatedInformation(location, relatedInformation.message) - bDiag.setRelatedInformation(related) + bDiag.setRelatedInformation(List(related).asJava) } bDiag.setSeverity(diag.severity.toBsp4j) bDiag.setSource("scala-cli") diff --git a/modules/build/src/main/scala/scala/build/bsp/BspImpl.scala b/modules/build/src/main/scala/scala/build/bsp/BspImpl.scala index cc3281037f..9b2a381ef6 100644 --- a/modules/build/src/main/scala/scala/build/bsp/BspImpl.scala +++ b/modules/build/src/main/scala/scala/build/bsp/BspImpl.scala @@ -10,7 +10,7 @@ import java.io.{InputStream, OutputStream} import java.util.concurrent.{CompletableFuture, Executor} import scala.build.* import scala.build.EitherCps.{either, value} -import scala.build.bloop.{BloopServer, ScalaDebugServer} +import scala.build.bloop.BloopServer import scala.build.compiler.BloopCompiler import scala.build.errors.{BuildException, Diagnostic, ParsingInputsException} import scala.build.internal.{Constants, CustomCodeWrapper} @@ -423,7 +423,7 @@ final class BspImpl( bloopSession.update(null, currentBloopSession, "BSP server already initialized") val actualLocalServer: b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer - with ScalaDebugServer with ScalaScriptBuildServer with HasGeneratedSources = + with ScalaScriptBuildServer with HasGeneratedSources = new BuildServerProxy( () => bloopSession.get().bspServer, () => onReload() diff --git a/modules/build/src/main/scala/scala/build/bsp/BspServer.scala b/modules/build/src/main/scala/scala/build/bsp/BspServer.scala index 4ca0b9b662..d02aed74aa 100644 --- a/modules/build/src/main/scala/scala/build/bsp/BspServer.scala +++ b/modules/build/src/main/scala/scala/build/bsp/BspServer.scala @@ -9,7 +9,6 @@ import java.util.concurrent.{CompletableFuture, TimeUnit} import java.util as ju import scala.build.Logger -import scala.build.bloop.{ScalaDebugServer, ScalaDebugServerForwardStubs} import scala.build.internal.Constants import scala.build.options.Scope import scala.concurrent.{Future, Promise} @@ -17,13 +16,12 @@ import scala.jdk.CollectionConverters.* import scala.util.Random class BspServer( - bloopServer: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer & ScalaDebugServer, + bloopServer: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer, compile: (() => CompletableFuture[b.CompileResult]) => CompletableFuture[b.CompileResult], logger: Logger, presetIntelliJ: Boolean = false ) extends b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer with BuildServerForwardStubs with ScalaScriptBuildServer - with ScalaDebugServerForwardStubs with ScalaBuildServerForwardStubs with JavaBuildServerForwardStubs with HasGeneratedSourcesImpl { @@ -108,7 +106,12 @@ class BspServer( logger.debug(s"invalid target in Test request: $target") params } - + private def check(params: b.DebugSessionParams): params.type = { + val invalidTargets = params.getTargets.asScala.filter(!validTarget(_)) + for (target <- invalidTargets) + logger.debug(s"invalid target in Test request: $target") + params + } private def mapGeneratedSources(res: b.SourcesResult): Unit = { val gen = generatedSources.values.toVector for { @@ -123,8 +126,7 @@ class BspServer( } } - protected def forwardTo - : b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer & ScalaDebugServer = bloopServer + protected def forwardTo: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer = bloopServer private val supportedLanguages: ju.List[String] = List( "scala", @@ -215,6 +217,10 @@ class BspServer( override def buildTargetTest(params: b.TestParams): CompletableFuture[b.TestResult] = super.buildTargetTest(check(params)) + override def debugSessionStart(params: b.DebugSessionParams) + : CompletableFuture[b.DebugSessionAddress] = + super.debugSessionStart(check(params)) + override def workspaceBuildTargets(): CompletableFuture[b.WorkspaceBuildTargetsResult] = super.workspaceBuildTargets().thenApply { res => maybeUpdateProjectTargetUri(res) diff --git a/modules/build/src/main/scala/scala/build/bsp/BuildServerForwardStubs.scala b/modules/build/src/main/scala/scala/build/bsp/BuildServerForwardStubs.scala index 0f0727ae12..3cab5a4ffc 100644 --- a/modules/build/src/main/scala/scala/build/bsp/BuildServerForwardStubs.scala +++ b/modules/build/src/main/scala/scala/build/bsp/BuildServerForwardStubs.scala @@ -70,6 +70,11 @@ trait BuildServerForwardStubs extends b.BuildServer { forwardTo.buildTargetTest(params) .handle(fatalExceptionHandler("buildTargetTest", params)) + override def debugSessionStart(params: b.DebugSessionParams) + : CompletableFuture[b.DebugSessionAddress] = + forwardTo.debugSessionStart(params) + .handle(fatalExceptionHandler("debugSessionStart", params)) + override def workspaceBuildTargets(): CompletableFuture[b.WorkspaceBuildTargetsResult] = forwardTo.workspaceBuildTargets() .handle(fatalExceptionHandler("workspaceBuildTargets")) diff --git a/modules/build/src/main/scala/scala/build/bsp/BuildServerProxy.scala b/modules/build/src/main/scala/scala/build/bsp/BuildServerProxy.scala index 1cb0493bdb..a0e66d0e25 100644 --- a/modules/build/src/main/scala/scala/build/bsp/BuildServerProxy.scala +++ b/modules/build/src/main/scala/scala/build/bsp/BuildServerProxy.scala @@ -4,7 +4,6 @@ import ch.epfl.scala.{bsp4j => b} import java.util.concurrent.CompletableFuture -import scala.build.bloop.ScalaDebugServer import scala.build.options.Scope import scala.build.{GeneratedSource, Inputs} @@ -12,7 +11,7 @@ class BuildServerProxy( bspServer: () => BspServer, onReload: () => CompletableFuture[Object] ) extends b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer - with ScalaDebugServer with ScalaScriptBuildServer with HasGeneratedSources { + with ScalaScriptBuildServer with HasGeneratedSources { override def buildInitialize(params: b.InitializeBuildParams) : CompletableFuture[b.InitializeBuildResult] = bspServer().buildInitialize(params) @@ -67,9 +66,9 @@ class BuildServerProxy( override def buildTargetJavacOptions(params: b.JavacOptionsParams) : CompletableFuture[b.JavacOptionsResult] = bspServer().buildTargetJavacOptions(params) - - override def buildTargetDebugSession(params: b.DebugSessionParams) - : CompletableFuture[b.DebugSessionAddress] = bspServer().buildTargetDebugSession(params) + override def debugSessionStart(params: b.DebugSessionParams) + : CompletableFuture[b.DebugSessionAddress] = + bspServer().debugSessionStart(params) override def buildTargetWrappedSources(params: WrappedSourcesParams) : CompletableFuture[WrappedSourcesResult] = bspServer().buildTargetWrappedSources(params) diff --git a/modules/build/src/main/scala/scala/build/bsp/LoggingBuildServer.scala b/modules/build/src/main/scala/scala/build/bsp/LoggingBuildServer.scala index f158d17147..f05968fc51 100644 --- a/modules/build/src/main/scala/scala/build/bsp/LoggingBuildServer.scala +++ b/modules/build/src/main/scala/scala/build/bsp/LoggingBuildServer.scala @@ -41,6 +41,9 @@ trait LoggingBuildServer extends b.BuildServer { underlying.buildTargetSources(pprint.err.log(params)).logF override def buildTargetTest(params: b.TestParams): CompletableFuture[b.TestResult] = underlying.buildTargetTest(pprint.err.log(params)).logF + override def debugSessionStart(params: b.DebugSessionParams) + : CompletableFuture[b.DebugSessionAddress] = + underlying.debugSessionStart(pprint.err.log(params)).logF override def workspaceBuildTargets(): CompletableFuture[b.WorkspaceBuildTargetsResult] = underlying.workspaceBuildTargets().logF override def workspaceReload(): CompletableFuture[Object] = diff --git a/modules/build/src/main/scala/scala/build/bsp/package.scala b/modules/build/src/main/scala/scala/build/bsp/package.scala index fc2ba59c46..05ccc91cee 100644 --- a/modules/build/src/main/scala/scala/build/bsp/package.scala +++ b/modules/build/src/main/scala/scala/build/bsp/package.scala @@ -1,10 +1,10 @@ package scala.build -import ch.epfl.scala.{bsp4j => b} +import ch.epfl.scala.bsp4j as b +import ch.epfl.scala.bsp4j.SourcesItem import java.util.concurrent.CompletableFuture - -import scala.jdk.CollectionConverters._ +import scala.jdk.CollectionConverters.* package object bsp { @@ -44,7 +44,10 @@ package object bsp { implicit class SourcesResultExt(private val res: b.SourcesResult) extends AnyVal { def duplicate(): b.SourcesResult = - new b.SourcesResult(res.getItems().asScala.toList.map(_.duplicate()).asJava) + new b.SourcesResult( + res.getItems().asScala.toList + .map((item: SourcesItem) => item.duplicate()).asJava + ) } implicit class BuildTargetCapabilitiesExt( @@ -102,7 +105,9 @@ package object bsp { def duplicate(): b.Diagnostic = { val diag0 = new b.Diagnostic(diag.getRange.duplicate(), diag.getMessage) diag0.setCode(diag.getCode) - diag0.setRelatedInformation(Option(diag.getRelatedInformation).map(_.duplicate()).orNull) + diag0.setRelatedInformation( + Option(diag.getRelatedInformation).map(_.asScala.map(_.duplicate()).asJava).orNull + ) diag0.setSeverity(diag.getSeverity) diag0.setSource(diag.getSource) diag0 diff --git a/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala b/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala index 99f9264b5c..fb3118333c 100644 --- a/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala +++ b/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala @@ -15,6 +15,7 @@ import scala.build.internal.CustomProgressBarRefreshDisplay import scala.build.{ConsoleBloopBuildClient, Logger, Position} import scala.collection.mutable import scala.scalanative.{build => sn} +import scala.jdk.CollectionConverters._ class CliLogger( val verbosity: Int, @@ -88,7 +89,7 @@ class CliLogger( } { val location = new Location(filePath.toNIO.toUri.toASCIIString, range) val related = new b.DiagnosticRelatedInformation(location, info.message) - diag.setRelatedInformation(related) + diag.setRelatedInformation(List(related).asJava) } for (file <- f.path) { diff --git a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala index 8f6e2581e5..2f6fc6daa4 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala @@ -1180,7 +1180,7 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String]) strictlyCheckMessage = false ) - val relatedInformation = updateActionableDiagnostic.getRelatedInformation() + val relatedInformation = updateActionableDiagnostic.getRelatedInformation().asScala.head expect(relatedInformation.getMessage.contains("com.lihaoyi::os-lib:")) expect( relatedInformation.getLocation().getUri() == (root / fileName).toNIO.toUri.toASCIIString diff --git a/project/deps.sc b/project/deps.sc index add929e85d..e138b488fb 100644 --- a/project/deps.sc +++ b/project/deps.sc @@ -68,7 +68,7 @@ object Deps { def asm = ivy"org.ow2.asm:asm:9.3" // Force using of 2.13 - is there a better way? def bloopConfig = ivy"io.github.alexarchambault.bleep:bloop-config_2.13:1.5.3-sc-1" - def bsp4j = ivy"ch.epfl.scala:bsp4j:2.0.0" + def bsp4j = ivy"ch.epfl.scala:bsp4j:2.1.0-M1" def caseApp = ivy"com.github.alexarchambault:case-app_2.13:2.1.0-M15" def collectionCompat = ivy"org.scala-lang.modules::scala-collection-compat:2.8.1" // Force using of 2.13 - is there a better way?