根据文件扩展名在VS代码中定义多个启动配置



我有一个简单的项目,其中包含JS和PY文件。

在我的launch.json中,我想根据文件类型定义启动配置,这样JS将与Node一起运行,而PY将与Python一起运行。

launch.json中有这样的配置吗?

您可以使用扩展命令变量v1.6.2。

您可以使用文件路径为特定调试器选择替换项。

如果使用包含Python调试器和节点调试器的复合启动,并在扩展名与调试器不匹配时将文件替换为伪文件,则该调试器只是启动和结束。

在workspaceRoot/.vscode文件夹中创建一个名为dummy的空文件。

launch.json设置为

{
"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"
}
}
]
}

如果使用Linux/MacOS,请调整目录分隔符。

最新更新