-
-
Notifications
You must be signed in to change notification settings - Fork 401
Send BSP onBuildTargetDidChange notifications to clients when the build changes #4957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alexarchambault
wants to merge
9
commits into
com-lihaoyi:main
Choose a base branch
from
alexarchambault:bsp-stuff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,563
−187
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
632d53f
Add new integration.bsp-util module
alexarchambault 1c9e364
Fix file name
alexarchambault cc1de3b
Clean-up unused BspContextApi
alexarchambault 8d249b7
Automatically reload BSP server upon meta-build change
alexarchambault 02c4856
More careful stream handling when starting BSP server
alexarchambault 163a44f
Copy meta-build classes in an evaluator specific directory
alexarchambault 77b1bfc
Add comment
alexarchambault f59f85c
NIT
alexarchambault 53f9482
Suspend BSP requests when we re-compile the build
alexarchambault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,21 +45,98 @@ private class MillBuildServer( | |
// progresses through: | ||
// | ||
// Set when the client connects | ||
protected var client: BuildClient = scala.compiletime.uninitialized | ||
protected var client: BuildClient = null | ||
// Set when the `buildInitialize` message comes in | ||
protected var sessionInfo: SessionInfo = scala.compiletime.uninitialized | ||
// Set when the `MillBuildBootstrap` completes and the evaluators are available | ||
private var bspEvaluators: Promise[BspEvaluators] = Promise[BspEvaluators]() | ||
private var savedPreviousEvaluators = Option.empty[BspEvaluators] | ||
// Set when a session is completed, either due to reload or shutdown | ||
private[worker] var sessionResult: Option[BspServerResult] = None | ||
private[worker] var sessionResult = Promise[BspServerResult]() | ||
|
||
def initialized = sessionInfo != null | ||
|
||
def updateEvaluator(evaluatorsOpt: Option[Seq[EvaluatorApi]]): Unit = { | ||
def updateEvaluator(evaluatorsOpt: Option[Seq[EvaluatorApi]], errored: Boolean): Unit = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have ScalaDoc explaining what |
||
debug(s"Updating Evaluator: $evaluatorsOpt") | ||
val previousEvaluatorsOpt = bspEvaluators.future.value.flatMap(_.toOption) | ||
.orElse(savedPreviousEvaluators) | ||
if (bspEvaluators.isCompleted) bspEvaluators = Promise[BspEvaluators]() // replace the promise | ||
evaluatorsOpt.foreach { evaluators => | ||
bspEvaluators.success(new BspEvaluators(topLevelProjectRoot, evaluators, s => debug(s()))) | ||
evaluatorsOpt match { | ||
case None => | ||
savedPreviousEvaluators = previousEvaluatorsOpt | ||
case Some(evaluators) => | ||
val updatedEvaluators = | ||
if (errored) | ||
previousEvaluatorsOpt.map(_.evaluators) match { | ||
case Some(previous) => | ||
evaluators.headOption match { | ||
case None => // ??? | ||
previous | ||
case Some(headEvaluator) => | ||
val idx = previous.indexWhere(_.outPathJava == headEvaluator.outPathJava) | ||
if (idx < 0) // ??? | ||
evaluators | ||
else | ||
previous.take(idx) ++ evaluators | ||
} | ||
case None => evaluators | ||
} | ||
else | ||
evaluators | ||
val bspEvaluators0 = | ||
new BspEvaluators(topLevelProjectRoot, updatedEvaluators, s => debug(s())) | ||
bspEvaluators.success(bspEvaluators0) | ||
if (client != null) { | ||
val newTargetIds = bspEvaluators0.bspModulesIdList.map { | ||
case (id, (_, ev)) => | ||
id -> ev | ||
} | ||
val newTargetIdsMap = newTargetIds.toMap | ||
|
||
val previousTargetIds = previousEvaluatorsOpt.map(_.bspModulesIdList).getOrElse(Nil).map { | ||
case (id, (_, ev)) => | ||
id -> ev | ||
} | ||
|
||
val deleted0 = previousTargetIds.filterNot { | ||
case (id, _) => | ||
newTargetIdsMap.contains(id) | ||
} | ||
val previousTargetIdsMap = previousTargetIds.toMap | ||
val (modified0, created0) = newTargetIds.partition { | ||
case (id, _) => | ||
previousTargetIdsMap.contains(id) | ||
} | ||
|
||
val deletedEvents = deleted0.map { | ||
case (id, _) => | ||
val event = new bsp4j.BuildTargetEvent(id) | ||
event.setKind(bsp4j.BuildTargetEventKind.DELETED) | ||
event | ||
} | ||
val createdEvents = created0.map { | ||
case (id, _) => | ||
val event = new bsp4j.BuildTargetEvent(id) | ||
event.setKind(bsp4j.BuildTargetEventKind.CREATED) | ||
event | ||
} | ||
val modifiedEvents = modified0 | ||
.filter { | ||
case (id, ev) => | ||
!previousTargetIdsMap.get(id).contains(ev) | ||
} | ||
.map { | ||
case (id, ev) => | ||
val event = new bsp4j.BuildTargetEvent(id) | ||
event.setKind(bsp4j.BuildTargetEventKind.CHANGED) | ||
event | ||
} | ||
|
||
val allEvents = deletedEvents ++ createdEvents ++ modifiedEvents | ||
|
||
if (allEvents.nonEmpty) | ||
client.onBuildTargetDidChange(new bsp4j.DidChangeBuildTarget(allEvents.asJava)) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -81,7 +158,7 @@ private class MillBuildServer( | |
val supportedLangs = Constants.languages.asJava | ||
val capabilities = new BuildServerCapabilities | ||
|
||
capabilities.setBuildTargetChangedProvider(false) | ||
capabilities.setBuildTargetChangedProvider(true) | ||
capabilities.setCanReload(canReload) | ||
capabilities.setCompileProvider(new CompileProvider(supportedLangs)) | ||
capabilities.setDebugProvider(new DebugProvider(Seq().asJava)) | ||
|
@@ -139,7 +216,7 @@ private class MillBuildServer( | |
override def onBuildExit(): Unit = { | ||
print("Entered onBuildExit") | ||
SemanticDbJavaModuleApi.resetContext() | ||
sessionResult = Some(BspServerResult.Shutdown) | ||
sessionResult.trySuccess(BspServerResult.Shutdown) | ||
onShutdown() | ||
} | ||
|
||
|
@@ -192,7 +269,7 @@ private class MillBuildServer( | |
handlerRaw(checkInitialized = false) { | ||
// Instead stop and restart the command | ||
// BSP.install(evaluator) | ||
sessionResult = Some(BspServerResult.ReloadWorkspace) | ||
sessionResult.trySuccess(BspServerResult.ReloadWorkspace) | ||
().asInstanceOf[Object] | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
integration/ide/bsp-server-reload/resources/project/app/src/milltests/TheApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package milltests | ||
|
||
object TheApp { | ||
def main(args: Array[String]): Unit = | ||
println(Lib.message) | ||
} |
25 changes: 25 additions & 0 deletions
25
integration/ide/bsp-server-reload/resources/project/build.mill.base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package build | ||
|
||
import mill.scalalib._ | ||
|
||
object thing extends ScalaModule { | ||
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???) | ||
def mvnDeps = Seq( | ||
mvn"com.lihaoyi::pprint:0.9.0" | ||
) | ||
} | ||
|
||
object lib extends ScalaModule { | ||
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???) | ||
def mvnDeps = Seq( | ||
mvn"org.slf4j:slf4j-api:2.0.16" | ||
) | ||
} | ||
|
||
object app extends ScalaModule { | ||
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???) | ||
def moduleDeps = Seq(lib) | ||
def mvnDeps = Seq( | ||
mvn"ch.qos.logback:logback-core:1.5.15" | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
integration/ide/bsp-server-reload/resources/project/build.mill.broken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package build | ||
|
||
import mill.scalalib._ | ||
|
||
object thing extends ScalaModule { | ||
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???) | ||
def mvnDeps = Seq( | ||
mvn"com.lihaoyi::pprint:0.9.0" | ||
) | ||
} | ||
|
||
object lib extends ScalaModule { | ||
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???) | ||
def mvnDeps = Seq( | ||
mvnz"org.slf4j:slf4j-api:2.0.16" | ||
) | ||
} | ||
|
||
object app extends ScalaModule { | ||
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???) | ||
def moduleDeps = Seq(lib) | ||
def mvnDeps = Seq( | ||
mvn"ch.qos.logback:logback-core:1.5.15" | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
uninitialized
not enough? Can we use a better type then, e.g.Option
?