Skip to content

Commit

Permalink
Merge pull request #20309 from MichaelHatherly/mh/helpmode-fix
Browse files Browse the repository at this point in the history
Fix helpmode for method lookups
  • Loading branch information
ararslan authored Jan 30, 2017
2 parents 8759262 + 0878726 commit 8cc647b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
16 changes: 13 additions & 3 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,21 @@ end
# =================

"""
getdoc(x::T, sig) -> String
getdoc(obj)
getdoc(obj, sig)
Return the dynamic docstring associated with object `x`, or `nothing` to use
the binding's documentation.
Return a custom docstring object associated with the object `obj` and, optionally, the tuple
type signature `sig`. See `MultiDoc` docs for an explanation of the possible values of `sig`.
The returned object can either be a markdown object generated by `Markdown.parse` or some
other custom type used to display non-markdown formatted documentation.
A return value of `nothing` can be used to signify to the docsystem that no documentation
was found for `obj`, in which case the docsystem will fall back to searching for the
`Binding` associated with `obj` instead.
"""
function getdoc end

getdoc(x, sig) = getdoc(x)
getdoc(x) = nothing

Expand Down
6 changes: 4 additions & 2 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ repl(io::IO, other) = :(@doc $(esc(other)))
repl(x) = repl(STDOUT, x)

function _repl(x)
docs = (isexpr(x, :call) && !any(isexpr(x, :(::)) for x in x.args)) ?
Base.gen_call_with_extracted_types(doc, x) : :(@doc $(esc(x)))
if (isexpr(x, :call) && !any(isexpr(x, :(::)) for x in x.args))
x.args[2:end] = [:(::typeof($arg)) for arg in x.args[2:end]]
end
docs = :(@doc $(esc(x)))
if isfield(x)
quote
if isa($(esc(x.args[1])), DataType)
Expand Down
10 changes: 7 additions & 3 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,13 @@ type DynamicDocType
x
end

Base.Docs.getdoc(d::DynamicDocType) = Base.Markdown.parse(d.x)
Base.Docs.getdoc(d::DynamicDocType, sig) = "$(d.x) $(sig)"

dynamic_test = DynamicDocType("test 1")
@test docstrings_equal(@doc(dynamic_test), doc"test 1")
@test @doc(dynamic_test) == "test 1 Union{}"
dynamic_test.x = "test 2"
@test docstrings_equal(@doc(dynamic_test), doc"test 2")
@test @doc(dynamic_test) == "test 2 Union{}"
@test @doc(dynamic_test(::String)) == "test 2 Tuple{String}"

@test Docs._repl(:(dynamic_test(1.0))) == :(@doc $(Expr(:escape, :(dynamic_test(::typeof(1.0))))))
@test Docs._repl(:(dynamic_test(::String))) == :(@doc $(Expr(:escape, :(dynamic_test(::String)))))

0 comments on commit 8cc647b

Please sign in to comment.