Skip to content

Commit

Permalink
[BSP] Report compilation's completion percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Dec 2, 2024
1 parent 70de321 commit d5bd957
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions bsp/worker/src/mill/bsp/worker/BspCompileProblemReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ private class BspCompileProblemReporter(
client.onBuildTaskStart(taskStartParams)
}

override def notifyProgress(percentage: Long, total: Long): Unit = {
val params = new TaskProgressParams(taskId).tap { it =>
it.setEventTime(System.currentTimeMillis())
it.setData(new CompileTask(targetId))
it.setDataKind("compile-progress")
it.setMessage(s"Compiling target ${targetDisplayName} ($percentage%)")
it.setProgress(percentage)
it.setTotal(total)
}
client.onBuildTaskProgress(params)
}

override def finish(): Unit = {
val taskFinishParams =
new TaskFinishParams(taskId, if (errors > 0) StatusCode.ERROR else StatusCode.OK).tap { it =>
Expand Down
1 change: 1 addition & 0 deletions main/api/src/mill/api/CompileProblemReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ trait CompileProblemReporter {
def fileVisited(file: os.Path): Unit
def printSummary(): Unit
def finish(): Unit
def notifyProgress(percentage: Long, total: Long): Unit
}

/**
Expand Down
17 changes: 16 additions & 1 deletion scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import xsbti.compile.{
PreviousResult
}
import xsbti.{PathBasedFile, VirtualFile}
import xsbti.compile.CompileProgress

import java.io.File
import java.net.URLClassLoader
Expand Down Expand Up @@ -589,6 +590,20 @@ class ZincWorkerImpl(
val incOptions = IncOptions.of().withAuxiliaryClassFiles(
auxiliaryClassFileExtensions.map(new AuxiliaryClassFileExtension(_)).toArray
)
val compileProgress = reporter.map { reporter =>
new CompileProgress {
override def advance(
current: Int,
total: Int,
prevPhase: String,
nextPhase: String
): Boolean = {
val percentage = current * 100 / total
reporter.notifyProgress(percentage = percentage, total = total)
true
}
}
}

val inputs = ic.inputs(
classpath = classpath,
Expand All @@ -608,7 +623,7 @@ class ZincWorkerImpl(
cache = new FreshCompilerCache,
incOptions = incOptions,
reporter = newReporter,
progress = None,
progress = compileProgress,
earlyAnalysisStore = None,
extra = Array()
),
Expand Down

0 comments on commit d5bd957

Please sign in to comment.