Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ function whereis(method::Method)
if lin === nothing
f = method_lookup_callback[]
if f !== nothing
Base.invokelatest(f, method)
try
Base.invokelatest(f, method)
lin = get(method_info, method.sig, nothing)
catch
Copy link
Contributor

Choose a reason for hiding this comment

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

Should log at least something here

end
end
lin = get(method_info, method.sig, nothing)
end
if lin === nothing
file, line = String(method.file), method.line
Expand Down Expand Up @@ -115,12 +118,15 @@ end
function signatures_at(id::PkgId, relpath::AbstractString, line::Integer)
expressions = expressions_callback[]
expressions === nothing && error("cannot look up methods by line number, try `using Revise` before loading other packages")
for (mod, exsigs) in Base.invokelatest(expressions, id, relpath)
for (ex, sigs) in exsigs
lr = linerange(ex)
lr === nothing && continue
line ∈ lr && return sigs
try
for (mod, exsigs) in Base.invokelatest(expressions, id, relpath)
for (ex, sigs) in exsigs
lr = linerange(ex)
lr === nothing && continue
line ∈ lr && return sigs
end
end
catch
end
return nothing
end
Expand Down Expand Up @@ -167,9 +173,12 @@ function definition(method::Method, ::Type{Expr})
if def === nothing
f = method_lookup_callback[]
if f !== nothing
Base.invokelatest(f, method)
try
Base.invokelatest(f, method)
def = get(method_info, method.sig, nothing)
catch
end
end
def = get(method_info, method.sig, nothing)
end
return def === nothing ? nothing : copy(def[2])
end
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ include("script.jl")
eval(ex)
m = first(methods(replfunc))
@test whereis(m) == ("REPL[1]", 1)

# Test with broken lookup
CodeTracking.method_lookup_callback[] = m -> error("oops")
@test whereis(m) == ("REPL[1]", 1)
end