Reputation: 2010
Sometimes when doing certain kinds of refactorings, the compiler may generate hundreds of errors. I like to start resolving these errors from the top, but the sheer number of errors can make it quite cumbersome to scroll all the way back up.
Is it possible to make the Scala compiler limit the number of errors it shows so that it becomes easier to start fixing them from the top? At the expense of possibly having to run the compiler multiple times, obviously.
Upvotes: 3
Views: 138
Reputation: 39587
Yes, since 2.12 it's possible to use a custom reporter.
Here is an example reporter:
package myrep
import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.ConsoleReporter
import scala.reflect.internal.util._
class MyReporter(ss: Settings) extends ConsoleReporter(ss) {
var deprecationCount = 0
override def warning(pos: Position, msg: String): Unit = {
if (msg contains "is deprecated") deprecationCount += 1
super.warning(pos, msg)
}
override def hasWarnings: Boolean = count(WARNING) - deprecationCount > 0
override def reset() = { deprecationCount = 0 ; super.reset() }
// limit total
var limit = 5
override def display(pos: Position, msg: String, severity: Severity): Unit =
if (severity != ERROR || severity.count <= limit) print(pos, msg, severity)
}
Your reporter class has to be on the tool class path:
$ ~/scala-2.12.0-M3/bin/scalac -toolcp . -Xreporter myrep.MyReporter test.scala
You might choose to configure the limit somehow, perhaps with a system property, but configuration is not built-in.
For this sample file, there are six errors but five are reported:
package tester
@deprecated("Don't use me", since="2.12.0")
class C
object Test extends App {
Console println s"${new C}"
val x: String = 42
val y: Int = "42"
val z: Int = 2.0
Console println (42 drop 1)
Console println (42 take 1)
Console println (42 shift 1)
}
Upvotes: 3