如何解决根据文件扩展名在VS Code中定义多个启动配置
在我的launch.json
中,我想基于文件类型定义启动配置,以便JS将与Node运行,而PY将与Python运行。
launch.json中有这样的配置吗?
解决方法
您可以使用扩展名Command Variable v1.6.2。
您可以使用文件路径为特定的调试器选择替换项。
如果您使用包含Python Debugger和Node Debugger的Composite启动,并在扩展名与该调试器不匹配的情况下将文件替换为虚拟文件。
在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","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","args": {
".js": "${file}",".py": "${workspaceFolder}\\.vscode\\dummy"
}
}
]
}
如果使用Linux / MacOS,请调整目录分隔符。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。