Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package demo
import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.{Global, Phase}
import scala.tools.nsc.plugins.{Plugin, PluginComponent}
class DemoPlugin(val global: Global) extends Plugin {
import global._
override def init(options: List[String], error: String => Unit): Boolean = true
val name = "demo"
val description = "a plugin"
val components = List[PluginComponent](DemoComponent)
private object DemoComponent extends PluginComponent {
val global = DemoPlugin.this.global
import global._
override val runsAfter = List("parser")
override val runsBefore = List("namer")
val phaseName = "Demo"
override def newPhase(prev: Phase) = new GlobalPhase(prev) {
override def run() = {
val count = global.currentRun.units.length
val x: Iterator[Seq[String]] = global.currentRun.units.map(_.source.file.path.split("/"))
var start = x.next()
for(next <- x){
for(i <- next.indices){
if (i < start.length && start.lift(i) != next.lift(i)){
start = start.take(i)
}
}
}
val cwd = new java.io.File("").getAbsolutePath.split("/")
if (start.startsWith(cwd)) start = start.drop(cwd.length)
val msg = s"Compiling $count files in ${start.mkString("/")}"
val spaces = " " * ((90 - msg.length) / 2)
global.reporter.echo(
scala.Console.BLUE_B +
spaces + msg + spaces +
scala.Console.RESET
)
}
def name: String = phaseName
def apply(unit: global.CompilationUnit): Unit = {}
}
}
}

@lihaoyi How can this be added to sbt? I tried to put it in ~/.sbt/0.13/plugins/Plugin.scala but then sbt fails to start with:

[error] ...\.sbt\0.13\plugins\CompilationBar.scala:9: method init overrides nothing
[error]   override def init(options: List[String],  error: String => Unit): Boolean = true

Removing override doesn't seem to help ;)

I tried it on a project built with sbt 0.13.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment