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
10 changes: 9 additions & 1 deletion src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module CodeTracking

using Base: PkgId
using Core: LineInfoNode
using Base.Meta: isexpr
using UUIDs
using InteractiveUtils

Expand Down Expand Up @@ -203,9 +204,16 @@ function definition(::Type{String}, method::Method)
end
# The function declaration was presumably on a previous line
lineindex = lastindex(linestarts)
local istart_noerr
while !isfuncexpr(ex) && lineindex > 0
istart = linestarts[lineindex]
ex, iend = Meta.parse(src, istart)
try
ex, iend = Meta.parse(src, istart)
catch
istart = istart_noerr
break
end
istart_noerr = istart
lineindex -= 1
line -= 1
end
Expand Down
5 changes: 5 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
function isfuncexpr(ex)
# Strip any macros that wrap the method definition
while isexpr(ex, :macrocall)
ex = ex.args[3]
end
isa(ex, Expr) || return false
ex.head == :function && return true
if ex.head == :(=)
a = ex.args[1]
Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
catch
stacktrace(catch_backtrace())
end
@test whereis(trace[2]) == (scriptpath, 11)
@test whereis(trace[2]) == (scriptpath, 9)
@test whereis(trace[3]) === nothing

src, line = definition(String, m)
Expand All @@ -32,6 +32,11 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl")
m = first(methods(f2))
src, line = definition(String, m)
@test src == "f2(x, y) = x + y"
@test line == 14

m = first(methods(throws))
src, line = definition(String, m)
@test startswith(src, "@noinline")
@test line == 7

info = CodeTracking.PkgFiles(Base.PkgId(CodeTracking))
Expand Down
4 changes: 2 additions & 2 deletions test/script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ function f1(x, y)
return x + y
end

f2(x, y) = x + y

@noinline function throws()
x = nothing
error("oops")
end
@inline inlined() = throws()
call_throws() = inlined()

f2(x, y) = x + y