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
2 changes: 1 addition & 1 deletion src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ 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 = getpkgid(project, libname)
return signatures_at(id, joinpath(spath[2:end]...), line)
end
if startswith(filename, "REPL[")
Expand Down
35 changes: 35 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function checkname(fdef::Expr, name)
fproto = fdef.args[1]
fdef.head === :where && return checkname(fproto, name)
fdef.head === :call || return false
if fproto isa Expr
# A metaprogramming-generated function
fproto.head === :$ && return true # uncheckable, let's assume all is well
# Is the check below redundant?
fproto.head === :. || return false
# E.g. `function Mod.bar.foo(a, b)`
Expand Down Expand Up @@ -137,3 +140,35 @@ function postpath(filename, pre)
post[1:1] == Base.Filesystem.path_separator && return post[2:end]
return post
end

if Base.VERSION < v"1.1"
function splitpath(p::String)
# splitpath became available with Julia 1.1
# Implementation copied from Base except doesn't handle the drive
out = String[]
isempty(p) && (pushfirst!(out,p)) # "" means the current directory.
while !isempty(p)
dir, base = _splitdir_nodrive(p)
dir == p && (pushfirst!(out, dir); break) # Reached root node.
if !isempty(base) # Skip trailing '/' in basename
pushfirst!(out, base)
end
p = dir
end
return out
end
splitpath(p::AbstractString) = splitpath(String(p))

_splitdir_nodrive(path::String) = _splitdir_nodrive("", path)
function _splitdir_nodrive(a::String, b::String)
m = match(Base.Filesystem.path_dir_splitter,b)
m === nothing && return (a,b)
a = string(a, isempty(m.captures[1]) ? m.captures[2][1] : m.captures[1])
a, String(m.captures[3])
end
end

# Robust across Julia versions
getpkgid(project::AbstractString, libname) = getpkgid(Base.project_deps_get(project, libname), libname)
getpkgid(id::PkgId, libname) = id
getpkgid(uuid::UUID, libname) = PkgId(uuid, libname)
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
# Ensure that we don't error on difficult cases
m = which(+, (AbstractSparseVector, AbstractSparseVector)) # defined inside an `@eval`
d = definition(String, m)
@test d === nothing || isa(d[1], String)
@test d === nothing || isa(d[1], AbstractString)

# Check for existence of file
id = Base.PkgId("__PackagePrecompilationStatementModule") # not all Julia versions have this
Expand All @@ -149,7 +149,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))
body = ex.args[2]
idx = findfirst(x -> isa(x, LineNumberNode), body.args)
@test occursin(String(m.file), String(body.args[idx].file))
@test ex == code_expr(gcd, Tuple{Int,Int})

m = first(methods(edit))
Expand Down