Updating the location of a method definition

If you control how the code is evaluated, maybe you can just use task_local_storage()[:SOURCE_PATH]? For example, see how Distributed.@everywhere pass around “current file context”:

https://github.com/JuliaLang/julia/blob/bdacfa21ef7d9657be0ff3220947ceca92a340a1/stdlib/Distributed/src/macros.jl#L205

It’s not enough to make line positions correct, though. For this, I think it’s simpler to parse the code and change the LineNumberNode yourself before eval. Or, maybe even simpler solution to add empty lines in the temp file.

1 Like