Skip to content

Commit

Permalink
add context module for REPL help/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Aug 30, 2019
1 parent d7428f0 commit 203abc1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ repl_search(s) = repl_search(stdout, s)

function repl_corrections(io::IO, s)
print(io, "Couldn't find ")
printstyled(io, s, '\n', color=:cyan)
pre = context_module == Main ? [] : [context_module, '.']
printstyled(io, pre..., s, '\n', color=:cyan)
print_correction(io, s)
end
repl_corrections(s) = repl_corrections(stdout, s)
Expand Down Expand Up @@ -279,7 +280,7 @@ function repl(io::IO, s::Symbol)
quote
repl_latex($io, $str)
repl_search($io, $str)
$(if !isdefined(Main, s) && !haskey(keywords, s)
$(if !isdefined(context_module, s) && !haskey(keywords, s)
:(repl_corrections($io, $str))
end)
$(_repl(s))
Expand Down Expand Up @@ -346,7 +347,8 @@ function _repl(x)
end
end
#docs = lookup_doc(x) # TODO
docs = esc(:(@doc $x))
include_str = "@doc $x"
docs = esc(:(include_string($context_module, $include_str)))
if isfield(x)
quote
if isa($(esc(x.args[1])), DataType)
Expand Down Expand Up @@ -507,7 +509,7 @@ end
print_joined_cols(args...; cols = displaysize(stdout)[2]) = print_joined_cols(stdout, args...; cols=cols)

function print_correction(io, word)
cors = levsort(word, accessible(Main))
cors = levsort(word, accessible(context_module))
pre = "Perhaps you meant "
print(io, pre)
print_joined_cols(io, cors, ", ", " or "; cols = displaysize(io)[2] - length(pre))
Expand Down Expand Up @@ -535,7 +537,7 @@ accessible(mod::Module) =
map(names, moduleusings(mod))...;
builtins] |> unique |> filtervalid

doc_completions(name) = fuzzysort(name, accessible(Main))
doc_completions(name) = fuzzysort(name, accessible(context_module))
doc_completions(name::Symbol) = doc_completions(string(name))


Expand Down

0 comments on commit 203abc1

Please sign in to comment.