Skip to content

Commit

Permalink
Update bsp4j to 2.1.0-M1 (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski authored Aug 29, 2022
1 parent 55123ab commit 01960be
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions modules/build/src/main/scala/scala/build/bsp/BspImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 12 additions & 6 deletions modules/build/src/main/scala/scala/build/bsp/BspServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ 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}
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 {

Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ 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}

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)

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
15 changes: 10 additions & 5 deletions modules/build/src/main/scala/scala/build/bsp/package.scala
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 01960be

Please sign in to comment.