Skip to content

Commit

Permalink
bold function names in stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Abbott committed Oct 18, 2020
1 parent 16e2fd3 commit b7809f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,8 @@ function show_signature_function(io::IO, @nospecialize(ft), demangle=false, farg
if ft <: Function && isa(uw, DataType) && isempty(uw.parameters) &&
isdefined(uw.name.module, uw.name.mt.name) &&
ft == typeof(getfield(uw.name.module, uw.name.mt.name))
show_sym(io, (demangle ? demangle_function_name : identity)(uw.name.mt.name))
s = sprint(show_sym, (demangle ? demangle_function_name : identity)(uw.name.mt.name), context=io)
print_within_stacktrace(io, s, bold=true)
elseif isa(ft, DataType) && ft.name === Type.body.name &&
(f = ft.parameters[1]; !isa(f, TypeVar))
uwf = unwrap_unionall(f)
Expand All @@ -2076,19 +2077,20 @@ function show_signature_function(io::IO, @nospecialize(ft), demangle=false, farg
if html
print(io, "($fargname::<b>", ft, "</b>)")
else
print(io, "($fargname::", ft, ")")
print_within_stacktrace(io, "($fargname::", ft, ")", bold=true)
end
end
nothing
end

function print_within_stacktrace(io, s...; color, bold=false)
function print_within_stacktrace(io, s...; color=:normal, bold=false)
if get(io, :backtrace, false)::Bool
printstyled(io, s...; color, bold)
else
print(io, s...)
end
end

function show_tuple_as_call(io::IO, name::Symbol, sig::Type, demangle=false, kwargs=nothing, argnames=nothing)
# print a method signature tuple for a lambda definition
if sig === Tuple
Expand Down Expand Up @@ -2127,15 +2129,15 @@ function show_tuple_as_call(io::IO, name::Symbol, sig::Type, demangle=false, kwa
print_type_stacktrace(io, t)
end
end
print(io, ")")
print_within_stacktrace(io, ")", bold=true)
show_method_params(io, tv)
nothing
end

function print_type_stacktrace(io, type; color=:normal)
str = sprint(show, type, context=io)
i = findfirst('{', str)
if isnothing(i)
if isnothing(i) || !get(io, :backtrace, false)::Bool
printstyled(io, str; color=color)
else
printstyled(io, str[1:i-1]; color=color)
Expand Down
2 changes: 1 addition & 1 deletion base/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function show_spec_linfo(io::IO, frame::StackFrame)
elseif frame.func === top_level_scope_sym
print(io, "top-level scope")
else
print(io, Base.demangle_function_name(string(frame.func)))
Base.print_within_stacktrace(io, Base.demangle_function_name(string(frame.func)), bold=true)
end
elseif linfo isa MethodInstance
def = linfo.def
Expand Down

0 comments on commit b7809f3

Please sign in to comment.