@@ -100,10 +100,39 @@ function showerror(io::IO, ex, bt; backtrace=true)
100
100
end
101
101
end
102
102
103
+ function stacktrace_path (file:: Union{Nothing, String} , line:: Union{Nothing, Int64} )
104
+ realfile = if ! isnothing (file) && file != " " && ! startswith (String (file), " REPL" )
105
+ fixup_stdlib_path (String (file))
106
+ end
107
+ pathstr = file
108
+ if ! isnothing (pathstr)
109
+ stacktrace_expand_basepaths () && (pathstr = something (find_source_file (file), file))
110
+ stacktrace_contract_userdir () && (pathstr = contractuser (pathstr))
111
+ end
112
+ linestr, llen = if ! isnothing (line) && line > 0
113
+ string (something (pathstr, " " ), ' :' , line), ncodeunits (string (line))
114
+ else
115
+ something (pathstr, " " ), 0
116
+ end
117
+ if ! isnothing (realfile)
118
+ flen = ncodeunits (basename (realfile))
119
+ AnnotatedString (linestr,
120
+ [(1 : ncodeunits (linestr), :link => Filesystem. uripath (realfile)),
121
+ (1 : ncodeunits (linestr)- flen- llen- 1 , :face => :julia_stacktrace_location ),
122
+ (ncodeunits (linestr)- flen- llen: ncodeunits (linestr)- llen- 1 , :face => :julia_stacktrace_filename ),
123
+ (ncodeunits (linestr)- llen: ncodeunits (linestr), :face => :julia_stacktrace_fileline )])
124
+ else
125
+ AnnotatedString (linestr, [(1 : ncodeunits (linestr), :face => :julia_stacktrace_location )])
126
+ end
127
+ end
128
+
129
+ stacktrace_path (location:: LineNumberNode ) =
130
+ stacktrace_path (if ! isnothing (location. file) String (location. file) end , location. line)
131
+
103
132
function showerror (io:: IO , ex:: LoadError , bt; backtrace= true )
104
133
! isa (ex. error, LoadError) && print (io, " LoadError: " )
105
134
showerror (io, ex. error, bt, backtrace= backtrace)
106
- print (io, " \n in expression starting at $ (ex. file) : $( ex. line)" )
135
+ print (io, " \n in expression starting at " , stacktrace_path (ex. file, ex. line))
107
136
end
108
137
showerror (io:: IO , ex:: LoadError ) = showerror (io, ex, [])
109
138
616
645
const update_stackframes_callback = Ref {Function} (identity)
617
646
618
647
const STACKTRACE_MODULECOLORS = Iterators. Stateful (Iterators. cycle ([:magenta , :cyan , :green , :yellow ]))
619
- const STACKTRACE_FIXEDCOLORS = IdDict (Base => :light_black , Core => :light_black )
648
+ const STACKTRACE_FIXEDCOLORS = IdDict (Base => :julia_stacktrace_basemodule , Core => :julia_stacktrace_basemodule )
620
649
621
650
function show_full_backtrace (io:: IO , trace:: Vector ; print_linebreaks:: Bool )
622
651
num_frames = length (trace)
@@ -701,9 +730,9 @@ function show_reduced_backtrace(io::IO, t::Vector)
701
730
cycle_length = repeated_cycle[1 ][2 ]
702
731
repetitions = repeated_cycle[1 ][3 ]
703
732
popfirst! (repeated_cycle)
704
- printstyled (io ,
705
- " --- the above " , cycle_length , " lines are repeated " ,
706
- repetitions, " more time " , repetitions > 1 ? " s " : " " , " --- " , color = :light_black )
733
+ repmsg = string ( " --- the above " , cycle_length, " lines are repeated " ,
734
+ repetitions , " more time " , repetitions > 1 ? " s " : " " , " --- " )
735
+ print (io, AnnotatedString (repmsg, [( 1 : ncodeunits (repmsg), :face => :julia_stacktrace_repetition )]) )
707
736
if i < length (displayed_stackframes)
708
737
println (io)
709
738
stacktrace_linebreaks () && println (io)
@@ -756,41 +785,30 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
756
785
digit_align_width = ndigits_max + 2
757
786
758
787
# frame number
759
- print (io, " " , lpad (" [ " * string (i) * " ] " , digit_align_width) )
760
- print (io, " " )
788
+ frameindex = lpad (' [ ' * string (i) * ' ] ' , digit_align_width)
789
+ print (io, ' ' , AnnotatedString (frameindex, [( 1 : ncodeunits (frameindex), :face => :julia_stacktrace_frameindex )]), ' ' )
761
790
762
791
StackTraces. show_spec_linfo (IOContext (io, :backtrace => true ), frame)
763
792
if n > 1
764
- printstyled (io, " (repeats $n times)" ; color= :light_black )
793
+ repmsg = " (repeats $n times)"
794
+ print (io, AnnotatedString (repmsg, [(2 : ncodeunits (repmsg), :face => :julia_stacktrace_repetition )]))
765
795
end
766
796
println (io)
767
797
768
798
# @ Module path / file : line
769
799
print_module_path_file (io, modul, file, line; modulecolor, digit_align_width)
770
800
771
801
# inlined
772
- printstyled (io, inlined ? " [inlined]" : " " , color = :light_black )
802
+ print (io, if inlined AnnotatedString ( " [inlined]" , [( 1 : 9 , :face => :julia_stacktrace_inlined )]) else " " end )
773
803
end
774
804
775
- function print_module_path_file (io, modul, file, line; modulecolor = :light_black , digit_align_width = 0 )
776
- printstyled (io, " " ^ digit_align_width * " @" , color = :light_black )
777
-
778
- # module
805
+ function print_module_path_file (io, modul, file, line; modulecolor = :bright_black , digit_align_width = 0 )
806
+ print (io, ' ' ^ digit_align_width, AnnotatedString (" @" , [(1 : 1 , :face => :julia_stacktrace_location )]))
779
807
if modul != = nothing && modulecolor != = nothing
780
- print (io, " " )
781
- printstyled (io, modul, color = modulecolor)
808
+ mstr = string (modul )
809
+ print (io, " " , AnnotatedString (mstr, [( 1 : ncodeunits (mstr), :face => modulecolor)]) )
782
810
end
783
-
784
- # filepath
785
- file = fixup_stdlib_path (file)
786
- stacktrace_expand_basepaths () && (file = something (find_source_file (file), file))
787
- stacktrace_contract_userdir () && (file = contractuser (file))
788
- print (io, " " )
789
- dir = dirname (file)
790
- ! isempty (dir) && printstyled (io, dir, Filesystem. path_separator, color = :light_black )
791
-
792
- # filename, separator, line
793
- printstyled (io, basename (file), " :" , line; color = :light_black , underline = true )
811
+ print (io, ' ' , stacktrace_path (file, line))
794
812
end
795
813
796
814
function show_backtrace (io:: IO , t:: Vector )
0 commit comments