Skip to content

Commit 6d65809

Browse files
committed
signatures_at support for Base and stdlibs
1 parent 38ab597 commit 6d65809

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/CodeTracking.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const method_lookup_callback = Ref{Any}(nothing)
3535
# a list of method-signatures defined by that expression.
3636
const expressions_callback = Ref{Any}(nothing)
3737

38+
const juliabase = joinpath("julia", "base")
39+
const juliastdlib = joinpath("julia", "stdlib", "v$(VERSION.major).$(VERSION.minor)")
3840

3941
### Public API
4042

@@ -112,6 +114,18 @@ Return the signatures of all methods whose definition spans the specified locati
112114
Returns `nothing` if there are no methods at that location.
113115
"""
114116
function signatures_at(filename::AbstractString, line::Integer)
117+
if occursin(juliabase, filename)
118+
rpath = postpath(filename, juliabase)
119+
id = PkgId(Base)
120+
return signatures_at(id, rpath, line)
121+
elseif occursin(juliastdlib, filename)
122+
rpath = postpath(filename, juliastdlib)
123+
spath = splitpath(rpath)
124+
libname = spath[1]
125+
project = Base.active_project()
126+
id = PkgId(Base.project_deps_get(project, libname), libname)
127+
return signatures_at(id, joinpath(spath[2:end]...), line)
128+
end
115129
for (id, pkgfls) in _pkgfiles
116130
if startswith(filename, basedir(pkgfls)) || id.name == "Main"
117131
bdir = basedir(pkgfls)

src/utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,11 @@ function maybe_fixup_stdlib_path(path)
8181
end
8282
return path
8383
end
84+
85+
function postpath(filename, pre)
86+
idx = findfirst(pre, filename)
87+
idx === nothing && error(pre, " not found in ", filename)
88+
post = filename[first(idx) + length(pre) : end]
89+
post[1:1] == Base.Filesystem.path_separator && return post[2:end]
90+
return post
91+
end

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,17 @@ include("script.jl")
7575
file, line = whereis(lin, m)
7676
@test endswith(file, String(lin.file))
7777
end
78+
79+
@testset "With Revise" begin
80+
if isdefined(Main, :Revise)
81+
m = @which gcd(10, 20)
82+
sigs = signatures_at(Base.find_source_file(String(m.file)), m.line)
83+
@test !isempty(sigs)
84+
85+
m = first(methods(edit))
86+
sigs = signatures_at(String(m.file), m.line)
87+
@test !isempty(sigs)
88+
sigs = signatures_at(Base.find_source_file(String(m.file)), m.line)
89+
@test !isempty(sigs)
90+
end
91+
end

0 commit comments

Comments
 (0)