Skip to content

Commit 79f12cf

Browse files
Tweak compiling / compiled messages
1 parent f802926 commit 79f12cf

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

modules/build/src/main/scala/scala/build/BloopBuildClient.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ch.epfl.scala.bsp4j
55
import java.io.PrintStream
66

77
trait BloopBuildClient extends bsp4j.BuildClient {
8+
def setProjectParams(newParams: Seq[String]): Unit
89
def setGeneratedSources(newGeneratedSources: Seq[GeneratedSource]): Unit
910
def diagnostics: Option[Seq[(Either[String, os.Path], bsp4j.Diagnostic)]]
1011
def clear(): Unit

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ object Build {
124124

125125
val generatedSources = sources.generateSources(inputs0.generatedSrcRoot)
126126

127+
buildClient.setProjectParams(options0.projectParams)
127128
build(
128129
inputs0,
129130
sources,

modules/build/src/main/scala/scala/build/ConsoleBloopBuildClient.scala

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class ConsoleBloopBuildClient(
1616
var generatedSources: Seq[GeneratedSource] = Nil
1717
) extends BloopBuildClient {
1818

19+
private var projectParams = Seq.empty[String]
20+
21+
private def projectNameSuffix =
22+
if (projectParams.isEmpty) ""
23+
else " (" + projectParams.mkString(", ") + ")"
24+
25+
private def projectName = "project" + projectNameSuffix
26+
1927
private var printedStart = false
2028
private val gray = "\u001b[90m"
2129
private val reset = Console.RESET
@@ -25,6 +33,9 @@ class ConsoleBloopBuildClient(
2533
def setGeneratedSources(newGeneratedSources: Seq[GeneratedSource]) = {
2634
generatedSources = newGeneratedSources
2735
}
36+
def setProjectParams(newParams: Seq[String]): Unit = {
37+
projectParams = newParams
38+
}
2839
def diagnostics: Option[Seq[(Either[String, os.Path], bsp4j.Diagnostic)]] =
2940
if (keepDiagnostics) Some(diagnostics0.result())
3041
else None
@@ -115,7 +126,10 @@ class ConsoleBloopBuildClient(
115126
logger.debug("Received onBuildTaskStart from bloop: " + params)
116127
for (msg <- Option(params.getMessage) if !msg.contains(" no-op compilation")) {
117128
printedStart = true
118-
out.println(gray + msg + reset)
129+
val msg0 =
130+
if (params.getDataKind == "compile-task") s"Compiling $projectName"
131+
else msg
132+
out.println(gray + msg0 + reset)
119133
}
120134
}
121135

@@ -125,8 +139,18 @@ class ConsoleBloopBuildClient(
125139
override def onBuildTaskFinish(params: bsp4j.TaskFinishParams): Unit = {
126140
logger.debug("Received onBuildTaskFinish from bloop: " + params)
127141
if (printedStart)
128-
for (msg <- Option(params.getMessage))
129-
out.println(gray + msg + reset)
142+
for (msg <- Option(params.getMessage)) {
143+
val msg0 =
144+
if (params.getDataKind == "compile-report")
145+
params.getStatus match {
146+
case bsp4j.StatusCode.OK => s"Compiled $projectName"
147+
case bsp4j.StatusCode.ERROR => s"Error compiling $projectName"
148+
case bsp4j.StatusCode.CANCELLED => s"Compilation cancelled$projectNameSuffix"
149+
case _ => s"Compiled $projectName" // ???
150+
}
151+
else msg
152+
out.println(gray + msg0 + reset)
153+
}
130154
}
131155

132156
override def onConnectWithServer(server: bsp4j.BuildServer): Unit = {}

modules/build/src/main/scala/scala/build/bsp/BspClient.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class BspClient(
8686
}
8787
}
8888

89+
def setProjectParams(newParams: Seq[String]): Unit = {}
8990
def diagnostics: Option[Seq[(Either[String, os.Path], b.Diagnostic)]] = None
9091
def clear(): Unit = {}
9192
}

modules/build/src/main/scala/scala/build/bsp/BspImpl.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ object BspImpl {
274274
def underlying = actualLocalClient
275275
def clear() = underlying.clear()
276276
def diagnostics = underlying.diagnostics
277+
def setProjectParams(newParams: Seq[String]) =
278+
underlying.setProjectParams(newParams)
277279
def setGeneratedSources(newGeneratedSources: Seq[GeneratedSource]) =
278280
underlying.setGeneratedSources(newGeneratedSources)
279281
}

modules/build/src/main/scala/scala/build/options/BuildOptions.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ final case class BuildOptions(
3030
replOptions: ReplOptions = ReplOptions()
3131
) {
3232

33+
lazy val projectParams: Seq[String] = {
34+
val platform =
35+
if (scalaJsOptions.enable) "Scala.JS"
36+
else if (scalaNativeOptions.enable) "Scala Native"
37+
else "JVM"
38+
Seq(s"Scala ${scalaParams.scalaVersion}", platform)
39+
}
40+
3341
def addRunnerDependency: Option[Boolean] =
3442
internalDependencies.addRunnerDependencyOpt
3543
.orElse(if (scalaJsOptions.enable || scalaNativeOptions.enable) Some(false) else None)

0 commit comments

Comments
 (0)