Maybe, instead of trying to debug the code of include
-d files, it would be worth to think why this is wanted, and if a different work flow might be a convenient way of achieving the same goal. I have encountered myself in that situation, and this is my analysis of that personal use case:
I had two kinds of files included in my code: (a) files with auxiliary functions, and (b) scripts where I calculated things in a series of steps, and kept all results as globals because later I wanted to look back into intermediate results.
The “function libraries” were no issue: I had no need to debug them at “include
time”; maybe I wanted to add breakpoints and debug the functions when I called them later on, but there is no problem with that.
Now, the problem came with the scripts. But why was I executing them with include
in the middle of a Julia session? Why the command of “Debug File in New Process” available in the VS Code extension was not good for me? There might be different reasons:
-
The instructions written in the script were a recipe for an analysis that might be done with different inputs. I created those inputs interactively in the REPL (e.g. reading from files), stored them in variables with fixed names, and then just include
d the script to run the analysis – which expected those variables with those names. After that, again in the REPL I inspected final and intermediate results, plotted this and that, etc. Running the file that I wanted to debug was just a step in between an interactive session, so this could not be done in a separate new process.
-
Related to the previous reason: there might be a stage where the interactive toying with inputs and outputs was not needed anymore, I was always doing the same, so everything could be written in a script. But when dealing with multiple repetitions of the analysis (with different inputs), I still wanted to look closely into the process for each input. Run it with data A – ok, everything fine; let’s go with data B – oh, that’s not right, I’ll repeat it in debug mode in order to see what’s happening. This might be done with “Debug File in New Process”, but having to start it in a new process may be slow and annoying.
-
Different steps of the analysis were written in different scripts, and nested with include
in the main script.
For #1 and #2, I realised that what I really wanted to do (run the whole script in a single step) was as easy and fast with the interactive tools of VS Code as by typing include("script.jl")
. And those tools also allowed me to stop in a given line without breakpoints, e.g. starting a new code cell right before the target code block, and running the file by code cells (Alt + Shift) – well, except if I wanted to stop right in the middle of a loop or another code block.
What I really missed is some kind of shortcut that does the same as “Send Current Line or Selection to REPL” (Ctrl + Enter), but prepended by @run
or @enter
, to start debugging the target line without having to copy-paste it manually in the REPL.
For #3, well, I had no solution. So I have accustomed myself to avoid that pattern of nesting include
s in scripts. Looking into it with another perspective, I think that this has also helped me to write cleaner code, e.g. replacing such things by functions when suitable.