I am using Visual Studio Code to edit and test python. I typically open the entire folder in Code and I have multiple python files in the folder. When I have a particular Python file open in the editor and I hit F5 to start debugging, I would like default arguments passed to the program I am debugging vary depending on which file I am debugging. E.g. one set of arguments for p1.py and a different set of arguments for p2.py, but without having to switch debugging configurations. Is that possible? It seems related to How to set multiple launch.json or different arguments in same project folder at Visual Studio Code? but not quite what I am looking for. I also looked at https://code.visualstudio.com/docs/editor/debugging#_launch-configurations and if I am reading it right, I am out of luck. (I could create two configurations, one for p1.py and another for p2.py, but I would have to manually switch between those configurations when I switch between those files in the editor.)
1 Answer
With extension Command Variable you can select arguments based on the file path.
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"args" : ["${input:arg1}","${input:arg2}"],
"console": "integratedTerminal"
}
],
"inputs": [
{
"id": "arg1",
"type": "command",
"command": "extension.commandvariable.file.fileAsKey",
"args": {
"/p1.py": "foobar",
"/p2.py": "blabla"
}
},
{
"id": "arg1",
"type": "command",
"command": "extension.commandvariable.file.fileAsKey",
"args": {
"/p1.py": "tralala",
"/p2.py": ""
}
}
]