diff --git a/.travis.yml b/.travis.yml index 99c2021..570b1b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,11 @@ language: julia os: - linux - osx + - windows julia: - 1.0 - - 1.1 + - 1 - nightly branches: diff --git a/Project.toml b/Project.toml index 6b9a6d2..d03459d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CodeTracking" uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" authors = ["Tim Holy "] -version = "0.5.8" +version = "0.5.9" [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index c4db1d9..8ee3299 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -8,6 +8,10 @@ using InteractiveUtils export whereis, definition, pkgfiles, signatures_at +# More recent Julia versions assign the line number to the line with the function declaration, +# not the first non-comment line of the body. +const line_is_decl = VERSION >= v"1.5.0-DEV.567" + include("pkgfiles.jl") include("utils.jl") @@ -44,8 +48,9 @@ const juliastdlib = joinpath("julia", "stdlib", "v$(VERSION.major).$(VERSION.min """ filepath, line = whereis(method::Method) -Return the file and line of the definition of `method`. `line` -is the first line of the method's body. +Return the file and line of the definition of `method`. The meaning of `line` +depends on the Julia version: on Julia 1.5 and higher it is the line number of +the method declaration, otherwise it is the first line of the method's body. """ function whereis(method::Method) file, line = String(method.file), method.line @@ -111,7 +116,8 @@ end sigs = signatures_at(filename, line) Return the signatures of all methods whose definition spans the specified location. -`line` must correspond to a line in the method body (not the signature or final `end`). +Prior to Julia 1.5, `line` must correspond to a line in the method body +(not the signature or final `end`). Returns `nothing` if there are no methods at that location. """ @@ -193,6 +199,7 @@ function definition(::Type{String}, method::Method) file, line = whereis(method) line == 0 && return nothing src = src_from_file_or_REPL(file) + src = replace(src, "\r"=>"") eol = isequal('\n') linestarts = Int[] istart = 1 diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..7fd1ad9 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,4 @@ +[deps] +ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index a396232..c8f9bc6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,6 +4,8 @@ using CodeTracking using Test, InteractiveUtils # Note: ColorTypes needs to be installed, but note the intentional absence of `using ColorTypes` +using CodeTracking: line_is_decl + isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl") @testset "CodeTracking.jl" begin @@ -11,7 +13,7 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl") file, line = whereis(m) scriptpath = normpath(joinpath(@__DIR__, "script.jl")) @test file == scriptpath - @test line == 4 + @test line == (line_is_decl ? 2 : 4) trace = try call_throws() catch