diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-10-04 15:51:15 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-10-10 13:25:37 +0200 |
commit | e754a2d790e0cf5ab2c1480166a42cbb908add0f (patch) | |
tree | 7ca2847e39d1b487b060a188933ff1678a0ae806 /src/dotty/tools/dotc/util/DiffUtil.scala | |
parent | d2b620541b18bb50d2a2b89194e1778c64bba567 (diff) | |
download | dotty-e754a2d790e0cf5ab2c1480166a42cbb908add0f.tar.gz dotty-e754a2d790e0cf5ab2c1480166a42cbb908add0f.tar.bz2 dotty-e754a2d790e0cf5ab2c1480166a42cbb908add0f.zip |
Change `typeDiff` to highlight changes less than 50%
Diffstat (limited to 'src/dotty/tools/dotc/util/DiffUtil.scala')
-rw-r--r-- | src/dotty/tools/dotc/util/DiffUtil.scala | 15 |
1 files changed, 10 insertions, 5 deletions
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 = { |