From cd4de55cd72a7ece3a7fe83f745b28c587b0f4c8 Mon Sep 17 00:00:00 2001 From: ssikdar1 Date: Sat, 15 Feb 2020 07:25:45 -0500 Subject: [PATCH] Fix REPL help mode to show help for using/import (#34757) Fix REPL help mode to show help for using/import for :(using A)/:(import A) expressions, fixes #34713. Co-authored-by: Shan Sikdar Co-authored-by: Fredrik Ekre --- stdlib/REPL/src/docview.jl | 2 ++ stdlib/REPL/test/repl.jl | 6 ++++-- test/docs.jl | 2 -- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/REPL/src/docview.jl b/stdlib/REPL/src/docview.jl index ffbb86a1aa4a2..926ebaee2a5c4 100644 --- a/stdlib/REPL/src/docview.jl +++ b/stdlib/REPL/src/docview.jl @@ -37,6 +37,8 @@ function _helpmode(io::IO, line::AbstractString) # Docs for keywords must be treated separately since trying to parse a single # keyword such as `function` would throw a parse error due to the missing `end`. Symbol(line) + elseif isexpr(x, (:using, :import)) + x.head else # Retrieving docs for macros requires us to make a distinction between the text # `@macroname` and `@macroname()`. These both parse the same, but are used by diff --git a/stdlib/REPL/test/repl.jl b/stdlib/REPL/test/repl.jl index a2b06eaab701f..d161d18932304 100644 --- a/stdlib/REPL/test/repl.jl +++ b/stdlib/REPL/test/repl.jl @@ -1027,9 +1027,11 @@ for (line, expr) in Pair[ "while " => :while, # keyword, trailing spaces should be stripped. "0" => 0, "\"...\"" => "...", - "r\"...\"" => Expr(:macrocall, Symbol("@r_str"), LineNumberNode(1, :none), "...") + "r\"...\"" => Expr(:macrocall, Symbol("@r_str"), LineNumberNode(1, :none), "..."), + "using Foo" => :using, + "import Foo" => :import, ] - #@test REPL._helpmode(line) == Expr(:macrocall, Expr(:., Expr(:., :Base, QuoteNode(:Docs)), QuoteNode(Symbol("@repl"))), LineNumberNode(119, doc_util_path), stdout, expr) + @test REPL._helpmode(line).args[4] == expr buf = IOBuffer() @test Base.eval(REPL._helpmode(buf, line)) isa Union{Markdown.MD,Nothing} end diff --git a/test/docs.jl b/test/docs.jl index 510152f15be44..e750001c8946c 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -982,8 +982,6 @@ let x = Binding(Main, :⊕) @test Meta.parse(string(x)) == :(⊕) end -doc_util_path = Symbol(joinpath("docs", "utils.jl")) - @test sprint(repl_latex, "√") == "\"√\" can be typed by \\sqrt\n\n" @test sprint(repl_latex, "x̂₂") == "\"x̂₂\" can be typed by x\\hat\\_2\n\n"