|
| 1 | +function body_for_method(current_file, current_line, meth) |
| 2 | + ret = JuliaInterpreter.whereis(meth) |
| 3 | + ret === nothing && return nothing |
| 4 | + deffile, _ = ret |
| 5 | + body_defline = CodeTracking.definition(String, meth) |
| 6 | + if body_defline === nothing |
| 7 | + return (nothing, 1, true) |
| 8 | + else |
| 9 | + body, defline = body_defline |
| 10 | + return (body, defline, deffile != current_file || defline > current_line) |
| 11 | + end |
| 12 | +end |
| 13 | + |
1 | 14 | function locinfo(frame::Frame)
|
2 |
| - if frame.framecode.scope isa Method |
3 |
| - meth = frame.framecode.scope |
4 |
| - ret = JuliaInterpreter.whereis(meth) |
5 |
| - ret === nothing && return nothing |
6 |
| - deffile, _ = ret |
| 15 | + scope = frame.framecode.scope |
| 16 | + if scope isa Method |
| 17 | + meth = scope |
7 | 18 | ret = JuliaInterpreter.whereis(frame)
|
8 | 19 | ret === nothing && return nothing
|
9 | 20 | current_file, current_line = ret
|
10 |
| - body_defline = CodeTracking.definition(String, meth) |
11 |
| - local body, defline |
12 |
| - unknown_start = false |
13 |
| - if body_defline === nothing |
14 |
| - unknown_start = true |
15 |
| - else |
16 |
| - body, defline = body_defline |
17 |
| - if deffile != current_file || defline > current_line |
18 |
| - unknown_start = true |
| 21 | + unknown_start = true |
| 22 | + if JuliaInterpreter.is_generated(meth) && !frame.framecode.generator |
| 23 | + # We're inside the expansion of a generated function. |
| 24 | + # There's not much point trying to query the method. |
| 25 | + # However, me heuristically make one exception: If our |
| 26 | + # src has method_for_inference_heuristics set, it is likely |
| 27 | + # a Cassette pass, so we can use the un-overdubbed method |
| 28 | + # to retrieve source. |
| 29 | + src = frame.framecode.src |
| 30 | + if isdefined(src, :method_for_inference_heuristics) |
| 31 | + (body, defline, unknown_start) = body_for_method(current_file, current_line, src.method_for_inference_heuristics) |
19 | 32 | end
|
| 33 | + else |
| 34 | + (body, defline, unknown_start) = body_for_method(current_file, current_line, meth) |
20 | 35 | end
|
21 | 36 | if unknown_start
|
22 | 37 | isfile(current_file) || return nothing
|
23 | 38 | body = read(current_file, String)
|
24 | 39 | defline = 1 # We are not sure where the context start in cases like these, could be improved?
|
25 | 40 | end
|
26 |
| - return defline, deffile, current_line, body |
| 41 | + return defline, current_file, current_line, body |
27 | 42 | else
|
28 | 43 | println("not yet implemented")
|
29 | 44 | end
|
|
0 commit comments