trigger an additional reload only if it's a ConsoleChannel, an interactive NetworkChannel, or a NetworkChannel where the exec ID is known, to ensure the response can be propagated correctly #8371

This commit is contained in:
Aleksandra Zdrojowa 2025-11-17 10:18:56 +01:00
parent 5d42dd65c8
commit 8770ad9de8
1 changed files with 17 additions and 4 deletions

View File

@ -10,6 +10,7 @@ package sbt
import sbt.BasicCommandStrings.{ StashOnFailure, networkExecPrefix }
import sbt.ProjectExtra.extract
import sbt.internal.{ ConsoleChannel, FastTrackCommands, ShutdownHooks, SysProp, TaskProgress }
import sbt.internal.langserver.ErrorCodes
import sbt.internal.nio.CheckBuildSources.CheckBuildSourcesKey
import sbt.internal.protocol.JsonRpcResponseError
@ -20,7 +21,6 @@ import sbt.internal.util.{
Prompt,
Terminal as ITerminal
}
import sbt.internal.{ FastTrackCommands, ShutdownHooks, SysProp, TaskProgress }
import sbt.io.{ IO, Using }
import sbt.protocol.*
import sbt.util.{ Logger, LoggerContext }
@ -31,6 +31,7 @@ import java.util.concurrent.RejectedExecutionException
import scala.annotation.tailrec
import scala.concurrent.duration.*
import scala.util.control.NonFatal
import sbt.internal.server.NetworkChannel
import java.text.ParseException
@ -301,10 +302,22 @@ private[sbt] object MainLoop:
.remove(Keys.terminalKey)
.remove(Keys.currentCommandProgress)
}
val channel = channelName.flatMap(exchange.channelForName)
val (canReload, useLoadp) = channel match
case Some(nc: NetworkChannel) =>
val isInteractive = nc.isInteractive
(isInteractive || exec.execId.nonEmpty, !isInteractive)
case Some(_: ConsoleChannel) => (true, false)
case _ => (false, false)
state.get(CheckBuildSourcesKey) match {
case Some(cbs) =>
if (!cbs.needsReload(state, exec)) process()
else Exec("reload", None) +: exec +: state.remove(CheckBuildSourcesKey)
case Some(cbs) if canReload && cbs.needsReload(state, exec) =>
val loadExec =
if (useLoadp) Exec("loadp", exec.execId, exec.source)
else Exec("reload", exec.source)
loadExec +: exec +: state.remove(CheckBuildSourcesKey)
case _ => process()
}
} catch {