ManuelHentschel / VSCode-R-Debugger

R Debugger Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=RDebugger.r-debugger
MIT License
170 stars 11 forks source link

F5 does not save file before debugging a file again (debugMode file, allowGlobalDebugging true) #137

Open bersbersbers opened 3 years ago

bersbersbers commented 3 years ago

Describe the bug I use the default "debug.saveBeforeStart": "allEditorsInActiveGroup" VS Code setting to have files saved when starting debugging. I have the impression that this does not work for my launch config (see #136) due to

    "debugMode": "file",
    "allowGlobalDebugging": true,

In fact, the first debug run (I use F5 for that) saves the file, but all subsequent ones don't. I see why that may not be happening - because the debugger stays open from the perspective of VS Code, and debugging an R file again is see as "Debug: Continue", which does not usually trigger saving of files. But maybe there is a way to address this.

The reason I am asking is because over Remote SSH (and probably locally too), formatting a large file takes a bit of time, so the file is not immediately saved upon Ctrl+S. So in many cases, by quickly typing Ctrl+S, F5, I accidently run the previously saved version of the code.

Expected behavior I'd expect files to be saved according to "debug.saveBeforeStart": "allEditorsInActiveGroup".

Desktop (please complete the following information): See #136

ManuelHentschel commented 3 years ago

Sourcing a file on F5 is a bit of an abuse of the debug protocol, so I'm not sure how to solve this properly.

The cleanest solution would be to set "allowGlobalDebugging": false, since this will launch a new debug session each time you run your script and all the default mechanics (e.g. save before start) will be done by vscode. If you want to be able to access the workspace after running your file, you could use ctrl+shift+F5 to restart the debug session. This will launch a completely new R session and should trigger vscode's mechanics as well.

To achieve the behaviour you are describing, we could implement a new command that saves the current editor and then writes .vsc.debugSource(...) to the debug console.

bersbersbers commented 3 years ago

Sourcing a file on F5 is a bit of an abuse of the debug protocol, so I'm not sure how to solve this properly.

Just to be sure: this "abuse" is what you implemented, right? Or is this something I (mis-)configured?

The cleanest solution would be to set "allowGlobalDebugging": false

Yes, this is what I have been doing. I don't actually care about the workspace after the file has finished successfully, but I thought that I could save some time restarting R every time.

It's no big deal if there's no solution to this other than documenting this limitation. But...

a new command that saves the current editor and then writes .vsc.debugSource(...) to the debug console

sounds very reasonable. I wonder if this shouldn't be the default behavior of F5 unless "debug.saveBeforeStart" is disabled.

ManuelHentschel commented 3 years ago

Just to be sure: this "abuse" is what you implemented, right? Or is this something I (mis-)configured?

Correct, my implementation is a bit of an "abuse".

I wonder if this shouldn't be the default behavior of F5 unless "debug.saveBeforeStart" is disabled.

The problem with this idea is that the communication between vscode and the debugged R session happens (almost) only through messages defined by the Debug Adapter Protocol. I.e. the debugger does not directly control what happens when the user presses F5, but only receives initialize or continue requests, depending on the situation. Therefore, the "natural" mechanism to debug a file multiple times is to launch a new debug session each time (this is also the debugger behavior for other languages like python, C).