Skip to content

Commit

Permalink
fix #4469, fix #2758, reopen #5230
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Feb 26, 2014
1 parent 0dbbaf7 commit 502e62a
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function argtype_decl(n, t) # -> (argname, argtype)
return s, string(t)
end

function arg_decl_parts(m::Method)
function arg_decl_parts(m::Method, kwfunc::Bool=false)
tv = m.tvars
if !isa(tv,Tuple)
tv = (tv,)
Expand All @@ -28,25 +28,35 @@ function arg_decl_parts(m::Method)
argnames = e.args[1]
s = symbol("?")
decls = [argtype_decl(get(argnames,i,s), m.sig[i]) for i=1:length(m.sig)]
return tv, decls, li.file, li.line
if kwfunc
shift!(decls)
kwargs = filter!(x->!('#' in string(x)), e.args[2][1])
else
kwargs = ()
end
return tv, decls, kwargs, li.file, li.line
end

function show(io::IO, m::Method)
function show(io::IO, m::Method; kwfunc::Bool=false)
print(io, m.func.code.name)
tv, decls, file, line = arg_decl_parts(m)
tv, decls, kwargs, file, line = arg_decl_parts(m, kwfunc)
if !isempty(tv)
show_delim_array(io, tv, '{', ',', '}', false)
end
print(io, "(")
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls],
",", ",")
if kwfunc
print(io, ";")
print_joined(io, kwargs, ",", ",")
end
print(io, ")")
if line > 0
print(io, " at ", file, ":", line)
end
end

function show_method_table(io::IO, mt::MethodTable, max::Int=-1, header::Bool=true)
function show_method_table(io::IO, mt::MethodTable, max::Int=-1, header::Bool=true, kwfunc::Bool=false)
name = mt.name
n = length(mt)
if header
Expand All @@ -58,13 +68,16 @@ function show_method_table(io::IO, mt::MethodTable, max::Int=-1, header::Bool=tr
while !is(d,())
if max==-1 || n<max || (rest==0 && n==max && d.next === ())
println(io)
show(io, d)
show(io, d; kwfunc=kwfunc)
n += 1
else
rest += 1
end
d = d.next
end
if isdefined(mt, :kwsorter) && (max == -1 || n+length(mt.kwsorter)<max || (rest==0 && length(mt.kwsorter)==max))
show_method_table(io, mt.kwsorter.env, max==-1 ? -1 : max-n, false, true)
end
if rest > 0
println(io)
print(io,"... $rest methods not shown (use methods($name) to see them all)")
Expand All @@ -75,6 +88,9 @@ show(io::IO, mt::MethodTable) = show_method_table(io, mt)

inbase(m::Module) = m == Base ? true : m == Main ? false : inbase(module_parent(m))
function url(m::Method)
if m.func.code.file == :none
return ""
end
M = m.func.code.module
file = string(m.func.code.file)
line = m.func.code.line
Expand All @@ -96,14 +112,18 @@ function url(m::Method)
return "file://"*find_source_file(file)
end
catch
return "file://"*find_source_file(file)
path = find_source_file(file)
if path === nothing
return ""
end
return "file://"*path
end
end
end

function writemime(io::IO, ::MIME"text/html", m::Method)
function writemime(io::IO, ::MIME"text/html", m::Method; kwfunc::Bool=false)
print(io, m.func.code.name)
tv, decls, file, line = arg_decl_parts(m)
tv, decls, kwargs, file, line = arg_decl_parts(m, kwfunc)
if !isempty(tv)
print(io,"<i>")
show_delim_array(io, tv, '{', ',', '}', false)
Expand All @@ -112,6 +132,11 @@ function writemime(io::IO, ::MIME"text/html", m::Method)
print(io, "(")
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::<b>"*d[2]*"</b>"
for d in decls], ",", ",")
if kwfunc
print(io, ";<i>")
print_joined(io, kwargs, ",", ",")
print(io, "</i>")
end
print(io, ")")
if line > 0
u = url(m)
Expand All @@ -133,8 +158,18 @@ function writemime(io::IO, mime::MIME"text/html", mt::MethodTable)
while !is(d,())
print(io, "<li> ")
writemime(io, mime, d)
print(io, "</li> ")
d = d.next
end
if isdefined(mt, :kwsorter)
d = mt.kwsorter.env.defs
while !is(d,())
print(io, "<li> ")
writemime(io, mime, d; kwfunc=true)
print(io, "</li> ")
d = d.next
end
end
print(io, "</ul>")
end

Expand Down

0 comments on commit 502e62a

Please sign in to comment.