Skip to content

Commit e4a5af3

Browse files
committed
Add BspClient to the BspServer constructor arguments
1 parent fcbfa20 commit e4a5af3

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

modules/build/src/main/scala/scala/build/bsp/BspImpl.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ final class BspImpl(
433433
)
434434
lazy val bspServer = new BspServer(
435435
remoteServer.bloopServer.server,
436+
localClient,
436437
doCompile =>
437438
compile(bloopSession0, threads.prepareBuildExecutor, reloadableOptions, doCompile),
438439
logger,
@@ -615,15 +616,16 @@ final class BspImpl(
615616
}
616617
else newBloopSession0
617618

618-
if (previousInputs.projectName != preBuildProject.mainScope.project.projectName)
619-
for (client <- finalBloopSession.bspServer.clientOpt) {
620-
val newTargetIds = finalBloopSession.bspServer.targetIds
621-
val events =
622-
newTargetIds.map(buildTargetIdToEvent(_, b.BuildTargetEventKind.CREATED)) ++
623-
previousTargetIds.map(buildTargetIdToEvent(_, b.BuildTargetEventKind.DELETED))
624-
val didChangeBuildTargetParams = new b.DidChangeBuildTarget(events.asJava)
625-
client.onBuildTargetDidChange(didChangeBuildTargetParams)
626-
}
619+
// TODO MG
620+
if (previousInputs.projectName != preBuildProject.mainScope.project.projectName) {
621+
val client = finalBloopSession.bspServer.bspCLient
622+
val newTargetIds = finalBloopSession.bspServer.targetIds
623+
val events =
624+
newTargetIds.map(buildTargetIdToEvent(_, b.BuildTargetEventKind.CREATED)) ++
625+
previousTargetIds.map(buildTargetIdToEvent(_, b.BuildTargetEventKind.DELETED))
626+
val didChangeBuildTargetParams = new b.DidChangeBuildTarget(events.asJava)
627+
client.onBuildTargetDidChange(didChangeBuildTargetParams)
628+
}
627629
CompletableFuture.completedFuture(new Object())
628630
}
629631
}

modules/build/src/main/scala/scala/build/bsp/BspServer.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import scala.util.Random
1818

1919
class BspServer(
2020
bloopServer: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer & b.JvmBuildServer,
21+
client: BuildClient,
2122
compile: (() => CompletableFuture[b.CompileResult]) => CompletableFuture[b.CompileResult],
2223
logger: Logger,
2324
presetIntelliJ: Boolean = false
@@ -28,13 +29,11 @@ class BspServer(
2829
with JvmBuildServerForwardStubs
2930
with ManagesBuildTargetsImpl {
3031

31-
private var client: Option[BuildClient] = None
32+
val bspCLient = client
3233

3334
@volatile private var intelliJ: Boolean = presetIntelliJ
3435
def isIntelliJ: Boolean = intelliJ
3536

36-
def clientOpt: Option[BuildClient] = client
37-
3837
@volatile private var extraDependencySources: Seq[os.Path] = Nil
3938
def setExtraDependencySources(sourceJars: Seq[os.Path]): Unit = {
4039
extraDependencySources = sourceJars
@@ -52,7 +51,7 @@ class BspServer(
5251
val message =
5352
s"Fatal error has occured within $context. Shutting down the server:\n ${sw.toString}"
5453
System.err.println(message)
55-
client.foreach(_.onBuildLogMessage(new LogMessageParams(MessageType.ERROR, message)))
54+
client.onBuildLogMessage(new LogMessageParams(MessageType.ERROR, message))
5655

5756
// wait random bit before shutting down server to reduce risk of multiple scala-cli instances starting bloop at the same time
5857
val timeout = Random.nextInt(400)

modules/build/src/test/scala/scala/build/tests/BspServerTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BspServerTests extends TestUtil.ScalaCliBuildSuite {
3838
workspace: os.Path,
3939
scope: Scope = Scope.Main
4040
): ScalaScriptBuildServer = {
41-
val bspServer = new BspServer(null, null, null)
41+
val bspServer = new BspServer(null, null, null, null)
4242
bspServer.addTarget(projectName, workspace, scope, generatedSources)
4343

4444
bspServer

0 commit comments

Comments
 (0)