From e754a2d790e0cf5ab2c1480166a42cbb908add0f Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 4 Oct 2016 15:51:15 +0200 Subject: Change `typeDiff` to highlight changes less than 50% --- src/dotty/tools/dotc/util/DiffUtil.scala | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/dotty/tools/dotc/util/DiffUtil.scala') 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 = { -- cgit v1.2.3