Skip to content

Commit

Permalink
Refine stacktrace printing
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Jan 31, 2020
1 parent c2d1a3c commit 97d4b22
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/init/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package init
import ast.tpd._

import core._
import Decorators._
import Decorators._, printing.SyntaxHighlighting
import Types._, Symbols._, Contexts._
import util.NoSourcePosition
import util.SourcePosition

import Effects._, Potentials._

Expand All @@ -30,19 +30,22 @@ object Errors {

def stacktrace(implicit ctx: Context): String = if (trace.isEmpty) "" else " Calling trace:\n" + {
var indentCount = 0
var last = ""
var last: String = ""
val sb = new StringBuilder
trace.foreach { tree =>
indentCount += 1
val pos = tree.sourcePos
val line = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]"
if (last != line)
sb.append(
if (pos.source.exists)
i"${ " " * indentCount }-> ${pos.lineContent.trim}\t$line\n"
else
i"${tree.show}\n"
)
val prefix = s"${ " " * indentCount }-> "
val line =
if pos.source.exists then
val loc = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]"
val code = SyntaxHighlighting.highlight(pos.lineContent.trim)
i"$code\t$loc"
else
tree.show

if (last != line) sb.append(prefix + line + "\n")

last = line
}
sb.toString
Expand Down

0 comments on commit 97d4b22

Please sign in to comment.