From 086e86e3e0f2940017f0f65db913d2245c56d77e Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Thu, 26 Oct 2023 11:34:01 +0200 Subject: [PATCH] report sbt's build progress 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. --- .../metals/ForwardingMetalsBuildClient.scala | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala b/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala index 9a8c29178f8..59a9da7cf27 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ForwardingMetalsBuildClient.scala @@ -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 _ => } }