Skip to content

Commit 4b6ef46

Browse files
authored
Merge pull request #19 from timholy/teh/missing
Allow marking of methods as missing
2 parents 00aad59 + 14cb3f3 commit 4b6ef46

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/CodeTracking.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ include("utils.jl")
1414

1515
# These values get populated by Revise
1616

17-
const method_info = IdDict{Type,Tuple{LineNumberNode,Expr}}()
17+
const method_info = IdDict{Type,Union{Missing,Tuple{LineNumberNode,Expr}}}()
1818

1919
const _pkgfiles = Dict{PkgId,PkgFiles}()
2020

@@ -41,7 +41,7 @@ function whereis(method::Method)
4141
end
4242
end
4343
end
44-
if lin === nothing
44+
if lin === nothing || ismissing(lin)
4545
file, line = String(method.file), method.line
4646
else
4747
file, line = fileline(lin[1])
@@ -189,7 +189,7 @@ function definition(method::Method, ::Type{Expr})
189189
end
190190
end
191191
end
192-
return def === nothing ? nothing : copy(def[2])
192+
return def === nothing || ismissing(def) ? nothing : copy(def[2])
193193
end
194194

195195
definition(method::Method) = definition(method, Expr)

test/runtests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Note: some of CodeTracking's functionality can only be tested by Revise
22

33
using CodeTracking
4-
using Test
4+
using Test, InteractiveUtils
55
# Note: ColorTypes needs to be installed, but note the intentional absence of `using ColorTypes`
66

77
include("script.jl")
@@ -45,6 +45,12 @@ include("script.jl")
4545
@test pkgfiles("ColorTypes") === nothing
4646
@test_throws ErrorException pkgfiles("NotAPkg")
4747

48+
# Test a method marked as missing
49+
m = @which sum(1:5)
50+
CodeTracking.method_info[m.sig] = missing
51+
@test whereis(m) == (CodeTracking.maybe_fix_path(String(m.file)), m.line)
52+
@test definition(m) === nothing
53+
4854
# Test that definitions at the REPL work with `whereis`
4955
ex = Base.parse_input_line("replfunc(x) = 1"; filename="REPL[1]")
5056
eval(ex)

0 commit comments

Comments
 (0)