Skip to content

Commit e31ac44

Browse files
committed
.
1 parent 64c6296 commit e31ac44

4 files changed

Lines changed: 28 additions & 24 deletions

File tree

runner/bsp/worker/src/mill/bsp/worker/BspWorkerImpl.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ object BspWorkerImpl {
2727
noWaitForBspLock: Boolean,
2828
killOther: Boolean,
2929
bspWatch: Boolean,
30-
bootstrapBridge: [T] => (
31-
String,
32-
(Seq[EvaluatorApi], Seq[Watchable], Option[String]) => T
33-
) => T
30+
bootstrapBridge: String => (
31+
Seq[EvaluatorApi],
32+
Seq[Watchable],
33+
Option[String],
34+
AutoCloseable
35+
)
3436
): mill.api.Result[(BspServerHandle, BuildClient)] = {
3537

3638
try {

runner/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ private abstract class MillBuildServer(
3636
noWaitForBspLock: Boolean,
3737
killOther: Boolean,
3838
bspWatch: Boolean,
39-
bootstrapBridge: [T] => (
40-
String,
41-
(Seq[EvaluatorApi], Seq[Watchable], Option[String]) => T
42-
) => T
39+
bootstrapBridge: String => (
40+
Seq[EvaluatorApi],
41+
Seq[Watchable],
42+
Option[String],
43+
AutoCloseable
44+
)
4345
) extends EndpointsApi with AutoCloseable {
4446

4547
import MillBuildServer.*

runner/daemon/src/mill/daemon/BspMode.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ import sun.misc.Signal
1010
import java.util.concurrent.atomic.AtomicReference
1111
import scala.concurrent.Await
1212
import scala.concurrent.duration.Duration
13-
import scala.util.{Failure, Success, Using}
13+
import scala.util.{Failure, Success}
1414

1515
private[daemon] object BspMode {
1616
type RunBootstrap =
1717
(String, Option[RunnerLauncherState], SystemStreams, Boolean) => RunnerLauncherState
1818

19-
type BootstrapBridge = [T] => (
20-
String,
21-
(Seq[EvaluatorApi], Seq[Watchable], Option[String]) => T
22-
) => T
19+
// The bridge returns the bootstrap attempt's evaluators, watched set, errorOpt,
20+
// and an AutoCloseable that releases the underlying RunnerLauncherState. The
21+
// caller (MillBuildServer) owns the closeable and decides whether to release it
22+
// immediately (broken attempt) or retain it across requests (successful attempt
23+
// serving as fallback during a future broken attempt).
24+
type BootstrapBridge =
25+
String => (Seq[EvaluatorApi], Seq[Watchable], Option[String], AutoCloseable)
2326

2427
def run(
2528
streams: SystemStreams,
@@ -33,15 +36,12 @@ private[daemon] object BspMode {
3336

3437
val bspPrevState = new AtomicReference[Option[RunnerLauncherState]](None)
3538

36-
val bootstrapBridge: BootstrapBridge = [T] =>
37-
(activeCommandMessage, body) =>
38-
Using.resource(
39-
runMillBootstrap(activeCommandMessage, bspPrevState.get(), streams, true)
40-
) { runnerState =>
41-
if (runnerState.errorOpt.isEmpty && runnerState.finalFrame.isDefined)
42-
bspPrevState.set(Some(runnerState))
43-
body(runnerState.allEvaluators, runnerState.watched, runnerState.errorOpt)
44-
}
39+
val bootstrapBridge: BootstrapBridge = activeCommandMessage => {
40+
val newState = runMillBootstrap(activeCommandMessage, bspPrevState.get(), streams, true)
41+
if (newState.errorOpt.isEmpty && newState.finalFrame.isDefined)
42+
bspPrevState.set(Some(newState))
43+
(newState.allEvaluators, newState.watched, newState.errorOpt, newState)
44+
}
4545

4646
val (bspServerHandle, _) = startBspServer(bootstrapBridge)
4747

runner/daemon/src/mill/daemon/IdeWorkerSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import mill.javalib.api.JvmWorkerUtil
99
import mill.util.{BuildInfo, Jvm}
1010

1111
private object IdeWorkerSupport {
12-
case class BspBuildClient private[daemon] (private[daemon] val value: AnyRef)
12+
final case class BspBuildClient private[daemon] (private[daemon] val value: AnyRef)
1313

1414
private val organization = Organization("com.lihaoyi")
1515

@@ -94,7 +94,7 @@ private object IdeWorkerSupport {
9494
classOf[Boolean],
9595
classOf[Boolean],
9696
classOf[Boolean],
97-
classOf[scala.Function2[?, ?, ?]]
97+
classOf[scala.Function1[?, ?]]
9898
)
9999

100100
val bspEvaluatorsClass = classLoader.loadClass("mill.bsp.worker.BspEvaluators")

0 commit comments

Comments
 (0)