You can use the extension Command Variable v1.6.2.
You can use the file path to select a replacement for the particular debugger.
If you use a Compound launch, containing the Python Debugger and the Node Debugger and replace the file with a dummy file if the extension does not match that debugger just starts and ends.
In the workspaceRoot/.vscode folder create an empty file called dummy
.
Setup launch.json
as
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Node File if .js",
"program": "${input:file_if_js}"
},
{
"name": "Python: Current File if .py",
"type": "python",
"request": "launch",
"program": "${input:file_if_python}",
"console": "integratedTerminal"
}
],
"compounds": [
{
"name": "Debug Python or Node",
"configurations": ["Python: Current File if .py", "Node File if .js"]
}
],
"inputs": [
{
"id": "file_if_python",
"type": "command",
"command": "extension.commandvariable.file.fileAsKey",
"args": {
".py": "${file}",
".js": "${workspaceFolder}\\.vscode\\dummy"
}
},
{
"id": "file_if_js",
"type": "command",
"command": "extension.commandvariable.file.fileAsKey",
"args": {
".js": "${file}",
".py": "${workspaceFolder}\\.vscode\\dummy"
}
}
]
}
Adjust the directory separator if you use Linux/MacOS.