Skip to content

Commit

Permalink
report sbt's build progress
Browse files Browse the repository at this point in the history
build progress from sbt BSP is now reported. Its notification has a
"compile-progress" datakind field, which is formatted the same as
"bloop-progress" except for one thing, the "current" field is actually
the percentage, so we use 100 for the total.
  • Loading branch information
bishabosha authored and tgodzik committed Oct 26, 2023
1 parent 5c5cab7 commit b7ebc29
Showing 1 changed file with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,37 @@ final class ForwardingMetalsBuildClient(

@JsonNotification("build/taskProgress")
def buildTaskProgress(params: TaskProgressParams): Unit = {
def buildTargetFromParams: Option[BuildTargetIdentifier] =
for {
data <- Option(params.getData).collect { case o: JsonObject =>
o
}
targetElement <- Option(data.get("target"))
if targetElement.isJsonObject
target = targetElement.getAsJsonObject
uriElement <- Option(target.get("uri"))
if uriElement.isJsonPrimitive
uri = uriElement.getAsJsonPrimitive
if uri.isString
} yield new BuildTargetIdentifier(uri.getAsString)

params.getDataKind match {
case "bloop-progress" =>
for {
data <- Option(params.getData).collect { case o: JsonObject =>
o
}
targetElement <- Option(data.get("target"))
if targetElement.isJsonObject
target = targetElement.getAsJsonObject
uriElement <- Option(target.get("uri"))
if uriElement.isJsonPrimitive
uri = uriElement.getAsJsonPrimitive
if uri.isString
buildTarget = new BuildTargetIdentifier(uri.getAsString)
buildTarget <- buildTargetFromParams
report <- compilations.get(buildTarget)
} yield {
report.progress.update(params.getProgress, params.getTotal)
}
case "compile-progress" =>
// "compile-progress" is from sbt, however its progress field is actually a percentage,
// so we should fix the total to 100.
for {
buildTarget <- buildTargetFromParams
report <- compilations.get(buildTarget)
} yield {
report.progress.update(params.getProgress, newTotal = 100)
}
case _ =>
}
}
Expand Down

0 comments on commit b7ebc29

Please sign in to comment.