aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-10-04 15:51:15 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-10 13:25:37 +0200
commite754a2d790e0cf5ab2c1480166a42cbb908add0f (patch)
tree7ca2847e39d1b487b060a188933ff1678a0ae806
parentd2b620541b18bb50d2a2b89194e1778c64bba567 (diff)
downloaddotty-e754a2d790e0cf5ab2c1480166a42cbb908add0f.tar.gz
dotty-e754a2d790e0cf5ab2c1480166a42cbb908add0f.tar.bz2
dotty-e754a2d790e0cf5ab2c1480166a42cbb908add0f.zip
Change `typeDiff` to highlight changes less than 50%
-rw-r--r--src/dotty/tools/dotc/printing/Formatting.scala12
-rw-r--r--src/dotty/tools/dotc/util/DiffUtil.scala15
2 files changed, 16 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/printing/Formatting.scala b/src/dotty/tools/dotc/printing/Formatting.scala
index 76d2bdc18..719c23e84 100644
--- a/src/dotty/tools/dotc/printing/Formatting.scala
+++ b/src/dotty/tools/dotc/printing/Formatting.scala
@@ -242,17 +242,17 @@ object Formatting {
* correct `Context` for printing should also be passed when calling the
* method.
*
- * @return the (found, expected) with coloring to highlight the difference
+ * @return the (found, expected, changePercentage) with coloring to
+ * highlight the difference
*/
def typeDiff(found: Type, expected: Type)(implicit ctx: Context): (String, String) = {
val fnd = wrapNonSensical(found, found.show)
val exp = wrapNonSensical(expected, expected.show)
- (found, expected) match {
- case (_: RefinedType, _: RefinedType) if ctx.settings.color.value != "never" =>
- DiffUtil.mkColoredTypeDiff(fnd, exp)
- case _ =>
- (hl"$fnd", hl"$exp")
+ DiffUtil.mkColoredTypeDiff(fnd, exp) match {
+ case _ if ctx.settings.color.value == "never" => (fnd, exp)
+ case (fnd, exp, change) if change < 0.5 => (fnd, exp)
+ case _ => (fnd, exp)
}
}
}
diff --git a/src/dotty/tools/dotc/util/DiffUtil.scala b/src/dotty/tools/dotc/util/DiffUtil.scala
index 8bb39c88a..b55aee719 100644
--- a/src/dotty/tools/dotc/util/DiffUtil.scala
+++ b/src/dotty/tools/dotc/util/DiffUtil.scala
@@ -32,8 +32,9 @@ object DiffUtil {
}
- /** @return a tuple of the (found, expected) diffs as strings */
- def mkColoredTypeDiff(found: String, expected: String): (String, String) = {
+ /** @return a tuple of the (found, expected, changedPercentage) diffs as strings */
+ def mkColoredTypeDiff(found: String, expected: String): (String, String, Double) = {
+ var totalChange = 0
val foundTokens = splitTokens(found, Nil).toArray
val expectedTokens = splitTokens(expected, Nil).toArray
@@ -42,15 +43,19 @@ object DiffUtil {
val exp = diffExp.collect {
case Unmodified(str) => str
- case Inserted(str) => ADDITION_COLOR + str + ANSI_DEFAULT
+ case Inserted(str) =>
+ totalChange += str.length
+ ADDITION_COLOR + str + ANSI_DEFAULT
}.mkString
val fnd = diffAct.collect {
case Unmodified(str) => str
- case Inserted(str) => DELETION_COLOR + str + ANSI_DEFAULT
+ case Inserted(str) =>
+ totalChange += str.length
+ DELETION_COLOR + str + ANSI_DEFAULT
}.mkString
- (fnd, exp)
+ (fnd, exp, totalChange.toDouble / (expected.length + found.length))
}
def mkColoredCodeDiff(code: String, lastCode: String, printDiffDel: Boolean): String = {