diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 721a08b5d..6246970f4 100644 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -12,7 +12,6 @@ import java.net.{ URI, URL } import java.nio.file.{ Paths, Path => NioPath } import java.util.Optional import java.util.concurrent.TimeUnit - import lmcoursier.CoursierDependencyResolution import lmcoursier.definitions.{ Configuration => CConfiguration } import org.apache.ivy.core.module.descriptor.ModuleDescriptor @@ -47,6 +46,7 @@ import sbt.internal.librarymanagement.mavenint.{ import sbt.internal.librarymanagement.{ CustomHttp => _, _ } import sbt.internal.nio.{ CheckBuildSources, Globs } import sbt.internal.server.{ + BspCompileProgress, BspCompileTask, BuildServerProtocol, BuildServerReporter, @@ -2353,39 +2353,16 @@ object Defaults extends BuildCommon { ) } def onProgress(s: Setup) = { - val p = s.progress.asScala - s.withProgress { - p.collect { - case c: CompileProgress => - new CompileProgress { - override def startUnit(phase: String, unitPath: String): Unit = - c.startUnit(phase, unitPath) - - override def afterEarlyOutput(success: Boolean): Unit = - c.afterEarlyOutput(success) - - override def advance( - current: Int, - total: Int, - prevPhase: String, - nextPhase: String - ): Boolean = { - val percentage = current * 100 / total - // Report percentages every 5% increments - val shouldReportPercentage = percentage % 5 == 0 - if (shouldReportPercentage) { - task.notifyProgress(percentage, total) - } - - c.advance(current, total, prevPhase, nextPhase) - } - } - }.asJava - } + val cp: BspCompileProgress = s.progress.asScala + .map(p => new BspCompileProgress(task, Some(p))) + .getOrElse(new BspCompileProgress(task, None)) + s.withProgress(cp) } val compilers: Compilers = ci.compilers val setup: Setup = ci.setup - val i = ci.withCompilers(onArgs(compilers)).withSetup(onProgress(setup)) + val i = ci + .withCompilers(onArgs(compilers)) + .withSetup(onProgress(setup)) try { val result = incCompiler.compile(i, s.log) reporter.sendSuccessReport(result.getAnalysis) diff --git a/main/src/main/scala/sbt/internal/server/BspCompileProgress.scala b/main/src/main/scala/sbt/internal/server/BspCompileProgress.scala new file mode 100644 index 000000000..7b882e2a1 --- /dev/null +++ b/main/src/main/scala/sbt/internal/server/BspCompileProgress.scala @@ -0,0 +1,24 @@ +package sbt.internal.server + +import xsbti.compile.CompileProgress + +private[sbt] final class BspCompileProgress( + task: BspCompileTask, + underlying: Option[CompileProgress] +) extends CompileProgress { + override def advance( + current: Int, + total: Int, + prevPhase: String, + nextPhase: String + ): Boolean = { + val percentage = current * 100 / total + // Report percentages every 5% increments + val shouldReportPercentage = percentage % 5 == 0 + if (shouldReportPercentage) { + task.notifyProgress(percentage, total) + } + underlying.foreach(_.advance(current, total, prevPhase, nextPhase)) + true + } +} diff --git a/main/src/main/scala/sbt/internal/server/BspCompileTask.scala b/main/src/main/scala/sbt/internal/server/BspCompileTask.scala index 4e53263ee..57abb770a 100644 --- a/main/src/main/scala/sbt/internal/server/BspCompileTask.scala +++ b/main/src/main/scala/sbt/internal/server/BspCompileTask.scala @@ -26,7 +26,7 @@ object BspCompileTask { ): CompileResult = { val task = BspCompileTask(targetId, project, config) try { - task.notifyStart + task.notifyStart() val result = Retry(compile(task)) task.notifySuccess(result) result