aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-09-16 22:28:27 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-10 13:25:34 +0200
commit787a2ceec02fe07fbb9efee673d3abb7cac2969e (patch)
treee64a077eea45b0298aca88fdfdd459cf9e1a9e83 /src
parent5c243778279d8b258d7b1d34dd5146dff07eb437 (diff)
downloaddotty-787a2ceec02fe07fbb9efee673d3abb7cac2969e.tar.gz
dotty-787a2ceec02fe07fbb9efee673d3abb7cac2969e.tar.bz2
dotty-787a2ceec02fe07fbb9efee673d3abb7cac2969e.zip
Add modifiers to highlighting
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/Compiler.scala4
-rw-r--r--src/dotty/tools/dotc/Driver.scala6
-rw-r--r--src/dotty/tools/dotc/printing/Highlighting.scala70
-rw-r--r--src/dotty/tools/dotc/reporting/ConsoleReporter.scala2
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala2
-rw-r--r--src/dotty/tools/dotc/typer/ErrorReporting.scala6
6 files changed, 49 insertions, 41 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala
index d6e3cc89b..ea6254f5b 100644
--- a/src/dotty/tools/dotc/Compiler.scala
+++ b/src/dotty/tools/dotc/Compiler.scala
@@ -140,10 +140,6 @@ class Compiler {
.setTyper(new Typer)
.setMode(Mode.ImplicitsEnabled)
.setTyperState(new MutableTyperState(ctx.typerState, ctx.typerState.reporter, isCommittable = true))
- .setReporter(
- if (ctx.settings.color.value == "never") new ConsoleReporter()
- else new FancyConsoleReporter()
- )
ctx.initialize()(start) // re-initialize the base context with start
def addImport(ctx: Context, refFn: () => TermRef) =
ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx))
diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala
index f54a23ad2..b2dc18d2a 100644
--- a/src/dotty/tools/dotc/Driver.scala
+++ b/src/dotty/tools/dotc/Driver.scala
@@ -22,7 +22,11 @@ abstract class Driver extends DotClass {
protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
if (fileNames.nonEmpty)
try {
- val run = compiler.newRun
+ val fresh = ctx.fresh.setReporter {
+ if (ctx.settings.color.value == "never") new ConsoleReporter()
+ else new FancyConsoleReporter()
+ }
+ val run = compiler.newRun(fresh)
run.compile(fileNames)
run.printSummary()
}
diff --git a/src/dotty/tools/dotc/printing/Highlighting.scala b/src/dotty/tools/dotc/printing/Highlighting.scala
index a496976a1..75f83bf29 100644
--- a/src/dotty/tools/dotc/printing/Highlighting.scala
+++ b/src/dotty/tools/dotc/printing/Highlighting.scala
@@ -6,33 +6,38 @@ import scala.collection.mutable
object Highlighting {
- implicit def colorToString(c: Color): String = c.toString
- implicit def cbufToString(cb: ColorBuffer): String = cb.toString
+ implicit def highlightToString(h: Highlight): String = h.toString
+ implicit def hbufToString(hb: HighlightBuffer): String = hb.toString
- abstract class Color(private val color: String) {
+ abstract class Highlight(private val highlight: String) {
def text: String
- override def toString = color + text + Console.RESET
+ override def toString = highlight + text + Console.RESET
- def +(other: Color): ColorBuffer =
- new ColorBuffer(this) + other
+ def +(other: Highlight): HighlightBuffer =
+ new HighlightBuffer(this) + other
- def +(other: String): ColorBuffer =
- new ColorBuffer(this) + other
+ def +(other: String): HighlightBuffer =
+ new HighlightBuffer(this) + other
}
- case class ColorBuffer(color: Color) {
+ abstract class Modifier(private val mod: String, text: String) extends Highlight(Console.RESET) {
+ override def toString =
+ mod + super.toString
+ }
+
+ case class HighlightBuffer(hl: Highlight) {
val buffer = new mutable.ListBuffer[String]
- buffer += color.toString
+ buffer += hl.toString
- def +(color: Color): ColorBuffer = {
- buffer += color.toString
+ def +(other: Highlight): HighlightBuffer = {
+ buffer += other.toString
this
}
- def +(str: String): ColorBuffer = {
- buffer += str
+ def +(other: String): HighlightBuffer = {
+ buffer += other
this
}
@@ -40,21 +45,24 @@ object Highlighting {
buffer.mkString
}
- case class Red(text: String) extends Color(Console.RED)
- case class Blue(text: String) extends Color(Console.BLUE)
- case class Cyan(text: String) extends Color(Console.CYAN)
- case class Black(text: String) extends Color(Console.BLACK)
- case class Green(text: String) extends Color(Console.GREEN)
- case class White(text: String) extends Color(Console.WHITE)
- case class Yellow(text: String) extends Color(Console.YELLOW)
- case class Magenta(text: String) extends Color(Console.MAGENTA)
-
- case class RedB(text: String) extends Color(Console.RED_B)
- case class BlueB(text: String) extends Color(Console.BLUE_B)
- case class CyanB(text: String) extends Color(Console.CYAN_B)
- case class BlackB(text: String) extends Color(Console.BLACK_B)
- case class GreenB(text: String) extends Color(Console.GREEN_B)
- case class WhiteB(text: String) extends Color(Console.WHITE_B)
- case class YellowB(text: String) extends Color(Console.YELLOW_B)
- case class MagentaB(text: String) extends Color(Console.MAGENTA_B)
+ case class Red(text: String) extends Highlight(Console.RED)
+ case class Blue(text: String) extends Highlight(Console.BLUE)
+ case class Cyan(text: String) extends Highlight(Console.CYAN)
+ case class Black(text: String) extends Highlight(Console.BLACK)
+ case class Green(text: String) extends Highlight(Console.GREEN)
+ case class White(text: String) extends Highlight(Console.WHITE)
+ case class Yellow(text: String) extends Highlight(Console.YELLOW)
+ case class Magenta(text: String) extends Highlight(Console.MAGENTA)
+
+ case class RedB(text: String) extends Highlight(Console.RED_B)
+ case class BlueB(text: String) extends Highlight(Console.BLUE_B)
+ case class CyanB(text: String) extends Highlight(Console.CYAN_B)
+ case class BlackB(text: String) extends Highlight(Console.BLACK_B)
+ case class GreenB(text: String) extends Highlight(Console.GREEN_B)
+ case class WhiteB(text: String) extends Highlight(Console.WHITE_B)
+ case class YellowB(text: String) extends Highlight(Console.YELLOW_B)
+ case class MagentaB(text: String) extends Highlight(Console.MAGENTA_B)
+
+ case class Bold(text: String) extends Modifier(Console.BOLD, text)
+ case class Underlined(text: String) extends Modifier(Console.UNDERLINED, text)
}
diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
index a00813328..b532d05c2 100644
--- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
+++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
@@ -37,7 +37,7 @@ class ConsoleReporter(
/** Prints the message with the given position indication. */
def printMessageAndPos(msg: String, pos: SourcePosition, kind: String = "")(implicit ctx: Context): Unit = {
val posStr = if (pos.exists) s"$pos: " else ""
- printMessage(posStr + kind + msg)
+ printMessage(s"${posStr}$kind: $msg")
if (pos.exists) {
printSourceLine(pos)
printColumnMarker(pos)
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala b/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala
index 4be325b63..99ccca4cc 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala
@@ -7,7 +7,7 @@ import util.{SourcePosition, NoSourcePosition}
import core.Contexts.Context
object MessageCreator {
- implicit def toNoExplanation(str: String) =
+ implicit def toNoExplanation(str: String): MessageCreator =
new NoExplanation(str)
}
diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala
index c8e76aa97..43c093510 100644
--- a/src/dotty/tools/dotc/typer/ErrorReporting.scala
+++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala
@@ -131,9 +131,9 @@ object ErrorReporting {
val found1 = reported(found)
reported.setVariance(-1)
val expected1 = reported(expected)
- ex"""type mismatch:
- | found : $found1
- | required: $expected1""" + whyNoMatchStr(found, expected)
+ ex"""|type mismatch:
+ |found: $found1
+ |required: $expected1""".stripMargin + whyNoMatchStr(found, expected)
}
/** Format `raw` implicitNotFound argument, replacing all