Debugging/modifying functions stack without reloading all the code

say I have foo() calling bar() and the bug is in the second one

using Printf

function foo()
    bar()
end

function bar()
    println("bar 1")
end

I run @run foo() all good bar 1 is printed out (in real live, found bug, fixed :wink: ). Now I modify bar like this

function bar()
    println("bar 1")
    println("bar 2")
end

I press Alt+Enter on this function. and if I just call foo() in REPL, all good I see two line output. however if I call @run foo() the debugger doesn’t pick up the modified code.

Is there a way to make debugger pick up latest code same way as REPL does?
(I found that running Alt+Enter on foo makes debugger pick up latest bar. but I am looking for something more elegant. i.e. if I have 10 function deep stack it is bit impractical.)

Short answer is “no”.

The Alt+Enter is processed by VS Code and passes the contents of the file you are interested in running to Julia for processing. Typing @run foo() into Julia, VS Code has no idea that you did that, so there is no way for it to push the latest code to Julia.

I don’t know the internals of VS Code, there might be a way to detect focus switch (or something else) and force VS Code to push the latest source into Julia. However I think this might do more harm than good since anytime you move to the Julia pane there would be a delay as VS Code & Julia “sync” the code. Additionally this “feature” would most likely run afoul of projects with multiple modules and multiple source files, unless the VS Code module did a whole lot more parsing of the Julia files to know the structure of the whole application.

There’s something wrong in how VSCode interfaces with the interpreter.

using JuliaInterpreter

function foo()
    bar()
end

function bar()
    println("bar 1")
end

foo()
@interpret foo()

function bar()
    println("bar 1")
    println("bar 2")
end

foo()
@interpret foo()

works as expected, so the Debugger should too. Will look into this.

2 Likes