Skip to content
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

[BSP] Report compilation's completion percentage #4064

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions main/api/src/mill/api/CompileProblemReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ trait CompileProblemReporter {
def fileVisited(file: os.Path): Unit
def printSummary(): Unit
def finish(): Unit
// TODO: cleanup once we break bin-compat in Mill 0.13
// Remove default implementation: `= ()`
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
Loading