Skip to content

Commit

Permalink
Bump zinc and account for diagnostic code
Browse files Browse the repository at this point in the history
At the moment this is just testing a bit. I see you already have a test
PR to bump zinc in #1845 but one
of the things that this brings in is the changes to `Problem` I made in
sbt/sbt#6874 that expose the diagnostic code of
the diagnostic coming from dotc. I have been doing some work on that on
the compiler side in scala/scala3#15565 and
wanted to try it out with Mill.

I tried to mimic the way you currently have it set up, so let me know if
it's not the direction you'd want to go. However, the idea here would be
that the diagnostic code is forwarded when diagnostics are published via
BSP so that Metals could then capture that code and know what code
actions to offer. You can see more of the big picture in scala/scala3#14904.
  • Loading branch information
ckipp01 committed Oct 8, 2022
1 parent 45e3871 commit 08e9b7f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bsp/src/mill/bsp/BspCompileProblemReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class BspCompileProblemReporter(
pos.endColumn.orElse(pos.pointer).getOrElse[Int](start.getCharacter.intValue())
)
val diagnostic = new bsp.Diagnostic(new bsp.Range(start, end), problem.message)
diagnostic.setCode(pos.lineContent)
diagnostic.setSource("mill")
diagnostic.setSeverity(
problem.severity match {
Expand All @@ -139,6 +138,7 @@ class BspCompileProblemReporter(
case mill.api.Warn => bsp.DiagnosticSeverity.WARNING
}
)
problem.diagnosticCode.foreach { existingCode => diagnostic.setCode(existingCode.code) }
diagnostic
}

Expand Down
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ object Deps {
val upickle = ivy"com.lihaoyi::upickle:2.0.0"
val utest = ivy"com.lihaoyi::utest:0.7.11"
val windowsAnsi = ivy"io.github.alexarchambault.windows-ansi:windows-ansi:0.0.4"
val zinc = ivy"org.scala-sbt::zinc:1.7.1"
val zinc = ivy"org.scala-sbt::zinc:1.7.2"
val bsp = ivy"ch.epfl.scala:bsp4j:2.1.0-M1"
val fansi = ivy"com.lihaoyi::fansi:0.4.0"
val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.8.1"
Expand Down
12 changes: 12 additions & 0 deletions main/api/src/mill/api/CompileProblemReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ trait Problem {
def message: String

def position: ProblemPosition

// TODO Remove default implementation in 0.11.x series
def diagnosticCode: Option[DiagnosticCode] = None
}

/**
* Unique diagnostic code given from the compiler with an optional further explanation.
*/
trait DiagnosticCode {
def code: String

def explanation: Option[String]
}

/**
Expand Down
12 changes: 12 additions & 0 deletions scalalib/worker/src/mill/scalalib/worker/ZincDiagnosticCode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package mill.scalalib.worker

import mill.api.internal
import mill.api.DiagnosticCode

import scala.jdk.OptionConverters._

@internal
final case class ZincDiagnosticCode(base: xsbti.DiagnosticCode) extends DiagnosticCode {
override def code: String = base.code()
override def explanation: Option[String] = base.explanation().toScala
}
5 changes: 5 additions & 0 deletions scalalib/worker/src/mill/scalalib/worker/ZincProblem.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mill.scalalib.worker

import mill.api.{Problem, ProblemPosition, Severity, internal}
import mill.api.DiagnosticCode
import scala.jdk.OptionConverters._

@internal
class ZincProblem(base: xsbti.Problem) extends Problem {
Expand All @@ -15,4 +17,7 @@ class ZincProblem(base: xsbti.Problem) extends Problem {
override def message: String = base.message()

override def position: ProblemPosition = new ZincProblemPosition(base.position())

override def diagnosticCode: Option[DiagnosticCode] =
base.diagnosticCode().toScala.map(ZincDiagnosticCode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ class ZincWorkerImpl(
val newReporter = reporter match {
case None => new ManagedLoggedReporter(10, logger)
case Some(r) => new ManagedLoggedReporter(10, logger) {

override def logError(problem: xsbti.Problem): Unit = {
r.logError(new ZincProblem(problem))
super.logError(problem)
Expand Down

0 comments on commit 08e9b7f

Please sign in to comment.