Skip to content

Commit 08e9b7f

Browse files
committed
Bump zinc and account for diagnostic code
At the moment this is just testing a bit. I see you already have a test PR to bump zinc in com-lihaoyi#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.
1 parent 45e3871 commit 08e9b7f

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

bsp/src/mill/bsp/BspCompileProblemReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class BspCompileProblemReporter(
130130
pos.endColumn.orElse(pos.pointer).getOrElse[Int](start.getCharacter.intValue())
131131
)
132132
val diagnostic = new bsp.Diagnostic(new bsp.Range(start, end), problem.message)
133-
diagnostic.setCode(pos.lineContent)
134133
diagnostic.setSource("mill")
135134
diagnostic.setSeverity(
136135
problem.severity match {
@@ -139,6 +138,7 @@ class BspCompileProblemReporter(
139138
case mill.api.Warn => bsp.DiagnosticSeverity.WARNING
140139
}
141140
)
141+
problem.diagnosticCode.foreach { existingCode => diagnostic.setCode(existingCode.code) }
142142
diagnostic
143143
}
144144

build.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ object Deps {
145145
val upickle = ivy"com.lihaoyi::upickle:2.0.0"
146146
val utest = ivy"com.lihaoyi::utest:0.7.11"
147147
val windowsAnsi = ivy"io.github.alexarchambault.windows-ansi:windows-ansi:0.0.4"
148-
val zinc = ivy"org.scala-sbt::zinc:1.7.1"
148+
val zinc = ivy"org.scala-sbt::zinc:1.7.2"
149149
val bsp = ivy"ch.epfl.scala:bsp4j:2.1.0-M1"
150150
val fansi = ivy"com.lihaoyi::fansi:0.4.0"
151151
val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.8.1"

main/api/src/mill/api/CompileProblemReporter.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ trait Problem {
3030
def message: String
3131

3232
def position: ProblemPosition
33+
34+
// TODO Remove default implementation in 0.11.x series
35+
def diagnosticCode: Option[DiagnosticCode] = None
36+
}
37+
38+
/**
39+
* Unique diagnostic code given from the compiler with an optional further explanation.
40+
*/
41+
trait DiagnosticCode {
42+
def code: String
43+
44+
def explanation: Option[String]
3345
}
3446

3547
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package mill.scalalib.worker
2+
3+
import mill.api.internal
4+
import mill.api.DiagnosticCode
5+
6+
import scala.jdk.OptionConverters._
7+
8+
@internal
9+
final case class ZincDiagnosticCode(base: xsbti.DiagnosticCode) extends DiagnosticCode {
10+
override def code: String = base.code()
11+
override def explanation: Option[String] = base.explanation().toScala
12+
}

scalalib/worker/src/mill/scalalib/worker/ZincProblem.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package mill.scalalib.worker
22

33
import mill.api.{Problem, ProblemPosition, Severity, internal}
4+
import mill.api.DiagnosticCode
5+
import scala.jdk.OptionConverters._
46

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

1719
override def position: ProblemPosition = new ZincProblemPosition(base.position())
20+
21+
override def diagnosticCode: Option[DiagnosticCode] =
22+
base.diagnosticCode().toScala.map(ZincDiagnosticCode)
1823
}

scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ class ZincWorkerImpl(
455455
val newReporter = reporter match {
456456
case None => new ManagedLoggedReporter(10, logger)
457457
case Some(r) => new ManagedLoggedReporter(10, logger) {
458+
458459
override def logError(problem: xsbti.Problem): Unit = {
459460
r.logError(new ZincProblem(problem))
460461
super.logError(problem)

0 commit comments

Comments
 (0)