Skip to content

Commit

Permalink
fix: also include diagnosticCode and related info in InterfaceUtil
Browse files Browse the repository at this point in the history
Looks like I missed this in sbt#6874 and I
hit on it in Mill when I couldn't figure out why it was also empty, and
thanks to @adpi realized it was because of the `LoggedReporter` in zinc
not taking it into account. However before I can bump that this needs to
be bumped as well.

refs: scala/scala3#14904
  • Loading branch information
ckipp01 authored and eed3si9n committed Oct 2, 2022
1 parent 87bbdd9 commit dadfee5
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions internal/util-logging/src/main/scala/sbt/util/InterfaceUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

package sbt.util

import xsbti.{ Position, Problem, Severity, T2 }
import java.io.File
import java.util.Optional
import java.util.function.Supplier
import java.{ util => ju }

import xsbti.{ DiagnosticCode, DiagnosticRelatedInformation, Position, Problem, Severity, T2 }

import scala.collection.mutable.ListBuffer

object InterfaceUtil {
def toSupplier[A](a: => A): Supplier[A] = new Supplier[A] {
Expand Down Expand Up @@ -43,6 +47,18 @@ object InterfaceUtil {
case None => Optional.empty[A]()
}

def l2jl[A](l: List[A]): ju.List[A] = {
val jl = new ju.ArrayList[A](l.size)
l.foreach(jl.add(_))
jl
}

def jl2l[A](jl: ju.List[A]): List[A] = {
val l = ListBuffer[A]()
jl.forEach(l += _)
l.toList
}

@deprecated("Use the overload of this method with more arguments", "1.2.2")
def position(
line0: Option[Integer],
Expand Down Expand Up @@ -104,14 +120,26 @@ object InterfaceUtil {
def problem(cat: String, pos: Position, msg: String, sev: Severity): Problem =
problem(cat, pos, msg, sev, None)

@deprecated("Use the overload of this method with more arguments", "1.7.2")
def problem(
cat: String,
pos: Position,
msg: String,
sev: Severity,
rendered: Option[String]
): Problem =
new ConcreteProblem(cat, pos, msg, sev, rendered)
problem(cat, pos, msg, sev, rendered, None, List.empty[DiagnosticRelatedInformation])

def problem(
cat: String,
pos: Position,
msg: String,
sev: Severity,
rendered: Option[String],
diagnosticCode: Option[DiagnosticCode],
diagnosticRelatedInforamation: List[DiagnosticRelatedInformation]
): Problem =
new ConcreteProblem(cat, pos, msg, sev, rendered, diagnosticCode, diagnosticRelatedInforamation)

private final class ConcreteT2[A1, A2](a1: A1, a2: A2) extends T2[A1, A2] {
val get1: A1 = a1
Expand Down Expand Up @@ -166,13 +194,18 @@ object InterfaceUtil {
pos: Position,
msg: String,
sev: Severity,
rendered0: Option[String]
rendered0: Option[String],
diagnosticCode0: Option[DiagnosticCode],
diagnosticRelatedInformation0: List[DiagnosticRelatedInformation]
) extends Problem {
val category = cat
val position = pos
val message = msg
val severity = sev
override val rendered = o2jo(rendered0)
override def diagnosticCode: Optional[DiagnosticCode] = o2jo(diagnosticCode0)
override def diagnosticRelatedInforamation(): ju.List[DiagnosticRelatedInformation] =
l2jl(diagnosticRelatedInformation0)
override def toString = s"[$severity] $pos: $message"
}
}

0 comments on commit dadfee5

Please sign in to comment.