Skip to content

Commit cbff210

Browse files
committed
Properly report problems to sbt
Dotty has its own logic for displaying problems with the proper file path, position, and caret, but if we store this information in Problem#message we end up with duplicated information in the output since Zinc will prepend/append similar things (see sbt.internal.inc.ProblemStringFormats). So far, we worked around this in Dotty by using an empty position in the sbt bridge reporter, but this means that crucial semantic information that could be used by a Build Server Protocol implementation and other tools is lost. Thanks to sbt/zinc#588 we can now fully customize how the message is displayed to the user using Problem#rendered, so we can now store the position information without any adverse effect.
1 parent e7d172c commit cbff210

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

sbt-bridge/src/xsbt/DelegatingReporter.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter
2929
}
3030

3131
val position =
32-
if (false && cont.pos.exists) { // Disabled because it duplicates the information printed by Dotty
32+
if (cont.pos.exists) {
3333
val pos = cont.pos
3434
val src = pos.source
3535
new Position {
@@ -46,13 +46,14 @@ final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter
4646
} else
4747
noPosition
4848

49-
val sb = new StringBuilder()
50-
sb.append(messageAndPos(cont.contained(), cont.pos, diagnosticLevel(cont)))
51-
if (ctx.shouldExplain(cont) && cont.contained().explanation.nonEmpty) {
52-
sb.append(explanation(cont.contained()))
49+
val message = cont.contained()
50+
val rendered = new StringBuilder()
51+
rendered.append(messageAndPos(message, cont.pos, diagnosticLevel(cont)))
52+
if (ctx.shouldExplain(cont) && message.explanation.nonEmpty) {
53+
rendered.append(explanation(message))
5354
}
5455

55-
delegate.log(Problem(position, sb.toString(), severity))
56+
delegate.log(Problem(position, message.msg, severity, rendered.toString))
5657
}
5758

5859
private[this] def maybe[T](opt: Option[T]): Optional[T] = opt match {

sbt-bridge/src/xsbt/Problem.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package xsbt
22

3+
import java.util.Optional
34
import xsbti.{Position, Severity}
45

56
final case class Problem(override val position: Position,
67
override val message: String,
7-
override val severity: Severity) extends xsbti.Problem {
8+
override val severity: Severity,
9+
rendered0: String) extends xsbti.Problem {
810
override val category = ""
9-
override def toString = s"[$severity] $position: $message"
10-
11+
override val rendered = Optional.of(rendered0)
1112
}
12-

0 commit comments

Comments
 (0)