Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ function signatures_at(filename::AbstractString, line::Integer)
spath = splitpath(rpath)
libname = spath[1]
project = Base.active_project()
id = PkgId(Base.project_deps_get(project, libname), libname)
id = project_deps_get(project, libname)
if id === nothing
id = PkgId(id, libname)
end
return signatures_at(id, joinpath(spath[2:end]...), line)
end
if startswith(filename, "REPL[")
Expand Down
26 changes: 25 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# An optimization to reduce the amount of time spent re-parsing Manifest.toml
# Revise may invalidate this if the active manifest file changes
if isdefined(Base, :TOMLCache)
const tomlcache = Ref{Union{Nothing,Base.TOMLCache}}(nothing)
function locate_package(id::PkgId)
cache = tomlcache[]
if cache === nothing
cache = tomlcache[] = Base.TOMLCache()
end
return Base.locate_package(id, cache)
end
function project_deps_get(env::String, name::String)
cache = tomlcache[]
if cache === nothing
cache = tomlcache[] = Base.TOMLCache()
end
return Base.project_deps_get(env, name, cache)
end
else
const tomlcache = Ref(nothing)
locate_package(id::PkgId) = Base.locate_package(id)
project_deps_get(env::String, name::String) = Base.project_deps_get(env, name)
end

function checkname(fdef::Expr, name)
fproto = fdef.args[1]
fdef.head === :where && return checkname(fproto, name)
Expand Down Expand Up @@ -86,7 +110,7 @@ end

function basepath(id::PkgId)
id.name ∈ ("Main", "Base", "Core") && return ""
loc = Base.locate_package(id)
loc = locate_package(id)
loc === nothing && return ""
return dirname(dirname(loc))
end
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ end
@test !isempty(sigs)
ex = @code_expr(gcd(10, 20))
@test ex isa Expr
@test occursin(String(m.file), String(ex.args[2].args[2].args[1].file))
lnn = ex.args[2].args[2]
lnn = isa(lnn, LineNumberNode) ? lnn : lnn.args[1]
@test occursin(String(m.file), String(lnn.file))
@test ex == code_expr(gcd, Tuple{Int,Int})

m = first(methods(edit))
Expand Down