@@ -186,32 +186,33 @@ private abstract class MillBuildServer(
186186 val watchedSeq = bootstrapBridge.runBootstrap(
187187 " BSP:watch" ,
188188 new BspBootstrapBridge .Body [Seq [Watchable ]] {
189- override def apply (
190- evaluators : java.util.List [EvaluatorApi ],
191- watched : java.util.List [Watchable ]
192- ): Seq [Watchable ] = {
193- val bspEvaluators = new BspEvaluators (
194- topLevelProjectRoot,
195- evaluators.asScala.toSeq,
196- s => baseLogger.debug(s()),
197- watched.asScala.toSeq
198- )
199- val current = bspEvaluators.targetSnapshots
200- // Re-read `client` each iteration: `onConnectWithClient`
201- // may run after `startWatcherThread`, so capturing once at
202- // thread start would silently leave `client0` null forever
203- // and never deliver `buildTargetDidChange`.
204- val currentClient = client
205- if (seenAnyBootstrap && currentClient != null )
206- ChangeNotifier .notifyChanges(
207- currentClient,
208- prevTargetSnapshots,
209- current
189+ override def apply (state : BspBootstrapBridge .BootstrapState ): Seq [Watchable ] =
190+ if (state.errorOpt.isDefined && state.evaluators.isEmpty) {
191+ state.watched.asScala.toSeq
192+ } else {
193+ val bspEvaluators = new BspEvaluators (
194+ topLevelProjectRoot,
195+ state.evaluators.asScala.toSeq,
196+ s => baseLogger.debug(s()),
197+ state.watched.asScala.toSeq,
198+ state.errorOpt
210199 )
211- prevTargetSnapshots = current
212- seenAnyBootstrap = true
213- watched.asScala.toSeq
214- }
200+ val current = bspEvaluators.targetSnapshots
201+ // Re-read `client` each iteration: `onConnectWithClient`
202+ // may run after `startWatcherThread`, so capturing once at
203+ // thread start would silently leave `client0` null forever
204+ // and never deliver `buildTargetDidChange`.
205+ val currentClient = client
206+ if (seenAnyBootstrap && currentClient != null )
207+ ChangeNotifier .notifyChanges(
208+ currentClient,
209+ prevTargetSnapshots,
210+ current
211+ )
212+ prevTargetSnapshots = current
213+ seenAnyBootstrap = true
214+ state.watched.asScala.toSeq
215+ }
215216 }
216217 )
217218
@@ -369,7 +370,7 @@ private abstract class MillBuildServer(
369370 requestName : String ,
370371 logger : Logger ,
371372 future : CompletableFuture [? ],
372- run : ( Seq [ EvaluatorApi ], Seq [ Watchable ]) => Unit ,
373+ run : BspBootstrapBridge . BootstrapState => Unit ,
373374 failFuture : Throwable => Unit
374375 )
375376
@@ -425,11 +426,12 @@ private abstract class MillBuildServer(
425426 bootstrapBridge.runBootstrap(
426427 s " BSP: ${req.requestName}" ,
427428 new BspBootstrapBridge .Body [Unit ] {
428- override def apply (
429- evaluators : java.util.List [EvaluatorApi ],
430- watched : java.util.List [Watchable ]
431- ): Unit =
432- req.run(evaluators.asScala.toSeq, watched.asScala.toSeq)
429+ override def apply (state : BspBootstrapBridge .BootstrapState ): Unit =
430+ if (state.errorOpt.isDefined && state.evaluators.isEmpty) {
431+ val error = state.errorOpt.get
432+ req.logger.error(error)
433+ req.failFuture(new IllegalStateException (error))
434+ } else req.run(state)
433435 }
434436 )
435437 } catch {
@@ -473,7 +475,7 @@ private abstract class MillBuildServer(
473475 requestName = prefix,
474476 logger = logger,
475477 future = future,
476- run = (evaluators, watched) => {
478+ run = bootstrapState => {
477479 // The cancel check is also done in `runQueuedRequest` before the
478480 // bootstrap, but a request might be cancelled between bootstrap
479481 // start and body invocation; preserve that behavior here too.
@@ -482,9 +484,10 @@ private abstract class MillBuildServer(
482484 } else {
483485 val bspEvaluators = new BspEvaluators (
484486 topLevelProjectRoot,
485- evaluators,
487+ bootstrapState. evaluators.asScala.toSeq ,
486488 s => baseLogger.debug(s()),
487- watched
489+ bootstrapState.watched.asScala.toSeq,
490+ bootstrapState.errorOpt
488491 )
489492 executeWithTiming(prefix, logger, future)(block(bspEvaluators, logger))
490493 }
0 commit comments