@@ -175,9 +175,10 @@ function signatures_at(id::PkgId, relpath::AbstractString, line::Integer)
175175end
176176
177177"""
178- src = definition(method::Method, String)
178+ src, line1 = definition(method::Method, String)
179179
180- Return a string with the code that defines `method`.
180+ Return a string with the code that defines `method`. Also return the first line of the
181+ definition, including the signature.
181182
182183Note this may not be terribly useful for methods that are defined inside `@eval` statements;
183184see [`definition(method::Method, Expr)`](@ref) instead.
@@ -194,15 +195,17 @@ function definition(method::Method, ::Type{String})
194195 end
195196 ex, iend = Meta. parse(src, istart)
196197 if isfuncexpr(ex)
197- return src[istart+ 1 : iend- 1 ]
198+ return src[istart+ 1 : iend- 1 ], line
198199 end
199200 # The function declaration was presumably on a previous line
200201 lineindex = lastindex(linestarts)
201- while ! isfuncexpr(ex)
202+ while ! isfuncexpr(ex) && lineindex > 0
202203 istart = linestarts[lineindex]
203204 ex, iend = Meta. parse(src, istart)
205+ lineindex -= 1
206+ line -= 1
204207 end
205- return src[istart: iend- 1 ]
208+ return src[istart: iend- 1 ], line
206209end
207210
208211"""
0 commit comments