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
43 changes: 0 additions & 43 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ function definition(::Type{String}, method::Method)
end
ex, iend = Meta.parse(src, istart)
iend = prevind(src, iend)
if isfuncexpr(ex)
if isfuncexpr(ex, method.name)
iend = min(iend, lastindex(src))
return strip(src[istart:iend], '\n'), line
end
# The function declaration was presumably on a previous line
lineindex = lastindex(linestarts)
while !isfuncexpr(ex) && lineindex > 0
while !isfuncexpr(ex, method.name) && lineindex > 0
istart = linestarts[lineindex]
try
ex, iend = Meta.parse(src, istart)
Expand Down
10 changes: 7 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
function isfuncexpr(ex)
function isfuncexpr(ex, name=nothing)
checkname(fdef::Expr, name) = checkname(fdef.args[1], name)
checkname(fname::Symbol, name::Symbol) = fname == name
checkname(fname::Symbol, ::Nothing) = true

# Strip any macros that wrap the method definition
while isexpr(ex, :macrocall) && length(ex.args) == 3
ex = ex.args[3]
end
isa(ex, Expr) || return false
ex.head == :function && return true
ex.head == :function && return checkname(ex, name)
if ex.head == :(=)
a = ex.args[1]
if isa(a, Expr)
while a.head == :where
a = a.args[1]
isa(a, Expr) || return false
end
a.head == :call && return true
a.head == :call && return checkname(a, name)
end
end
return false
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
@test startswith(src, "@inline")
@test line == 16

m = first(methods(f50))
src, line = definition(String, m)
@test occursin("100x", src)
@test line == 22

info = CodeTracking.PkgFiles(Base.PkgId(CodeTracking))
@test Base.PkgId(info) === info.id
@test CodeTracking.basedir(info) == dirname(@__DIR__)
Expand Down
5 changes: 5 additions & 0 deletions test/script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ f2(x, y) = x + y
z = x + 1
return z
end

function f50() # issue #50
todB(x) = 10*log10(x)
println("100x is $(todB(100)) dB.")
end