Skip to content

Commit

Permalink
Merge pull request #13330 from MichaelHatherly/mh/docsys-fixes
Browse files Browse the repository at this point in the history
Docsystem refactoring
  • Loading branch information
jakebolewski committed Sep 28, 2015
2 parents 5acbcc6 + 8c236e9 commit 26a4df7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
81 changes: 31 additions & 50 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ function doc(b::Binding)
`$(b.mod === Main ? b.var : join((b.mod, b.var),'.'))` is $(isgeneric(v) ? "a generic" : "an anonymous") `Function`.
"""), functionsummary(v))
elseif isa(v,DataType)
d = catdoc(Markdown.parse("""
No documentation found.
"""), typesummary(v))
else
T = typeof(v)
d = catdoc(Markdown.parse("""
Expand Down Expand Up @@ -234,37 +239,6 @@ function doc!(f::Function, sig::ANY, data, source)
fd.source[sig] = source
end

doc(f::Function) = doc(f, Tuple)

function doc(f::Function, sig::Type)
isgeneric(f) && isempty(methods(f,sig)) && return nothing
results, funcdocs = [], []
for mod in modules
if (haskey(meta(mod), f) && isa(meta(mod)[f], FuncDoc))
fd = meta(mod)[f]
push!(funcdocs, fd)
for msig in fd.order
# try to find specific matching method signatures
if sig <: msig
push!(results, (msig, fd.meta[msig]))
end
end
end
end
# if all method signatures are Union{} ( ⊥ ), concat all docstrings
if isempty(results)
for fd in funcdocs
append!(results, [fd.meta[msig] for msig in reverse(fd.order)])
end
else
sort!(results, lt = (a, b) -> type_morespecific(first(a), first(b)))
results = [last(r) for r in results]
end
catdoc(results...)
end
doc(f::Function,args::Any...) = doc(f, Tuple{args...})


"""
`catdoc(xs...)`: Combine the documentation metadata `xs` into a single meta object.
"""
Expand Down Expand Up @@ -317,32 +291,39 @@ function doc!(T::DataType, sig::ANY, data, source)
td.meta[sig] = data
end

function doc(T::DataType)
docs = []
for mod in modules
if haskey(meta(mod), T)
Td = meta(mod)[T]
if isa(Td, TypeDoc)
if length(docs) == 0 && Td.main !== nothing
push!(docs, Td.main)
function doc(obj::Base.Callable, sig::Type = Union)
isgeneric(obj) && sig !== Union && isempty(methods(obj, sig)) && return nothing
results, groups = [], []
for m in modules
if haskey(meta(m), obj)
docs = meta(m)[obj]
if isa(docs, FuncDoc) || isa(docs, TypeDoc)
push!(groups, docs)
for msig in docs.order
if sig <: msig
push!(results, (msig, docs.meta[msig]))
end
end
for m in Td.order
push!(docs, Td.meta[m])
if isempty(results) && docs.main !== nothing
push!(results, (Union{}, docs.main))
end
elseif length(docs) == 0
return Td
else
push!(results, (Union{}, docs))
end
end
end
if isempty(docs)
catdoc(Markdown.parse("""
No documentation found.
"""), typesummary(T))
else
catdoc(docs...)
# If all method signatures are Union{} ( ⊥ ), concat all docstrings.
if isempty(results)
for group in groups
append!(results, [group.meta[s] for s in reverse(group.order)])
end
else
sort!(results, lt = (a, b) -> type_morespecific(first(a), first(b)))
results = map(last, results)
end
catdoc(results...)
end
doc(f::Base.Callable, args::Any...) = doc(f, Tuple{args...})

function typesummary(T::DataType)
parts = [
Expand Down
41 changes: 30 additions & 11 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,40 @@ end

repl_corrections(s) = repl_corrections(STDOUT, s)

macro repl(ex)
macro repl(ex) repl(ex) end

function repl(s::Symbol)
quote
# Fuzzy Searching
$(isexpr(ex, Symbol)) && repl_search($(string(ex)))
if $(isa(ex, Symbol)) &&
!(isdefined($(current_module()), $(Expr(:quote, ex))) ||
haskey(keywords, $(Expr(:quote, ex))))
repl_corrections($(string(ex)))
else
if $(isfield(ex) ? :(isa($(esc(ex.args[1])), DataType)) : false)
$(isfield(ex) ? :(fielddoc($(esc(ex.args[1])), $(ex.args[2]))) : nothing)
repl_search($(string(s)))
($(isdefined(s) || haskey(keywords, s))) || repl_corrections($(string(s)))
$(_repl(s))
end
end

isregex(x) = isexpr(x, :macrocall, 2) && x.args[1] == symbol("@r_str") && !isempty(x.args[2])

repl(ex::Expr) = isregex(ex) ? :(apropos($ex)) : _repl(ex)

repl(str::AbstractString) = :(apropos($str))

repl(other) = nothing

function _repl(x)
docs = :(@doc $(esc(x)))
try
# Handles function call syntax where each argument is a symbol.
isexpr(x, :call) && (docs = Base.gen_call_with_extracted_types(doc, x))
end
if isfield(x)
quote
if isa($(esc(x.args[1])), DataType)
fielddoc($(esc(x.args[1])), $(esc(x.args[2])))
else
$((isa(ex,Symbol) || isfield(ex) || isexpr(ex,:macrocall)) ? :(@doc ($(esc(ex)))) : Base.gen_call_with_extracted_types(doc, ex))
$docs
end
end
else
docs
end
end

Expand Down

0 comments on commit 26a4df7

Please sign in to comment.