Skip to content

Commit 0ec0e9e

Browse files
authored
Bump zinc and account for diagnostic code (#1912)
Newer zinc 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. Pull request: #1912
1 parent c985ef8 commit 0ec0e9e

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
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

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)