@@ -8,6 +8,10 @@ using InteractiveUtils
88
99export whereis, definition, pkgfiles, signatures_at
1010
11+ # More recent Julia versions assign the line number to the line with the function declaration,
12+ # not the first non-comment line of the body.
13+ const line_is_decl = VERSION >= v" 1.5.0-DEV.567"
14+
1115include(" pkgfiles.jl" )
1216include(" utils.jl" )
1317
@@ -44,8 +48,9 @@ const juliastdlib = joinpath("julia", "stdlib", "v$(VERSION.major).$(VERSION.min
4448"""
4549 filepath, line = whereis(method::Method)
4650
47- Return the file and line of the definition of `method`. `line`
48- is the first line of the method's body.
51+ Return the file and line of the definition of `method`. The meaning of `line`
52+ depends on the Julia version: on Julia 1.5 and higher it is the line number of
53+ the method declaration, otherwise it is the first line of the method's body.
4954"""
5055function whereis(method:: Method )
5156 file, line = String(method. file), method. line
111116 sigs = signatures_at(filename, line)
112117
113118Return the signatures of all methods whose definition spans the specified location.
114- `line` must correspond to a line in the method body (not the signature or final `end`).
119+ Prior to Julia 1.5, `line` must correspond to a line in the method body
120+ (not the signature or final `end`).
115121
116122Returns `nothing` if there are no methods at that location.
117123"""
@@ -193,6 +199,7 @@ function definition(::Type{String}, method::Method)
193199 file, line = whereis(method)
194200 line == 0 && return nothing
195201 src = src_from_file_or_REPL(file)
202+ src = replace(src, " \r " => " " )
196203 eol = isequal(' \n ' )
197204 linestarts = Int[]
198205 istart = 1
0 commit comments