diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-03-31 11:47:47 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-03-31 11:55:06 +0200 |
commit | 6d7c23016ec866de0b29e9bdde00b60c99df90c2 (patch) | |
tree | 6a6e0bdff7aefa783b46415523f7c864f0785253 /compiler/src | |
parent | f9db9097d0cf314d675669d80f8d5eb8d20f0710 (diff) | |
download | dotty-6d7c23016ec866de0b29e9bdde00b60c99df90c2.tar.gz dotty-6d7c23016ec866de0b29e9bdde00b60c99df90c2.tar.bz2 dotty-6d7c23016ec866de0b29e9bdde00b60c99df90c2.zip |
Make DiffUtil's rendering readable in logs
Diffstat (limited to 'compiler/src')
-rw-r--r-- | compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala | 2 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/util/DiffUtil.scala | 19 |
2 files changed, 19 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala index 17eb8d39b..91e65ab66 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala @@ -21,7 +21,7 @@ trait MessageRendering { * @return string stripped of ANSI escape codes */ def stripColor(str: String): String = - str.replaceAll("\u001B\\[[;\\d]*m", "") + str.replaceAll("\u001b\\[.*?m", "") /** When inlining a method call, if there's an error we'd like to get the * outer context and the `pos` at which the call was inlined. diff --git a/compiler/src/dotty/tools/dotc/util/DiffUtil.scala b/compiler/src/dotty/tools/dotc/util/DiffUtil.scala index b55aee719..6f7df13a6 100644 --- a/compiler/src/dotty/tools/dotc/util/DiffUtil.scala +++ b/compiler/src/dotty/tools/dotc/util/DiffUtil.scala @@ -58,8 +58,25 @@ object DiffUtil { (fnd, exp, totalChange.toDouble / (expected.length + found.length)) } - def mkColoredCodeDiff(code: String, lastCode: String, printDiffDel: Boolean): String = { + def mkColoredLineDiff(expected: String, actual: String): String = { + val tokens = splitTokens(expected, Nil).toArray + val lastTokens = splitTokens(actual, Nil).toArray + + val diff = hirschberg(lastTokens, tokens) + " |SOF\n" + diff.collect { + case Unmodified(str) => + " |" + str + case Inserted(str) => + ADDITION_COLOR + "e |" + str + ANSI_DEFAULT + case Modified(old, str) => + DELETION_COLOR + "a |" + old + "\ne |" + ADDITION_COLOR + str + ANSI_DEFAULT + case Deleted(str) => + DELETION_COLOR + "\na |" + str + ANSI_DEFAULT + }.mkString + "\n |EOF" + } + + def mkColoredCodeDiff(code: String, lastCode: String, printDiffDel: Boolean): String = { val tokens = splitTokens(code, Nil).toArray val lastTokens = splitTokens(lastCode, Nil).toArray |