Check if current file is "main" when debugging

In Julia documentation, it is said that to determine that a file is run as the main script, one can check if abspath(PROGRAM_FILE) == @__FILE__ is true. When directly running the file, this works fine. However, when debugging in VS Code using the Julia extension, the value of PROGRAM_FILE changes to /Users/my_user_name/.vscode/extensions/julialang.language-julia-1.5.8/scripts/debugger/run_debugger.jl, i.e. the path to the debugger.

So my question is: how to check if the current file is “main” when debugging (in VS Code)?

Further information:

  • OS: macOS Monterey 12.0.1 (21A559)
  • VS Code: version 1.62.3 (Commit ccbaa2d27e38e5afa3e5c21c1c7bef4657064247)
  • Julia installation: version 1.7.1
  • Julia extension: version 1.5.8
1 Like

Seems like checking that run_debugger.jl file could maybe give some clues, cause that file will likely need to know what file should be run. I’m on the phone so haven’t looked at it, but would be where I start.
Maybe something that the vscode plug-in could fix by injecting the file you want run into whatever the @FILE uses in the background.

Probably best to fix this in the extension: