Skip to content

Commit 652aeae

Browse files
authored
Merge pull request #6 from timholy/teh/revise
A few cleanups
2 parents cea76d4 + 373df4b commit 652aeae

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/CodeTracking.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,33 @@ using UUIDs
77
export PkgFiles
88
export whereis, definition, pkgfiles
99

10-
include("data.jl")
10+
include("pkgfiles.jl")
1111
include("utils.jl")
1212

13+
### Global storage
14+
15+
# These values get populated by Revise
16+
17+
const method_info = IdDict{Type,Tuple{LineNumberNode,Expr}}()
18+
19+
const _pkgfiles = Dict{PkgId,PkgFiles}()
20+
21+
const method_lookup_callback = Ref{Any}(nothing)
22+
23+
### Public API
24+
1325
"""
1426
filepath, line = whereis(method::Method)
1527
1628
Return the file and line of the definition of `method`. `line`
1729
is the first line of the method's body.
1830
"""
1931
function whereis(method::Method)
20-
lin = get(method_locations, method.sig, nothing)
32+
lin = get(method_info, method.sig, nothing)
2133
if lin === nothing
2234
file, line = String(method.file), method.line
2335
else
24-
file, line = fileline(lin)
36+
file, line = fileline(lin[1])
2537
end
2638
if !isabspath(file)
2739
# This is a Base or Core method
@@ -68,15 +80,15 @@ end
6880
Return an expression that defines `method`.
6981
"""
7082
function definition(method::Method, ::Type{Expr})
71-
def = get(method_definitions, method.sig, nothing)
83+
def = get(method_info, method.sig, nothing)
7284
if def === nothing
7385
f = method_lookup_callback[]
7486
if f !== nothing
7587
Base.invokelatest(f, method)
7688
end
77-
def = get(method_definitions, method.sig, nothing)
89+
def = get(method_info, method.sig, nothing)
7890
end
79-
return def === nothing ? nothing : copy(def)
91+
return def === nothing ? nothing : copy(def[2])
8092
end
8193

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

src/data.jl renamed to src/pkgfiles.jl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# The variables here get populated by Revise.jl.
2-
31
"""
42
PkgFiles encodes information about the current location of a package.
53
Fields:
@@ -28,15 +26,7 @@ basedir(info::PkgFiles) = info.basedir
2826

2927
function Base.show(io::IO, info::PkgFiles)
3028
println(io, "PkgFiles(", info.id, "):")
31-
println(io, " basedir: ", info.basedir)
29+
println(io, " basedir: \"", info.basedir, '"')
3230
print(io, " files: ")
3331
show(io, info.files)
3432
end
35-
36-
const method_locations = IdDict{Type,LineInfoNode}()
37-
38-
const method_definitions = IdDict{Type,Expr}()
39-
40-
const _pkgfiles = Dict{PkgId,PkgFiles}()
41-
42-
const method_lookup_callback = Ref{Any}(nothing)

src/utils.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ function isfuncexpr(ex)
1313
return false
1414
end
1515

16-
fileline(lin::LineInfoNode) = String(lin.file), lin.line
16+
fileline(lin::LineInfoNode) = String(lin.file), lin.line
17+
fileline(lnn::LineNumberNode) = String(lnn.file), lnn.line
18+
19+
# This is piracy, but it's not ambiguous in terms of what it should do
20+
Base.convert(::Type{LineNumberNode}, lin::LineInfoNode) = LineNumberNode(lin.line, lin.file)
1721

1822
function basepath(id::PkgId)
1923
id.name ("Main", "Base", "Core") && return ""

0 commit comments

Comments
 (0)