diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-09-20 17:32:23 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-10-10 13:25:35 +0200 |
commit | 88e41465dd1dcecaa3cd8f0971e8d71e61d48490 (patch) | |
tree | 6f5d905d5e3e3c57ce5fd6f45af0a4d295c431e9 /src/dotty/tools | |
parent | 153c566d0d6ec8f2e55ab575e1e77f7881629cbc (diff) | |
download | dotty-88e41465dd1dcecaa3cd8f0971e8d71e61d48490.tar.gz dotty-88e41465dd1dcecaa3cd8f0971e8d71e61d48490.tar.bz2 dotty-88e41465dd1dcecaa3cd8f0971e8d71e61d48490.zip |
Add basic diffing for shown values
Diffstat (limited to 'src/dotty/tools')
-rw-r--r-- | src/dotty/tools/dotc/util/DiffUtil.scala | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/util/DiffUtil.scala b/src/dotty/tools/dotc/util/DiffUtil.scala index b7c77ad62..8bb39c88a 100644 --- a/src/dotty/tools/dotc/util/DiffUtil.scala +++ b/src/dotty/tools/dotc/util/DiffUtil.scala @@ -12,9 +12,7 @@ object DiffUtil { private final val DELETION_COLOR = ANSI_RED private final val ADDITION_COLOR = ANSI_GREEN - def mkColoredCodeDiff(code: String, lastCode: String, printDiffDel: Boolean): String = { - - @tailrec def splitTokens(str: String, acc: List[String] = Nil): List[String] = { + @tailrec private def splitTokens(str: String, acc: List[String] = Nil): List[String] = { if (str == "") { acc.reverse } else { @@ -33,6 +31,30 @@ object DiffUtil { } } + + /** @return a tuple of the (found, expected) diffs as strings */ + def mkColoredTypeDiff(found: String, expected: String): (String, String) = { + val foundTokens = splitTokens(found, Nil).toArray + val expectedTokens = splitTokens(expected, Nil).toArray + + val diffExp = hirschberg(foundTokens, expectedTokens) + val diffAct = hirschberg(expectedTokens, foundTokens) + + val exp = diffExp.collect { + case Unmodified(str) => str + case Inserted(str) => ADDITION_COLOR + str + ANSI_DEFAULT + }.mkString + + val fnd = diffAct.collect { + case Unmodified(str) => str + case Inserted(str) => DELETION_COLOR + str + ANSI_DEFAULT + }.mkString + + (fnd, exp) + } + + def mkColoredCodeDiff(code: String, lastCode: String, printDiffDel: Boolean): String = { + val tokens = splitTokens(code, Nil).toArray val lastTokens = splitTokens(lastCode, Nil).toArray |