Reputation: 5823
Trying to avoid the XY problem, my problem at the very high level: I work in a VS Code workspace with R and Python code files, and I often need to debug one or the other. Currently I have different debug launch configurations saved, and I need to switch between them manually - that is a pain. I would like to use F5 to
.py
file.R
fileI see many technical ways of doing that, but all have their roadblocks (some of which may just poor documentation):
"compound"
launch configuration, starting both R and Python launch configurations, and stopping all but one. This can be done using a "prelaunchTask"
for each, but non-zero return codes create error message that I don't like."when": "editorLangId == 'python'"
), but which command for debugging to start and how to pass the launch configuration? There is vscode.startDebug
which takes arguments (https://github.com/microsoft/vscode/issues/4615), but I cannot keybind to that. And then there is workbench.action.debug.start
which seems to ignore arguments. And then there is vscode.commands.executeCommand
to which I cannot keybind, either.Upvotes: 0
Views: 235
Reputation: 5823
After much fiddling, here is one solution following idea 2:
settings.json
(launch configs could be put into launch.json
):
{
"debug.onTaskErrors": "abort",
"launch": {
"compounds": [
{
"name": "Python/R: Current File",
"configurations": [
"Python: Current File",
"R: Current File",
],
},
],
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"preLaunchTask": "check_ext py",
"request": "launch",
// ...
},
{
"name": "R: Current File",
"type": "R-Debugger",
"preLaunchTask": "check_ext R",
"request": "launch",
// ...
}
],
},
}
tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"label": "check_ext py",
"type": "shell",
"command": "echo ${fileExtname} | grep -i ^.py$",
},
{
"label": "check_ext R",
"type": "shell",
"command": "echo ${fileExtname} | grep -i '^.R$'",
},
],
}
Upvotes: 0