Skip to content

Commit

Permalink
mention methodtable Ctrl+Q trick in methodshow (#35556)
Browse files Browse the repository at this point in the history
Co-authored-by: Takafumi Arakaki <[email protected]>
Co-authored-by: Jameson Nash <[email protected]>
  • Loading branch information
3 people authored Jun 14, 2020
1 parent 446618d commit 13b07fc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
13 changes: 6 additions & 7 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,10 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
end
end

# Contains file name and file number. Gets set when a backtrace
# or methodlist is shown. Used by the REPL to make it possible to open
# the location of a stackframe/method in the editor.
global LAST_SHOWN_LINE_INFOS = Tuple{String, Int}[]

function show_trace_entry(io, frame, n; prefix = "")
push!(LAST_SHOWN_LINE_INFOS, (string(frame.file), frame.line))
if haskey(io, :LAST_SHOWN_LINE_INFOS)
push!(io[:LAST_SHOWN_LINE_INFOS], (string(frame.file), frame.line))
end
print(io, "\n", prefix)
show(io, frame, full_path=true)
n > 1 && print(io, " (repeats ", n, " times)")
Expand Down Expand Up @@ -631,7 +628,9 @@ function show_reduced_backtrace(io::IO, t::Vector, with_prefix::Bool)
end

function show_backtrace(io::IO, t::Vector)
resize!(LAST_SHOWN_LINE_INFOS, 0)
if haskey(io, :LAST_SHOWN_LINE_INFOS)
resize!(io[:LAST_SHOWN_LINE_INFOS], 0)
end
filtered = process_backtrace(t)
isempty(filtered) && return

Expand Down
2 changes: 2 additions & 0 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
end
n = rest = 0
local last
LAST_SHOWN_LINE_INFOS = get(io, :LAST_SHOWN_LINE_INFOS, Tuple{String,Int}[])

resize!(LAST_SHOWN_LINE_INFOS, 0)
for meth in ms
Expand Down Expand Up @@ -373,6 +374,7 @@ show(io::IO, mime::MIME"text/html", mt::Core.MethodTable) = show(io, mime, Metho

# pretty-printing of AbstractVector{Method}
function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method})
LAST_SHOWN_LINE_INFOS = get(io, :LAST_SHOWN_LINE_INFOS, Tuple{String,Int}[])
resize!(LAST_SHOWN_LINE_INFOS, 0)
first = true
for (i, m) in enumerate(mt)
Expand Down
21 changes: 18 additions & 3 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,22 @@ function display(d::REPLDisplay, mime::MIME"text/plain", x)
io = foldl(IOContext, d.repl.options.iocontext,
init=IOContext(io, :limit => true, :module => Main))
end

infos = Tuple{String,Int}[]
io = IOContext(io, :LAST_SHOWN_LINE_INFOS => infos)

show(io, mime, x)
println(io)

if !isempty(infos)
d.repl.last_shown_line_infos = infos
println(
io,
"\nTo edit a specific method, type the corresponding number into the " *
"REPL and press Ctrl+Q",
)
end

nothing
end
display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x)
Expand Down Expand Up @@ -430,11 +444,12 @@ mutable struct LineEditREPL <: AbstractREPL
specialdisplay::Union{Nothing,AbstractDisplay}
options::Options
mistate::Union{MIState,Nothing}
last_shown_line_infos::Vector{Tuple{String,Int}}
interface::ModalInterface
backendref::REPLBackendRef
LineEditREPL(t,hascolor,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,in_help,envcolors) =
new(t,hascolor,prompt_color,input_color,answer_color,shell_color,help_color,history_file,in_shell,
in_help,envcolors,false,nothing, Options(), nothing)
in_help,envcolors,false,nothing, Options(), nothing, Tuple{String,Int}[])
end
outstream(r::LineEditREPL) = r.t
specialdisplay(r::LineEditREPL) = r.specialdisplay
Expand Down Expand Up @@ -1092,10 +1107,10 @@ function setup_interface(
end,

# Open the editor at the location of a stackframe or method
# This is accessing a global variable that gets set in
# This is accessing a contextual variable that gets set in
# the show_backtrace and show_method_table functions.
"^Q" => (s, o...) -> begin
linfos = Base.LAST_SHOWN_LINE_INFOS
linfos = repl.last_shown_line_infos
str = String(take!(LineEdit.buffer(s)))
n = tryparse(Int, str)
n === nothing && @goto writeback
Expand Down

3 comments on commit 13b07fc

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.