summaryrefslogtreecommitdiff
path: root/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala')
-rw-r--r--contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala104
1 files changed, 53 insertions, 51 deletions
diff --git a/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala b/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala
index b4f0260d..3e65b648 100644
--- a/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala
+++ b/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala
@@ -6,7 +6,7 @@ import java.util.concurrent.atomic.AtomicInteger
import ch.epfl.scala.bsp4j._
import ch.epfl.scala.{bsp4j => bsp}
-import mill.api.{Info, Problem, Warn, BuildProblemReporter}
+import mill.api.{BuildProblemReporter, Problem}
import scala.collection.JavaConverters._
import scala.collection.concurrent
@@ -17,11 +17,11 @@ import scala.language.implicitConversions
* for each problem it logs, either as information, warning or
* error as well as task finish notifications of type `compile-report`.
*
- * @param client the client to send diagnostics to
- * @param targetId the target id of the target whose compilation
- * the diagnostics are related to
- * @param taskId a unique id of the compilation task of the target
- * specified by `targetId`
+ * @param client the client to send diagnostics to
+ * @param targetId the target id of the target whose compilation
+ * the diagnostics are related to
+ * @param taskId a unique id of the compilation task of the target
+ * specified by `targetId`
* @param compilationOriginId optional origin id the client assigned to
* the compilation request. Needs to be sent
* back as part of the published diagnostics
@@ -48,25 +48,6 @@ class BspLoggedReporter(client: bsp.BuildClient,
infos.incrementAndGet()
}
- override def logWarning(problem: Problem): Unit = {
- client.onBuildPublishDiagnostics(getDiagnostics(problem, targetId, compilationOriginId))
- warnings.incrementAndGet()
- }
-
- override def printSummary(): Unit = {
- val taskFinishParams = new TaskFinishParams(taskId, getStatusCode)
- taskFinishParams.setEventTime(System.currentTimeMillis())
- taskFinishParams.setMessage("Finished compiling target: " + targetId.getUri)
- taskFinishParams.setDataKind("compile-report")
- val compileReport = new CompileReport(targetId, errors.get, warnings.get)
- compilationOriginId match {
- case Some(id) => compileReport.setOriginId(id)
- case None =>
- }
- taskFinishParams.setData(compileReport)
- client.onBuildTaskFinish(taskFinishParams)
- }
-
// Obtains the parameters for sending diagnostics about the given Problem ( as well as
// about all previous problems generated for the same text file ) related to the specified
// targetId, incorporating the given optional originId ( generated by the client for the
@@ -74,27 +55,24 @@ class BspLoggedReporter(client: bsp.BuildClient,
//TODO: document that if the problem is a general information without a text document
// associated to it, then the document field of the diagnostic is set to the uri of the target
private[this] def getDiagnostics(problem: Problem, targetId: bsp.BuildTargetIdentifier, originId: Option[String]):
- bsp.PublishDiagnosticsParams = {
- val diagnostic = getSingleDiagnostic(problem)
- val sourceFile = problem.position.sourceFile
- val textDocument = new TextDocumentIdentifier(
- sourceFile.getOrElse(None) match {
+ bsp.PublishDiagnosticsParams = {
+ val diagnostic = getSingleDiagnostic(problem)
+ val sourceFile = problem.position.sourceFile
+ val textDocument = new TextDocumentIdentifier(
+ sourceFile.getOrElse(None) match {
case None => targetId.getUri
case f: File => f.toURI.toString
})
- val params = new bsp.PublishDiagnosticsParams(textDocument,
- targetId,
- appendDiagnostics(textDocument, diagnostic).asJava,
- true)
+ val params = new bsp.PublishDiagnosticsParams(textDocument,
+ targetId,
+ appendDiagnostics(textDocument, diagnostic).asJava,
+ true)
- if (originId.nonEmpty) { params.setOriginId(originId.get) }
- diagnosticMap.put(textDocument, params)
- params
+ if (originId.nonEmpty) {
+ params.setOriginId(originId.get)
}
-
- // Compute the compilation status code
- private[this] def getStatusCode: StatusCode = {
- if (errors.get > 0) StatusCode.ERROR else StatusCode.OK
+ diagnosticMap.put(textDocument, params)
+ params
}
// Update the published diagnostics for the fiven text file by
@@ -103,14 +81,14 @@ class BspLoggedReporter(client: bsp.BuildClient,
private[this] def appendDiagnostics(textDocument: TextDocumentIdentifier,
currentDiagnostic: Diagnostic): List[Diagnostic] = {
diagnosticMap.putIfAbsent(textDocument, new bsp.PublishDiagnosticsParams(
- textDocument,
- targetId,
- List.empty[Diagnostic].asJava, true))
+ textDocument,
+ targetId,
+ List.empty[Diagnostic].asJava, true))
diagnosticMap(textDocument).getDiagnostics.asScala.toList ++ List(currentDiagnostic)
}
// Computes the diagnostic related to the given Problem
- private[this] def getSingleDiagnostic(problem: Problem): Diagnostic ={
+ private[this] def getSingleDiagnostic(problem: Problem): Diagnostic = {
val pos = problem.position
val i: Integer = pos.startLine.orElse(pos.line).getOrElse[Int](0)
println(i)
@@ -123,12 +101,36 @@ class BspLoggedReporter(client: bsp.BuildClient,
val diagnostic = new bsp.Diagnostic(new bsp.Range(start, end), problem.message)
diagnostic.setCode(pos.lineContent)
diagnostic.setSource("compiler from mill")
- diagnostic.setSeverity( problem.severity match {
- case mill.api.Info => bsp.DiagnosticSeverity.INFORMATION
- case mill.api.Error => bsp.DiagnosticSeverity.ERROR
- case mill.api.Warn => bsp.DiagnosticSeverity.WARNING
- }
- )
+ diagnostic.setSeverity(problem.severity match {
+ case mill.api.Info => bsp.DiagnosticSeverity.INFORMATION
+ case mill.api.Error => bsp.DiagnosticSeverity.ERROR
+ case mill.api.Warn => bsp.DiagnosticSeverity.WARNING
+ }
+ )
diagnostic
}
+
+ override def logWarning(problem: Problem): Unit = {
+ client.onBuildPublishDiagnostics(getDiagnostics(problem, targetId, compilationOriginId))
+ warnings.incrementAndGet()
+ }
+
+ override def printSummary(): Unit = {
+ val taskFinishParams = new TaskFinishParams(taskId, getStatusCode)
+ taskFinishParams.setEventTime(System.currentTimeMillis())
+ taskFinishParams.setMessage("Finished compiling target: " + targetId.getUri)
+ taskFinishParams.setDataKind("compile-report")
+ val compileReport = new CompileReport(targetId, errors.get, warnings.get)
+ compilationOriginId match {
+ case Some(id) => compileReport.setOriginId(id)
+ case None =>
+ }
+ taskFinishParams.setData(compileReport)
+ client.onBuildTaskFinish(taskFinishParams)
+ }
+
+ // Compute the compilation status code
+ private[this] def getStatusCode: StatusCode = {
+ if (errors.get > 0) StatusCode.ERROR else StatusCode.OK
+ }
}