-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sbt bridge reporter #1530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sbt bridge reporter #1530
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* sbt -- Simple Build Tool | ||
* Copyright 2008, 2009 Mark Harrah | ||
*/ | ||
package xsbt | ||
|
||
import dotty.tools._ | ||
import dotc._ | ||
import reporting._ | ||
import core.Contexts._ | ||
|
||
import xsbti.{Maybe, Position} | ||
|
||
final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter | ||
with UniqueMessagePositions | ||
with HideNonSensicalMessages { | ||
|
||
override def printSummary(implicit ctx: Context): Unit = delegate.printSummary() | ||
|
||
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = { | ||
val severity = | ||
d match { | ||
case _: Reporter.Error => xsbti.Severity.Error | ||
case _: Reporter.Warning => xsbti.Severity.Warn | ||
case _ => xsbti.Severity.Info | ||
} | ||
val pos = | ||
if (d.pos.exists) Some(d.pos) | ||
else None | ||
|
||
val file = | ||
if (d.pos.source.file.exists) Option(d.pos.source.file.file) | ||
else None | ||
|
||
val offset0 = pos.map(_.point) | ||
|
||
val position = new Position { | ||
def line: Maybe[Integer] = maybe(pos.map(_.line)) | ||
def lineContent: String = pos.map(_.lineContent).getOrElse("") | ||
def offset: Maybe[Integer] = maybeInt(offset0) | ||
def pointer: Maybe[Integer] = offset | ||
def pointerSpace: Maybe[String] = maybe(offset0.map(" " * _)) | ||
def sourceFile: Maybe[java.io.File] = maybe(file) | ||
def sourcePath: Maybe[String] = maybe(file.map(_.getPath)) | ||
} | ||
|
||
delegate.log(position, d.message, severity) | ||
} | ||
|
||
private[this] def maybe[T](opt: Option[T]): Maybe[T] = opt match { | ||
case None => Maybe.nothing[T] | ||
case Some(s) => Maybe.just[T](s) | ||
} | ||
import java.lang.{ Integer => I } | ||
private[this] def maybeInt(opt: Option[Int]): Maybe[I] = opt match { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is unnecessary, just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the compiler fails to infer with only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scalac: trait Position {
def offset(): Integer
}
object A {
val p = new Position {
def offset(): Int = 1
}
} overriding method offset in trait Position of type ()Integer; |
||
case None => Maybe.nothing[I] | ||
case Some(s) => Maybe.just[I](s) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
trait A | ||
trait B | ||
|
||
trait Wr { | ||
val z: A with B | ||
} | ||
|
||
object Er { | ||
val a = er1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reporter.checkSettings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import sbt._ | ||
import Keys._ | ||
|
||
object DottyInjectedPlugin extends AutoPlugin { | ||
override def requires = plugins.JvmPlugin | ||
override def trigger = allRequirements | ||
|
||
override val projectSettings = Seq( | ||
scalaVersion := "0.1-SNAPSHOT", | ||
scalaOrganization := "ch.epfl.lamp", | ||
scalacOptions += "-language:Scala2", | ||
scalaBinaryVersion := "2.11", | ||
autoScalaLibrary := false, | ||
libraryDependencies ++= Seq("org.scala-lang" % "scala-library" % "2.11.5"), | ||
scalaCompilerBridgeSource := ("ch.epfl.lamp" % "dotty-bridge" % "0.1.1-SNAPSHOT" % "component").sources() | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import sbt._ | ||
import Keys._ | ||
import KeyRanks.DTask | ||
|
||
object Reporter { | ||
import xsbti.{Reporter, Problem, Position, Severity, Maybe} | ||
|
||
lazy val check = TaskKey[Unit]("check", "make sure compilation info are forwared to sbt") | ||
|
||
// compilerReporter is marked private in sbt | ||
lazy val compilerReporter = TaskKey[Option[xsbti.Reporter]]("compilerReporter", "Experimental hook to listen (or send) compilation failure messages.", DTask) | ||
|
||
lazy val reporter = | ||
Some(new xsbti.Reporter { | ||
private val buffer = collection.mutable.ArrayBuffer.empty[Problem] | ||
def reset(): Unit = buffer.clear() | ||
def hasErrors: Boolean = buffer.exists(_.severity == Severity.Error) | ||
def hasWarnings: Boolean = buffer.exists(_.severity == Severity.Warn) | ||
def printSummary(): Unit = println(problems.mkString(System.lineSeparator)) | ||
def problems: Array[Problem] = buffer.toArray | ||
def log(pos: Position, msg: String, sev: Severity): Unit = { | ||
object MyProblem extends Problem { | ||
def category: String = null | ||
def severity: Severity = sev | ||
def message: String = msg | ||
def position: Position = pos | ||
override def toString = s"custom: $position:$severity: $message" | ||
} | ||
buffer.append(MyProblem) | ||
} | ||
def comment(pos: xsbti.Position, msg: String): Unit = () | ||
}) | ||
|
||
lazy val checkSettings = Seq( | ||
compilerReporter in (Compile, compile) := reporter, | ||
check <<= (compile in Compile).mapFailure( _ => { | ||
val problems = reporter.get.problems | ||
println(problems.toList) | ||
assert(problems.size == 2) | ||
assert(problems.count(_.severity == Severity.Error) == 1) // not found: er1, | ||
assert(problems.count(_.severity == Severity.Warn) == 1) // `with' as a type operator has been deprecated; use `&' instead, | ||
}) | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
> check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe[Int]
andMaybe[Integer]
are the same thing so just useMaybe[Int]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see https://github.com/lampepfl/dotty/pull/1530/files#r80051828