@@ -98,10 +98,39 @@ function showerror(io::IO, ex, bt; backtrace=true)
98
98
end
99
99
end
100
100
101
+ function stacktrace_path (file:: Union{Nothing, String} , line:: Union{Nothing, Int64} )
102
+ realfile = if ! isnothing (file) && file != " " && ! startswith (String (file), " REPL" )
103
+ fixup_stdlib_path (String (file))
104
+ end
105
+ pathstr = file
106
+ if ! isnothing (pathstr)
107
+ stacktrace_expand_basepaths () && (pathstr = something (find_source_file (file), file))
108
+ stacktrace_contract_userdir () && (pathstr = contractuser (pathstr))
109
+ end
110
+ linestr, llen = if ! isnothing (line) && line > 0
111
+ string (something (pathstr, " " ), ' :' , line), ncodeunits (string (line))
112
+ else
113
+ something (pathstr, " " ), 0
114
+ end
115
+ if ! isnothing (realfile)
116
+ flen = ncodeunits (basename (realfile))
117
+ AnnotatedString (linestr,
118
+ [(1 : ncodeunits (linestr), :link => Filesystem. uripath (realfile)),
119
+ (1 : ncodeunits (linestr)- flen- llen- 1 , :face => :julia_stacktrace_location ),
120
+ (ncodeunits (linestr)- flen- llen: ncodeunits (linestr)- llen- 1 , :face => :julia_stacktrace_filename ),
121
+ (ncodeunits (linestr)- llen: ncodeunits (linestr), :face => :julia_stacktrace_fileline )])
122
+ else
123
+ AnnotatedString (linestr, [(1 : ncodeunits (linestr), :face => :julia_stacktrace_location )])
124
+ end
125
+ end
126
+
127
+ stacktrace_path (location:: LineNumberNode ) =
128
+ stacktrace_path (if ! isnothing (location. file) String (location. file) end , location. line)
129
+
101
130
function showerror (io:: IO , ex:: LoadError , bt; backtrace= true )
102
131
! isa (ex. error, LoadError) && print (io, " LoadError: " )
103
132
showerror (io, ex. error, bt, backtrace= backtrace)
104
- print (io, " \n in expression starting at $ (ex. file) : $( ex. line)" )
133
+ print (io, " \n in expression starting at " , stacktrace_path (ex. file, ex. line))
105
134
end
106
135
showerror (io:: IO , ex:: LoadError ) = showerror (io, ex, [])
107
136
595
624
const update_stackframes_callback = Ref {Function} (identity)
596
625
597
626
const STACKTRACE_MODULECOLORS = Iterators. Stateful (Iterators. cycle ([:magenta , :cyan , :green , :yellow ]))
598
- const STACKTRACE_FIXEDCOLORS = IdDict (Base => :light_black , Core => :light_black )
627
+ const STACKTRACE_FIXEDCOLORS = IdDict (Base => :julia_stacktrace_basemodule , Core => :julia_stacktrace_basemodule )
599
628
600
629
function show_full_backtrace (io:: IO , trace:: Vector ; print_linebreaks:: Bool )
601
630
num_frames = length (trace)
@@ -680,9 +709,9 @@ function show_reduced_backtrace(io::IO, t::Vector)
680
709
cycle_length = repeated_cycle[1 ][2 ]
681
710
repetitions = repeated_cycle[1 ][3 ]
682
711
popfirst! (repeated_cycle)
683
- printstyled (io ,
684
- " --- the above " , cycle_length , " lines are repeated " ,
685
- repetitions, " more time " , repetitions > 1 ? " s " : " " , " --- " , color = :light_black )
712
+ repmsg = string ( " --- the above " , cycle_length, " lines are repeated " ,
713
+ repetitions , " more time " , repetitions > 1 ? " s " : " " , " --- " )
714
+ print (io, AnnotatedString (repmsg, [( 1 : ncodeunits (repmsg), :face => :julia_stacktrace_repetition )]) )
686
715
if i < length (displayed_stackframes)
687
716
println (io)
688
717
stacktrace_linebreaks () && println (io)
@@ -735,41 +764,30 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
735
764
digit_align_width = ndigits_max + 2
736
765
737
766
# frame number
738
- print (io, " " , lpad (" [ " * string (i) * " ] " , digit_align_width) )
739
- print (io, " " )
767
+ frameindex = lpad (' [ ' * string (i) * ' ] ' , digit_align_width)
768
+ print (io, ' ' , AnnotatedString (frameindex, [( 1 : ncodeunits (frameindex), :face => :julia_stacktrace_frameindex )]), ' ' )
740
769
741
770
StackTraces. show_spec_linfo (IOContext (io, :backtrace => true ), frame)
742
771
if n > 1
743
- printstyled (io, " (repeats $n times)" ; color= :light_black )
772
+ repmsg = " (repeats $n times)"
773
+ print (io, AnnotatedString (repmsg, [(2 : ncodeunits (repmsg), :face => :julia_stacktrace_repetition )]))
744
774
end
745
775
println (io)
746
776
747
777
# @ Module path / file : line
748
778
print_module_path_file (io, modul, file, line; modulecolor, digit_align_width)
749
779
750
780
# inlined
751
- printstyled (io, inlined ? " [inlined]" : " " , color = :light_black )
781
+ print (io, if inlined AnnotatedString ( " [inlined]" , [( 1 : 9 , :face => :julia_stacktrace_inlined )]) else " " end )
752
782
end
753
783
754
- function print_module_path_file (io, modul, file, line; modulecolor = :light_black , digit_align_width = 0 )
755
- printstyled (io, " " ^ digit_align_width * " @" , color = :light_black )
756
-
757
- # module
784
+ function print_module_path_file (io, modul, file, line; modulecolor = :bright_black , digit_align_width = 0 )
785
+ print (io, ' ' ^ digit_align_width, AnnotatedString (" @" , [(1 : 1 , :face => :julia_stacktrace_location )]))
758
786
if modul != = nothing && modulecolor != = nothing
759
- print (io, " " )
760
- printstyled (io, modul, color = modulecolor)
787
+ mstr = string (modul )
788
+ print (io, " " , AnnotatedString (mstr, [( 1 : ncodeunits (mstr), :face => modulecolor)]) )
761
789
end
762
-
763
- # filepath
764
- file = fixup_stdlib_path (file)
765
- stacktrace_expand_basepaths () && (file = something (find_source_file (file), file))
766
- stacktrace_contract_userdir () && (file = contractuser (file))
767
- print (io, " " )
768
- dir = dirname (file)
769
- ! isempty (dir) && printstyled (io, dir, Filesystem. path_separator, color = :light_black )
770
-
771
- # filename, separator, line
772
- printstyled (io, basename (file), " :" , line; color = :light_black , underline = true )
790
+ print (io, ' ' , stacktrace_path (file, line))
773
791
end
774
792
775
793
function show_backtrace (io:: IO , t:: Vector )
0 commit comments