@@ -8,6 +8,9 @@ import ast.tpd._
8
8
import core ._
9
9
import Decorators ._ , printing .SyntaxHighlighting
10
10
import Types ._ , Symbols ._ , Contexts ._
11
+ import util .{ SimpleIdentityMap , SourcePosition }
12
+
13
+ import reporting .MessageRendering
11
14
12
15
import Effects ._ , Potentials ._
13
16
@@ -30,10 +33,31 @@ object Errors {
30
33
31
34
def toErrors : Errors = this :: Nil
32
35
36
+ /** pinpoints in stacktrace */
37
+ private var pinpoints : SimpleIdentityMap [Tree , String ] = SimpleIdentityMap .empty
38
+
39
+ def pinpoint (tree : Tree , msg : String ): this .type =
40
+ this .pinpoints = this .pinpoints.updated(tree, msg)
41
+ this
42
+
33
43
private def stacktracePrefix : String =
34
44
val str = if traceSuppressed then " suppressed" else " full"
35
45
" Calling trace (" + str + " ):\n "
36
46
47
+ private val render = new MessageRendering {}
48
+
49
+ private def pinpointText (pos : SourcePosition , msg : String , offset : Int )(using Context ): String =
50
+ val carets = render.hl(" Warning" ) {
51
+ if (pos.startLine == pos.endLine)
52
+ " ^" * math.max(1 , pos.endColumn - pos.startColumn)
53
+ else " ^"
54
+ }
55
+
56
+ val padding = pos.startColumnPadding + (" " * offset)
57
+ val marker = padding + carets
58
+ val textline = padding + msg
59
+ " \n " + marker + " \n " + textline
60
+
37
61
def stacktrace (using Context ): String = if (trace.isEmpty) " " else stacktracePrefix + {
38
62
var indentCount = 0
39
63
var last : String = " "
@@ -45,8 +69,12 @@ object Errors {
45
69
val line =
46
70
if pos.source.exists then
47
71
val loc = " [ " + pos.source.file.name + " :" + (pos.line + 1 ) + " ]"
48
- val code = SyntaxHighlighting .highlight(pos.lineContent.trim)
49
- i " $code\t $loc"
72
+ val code = SyntaxHighlighting .highlight(pos.lineContent.stripLineEnd)
73
+ val pinpoint =
74
+ if ! pinpoints.contains(tree) then " "
75
+ else pinpointText(pos, pinpoints(tree), indentCount + 3 )
76
+
77
+ i " $code\t $loc" + pinpoint
50
78
else
51
79
tree.show
52
80
0 commit comments