[英]How can I start debugging R or Python code using the same key in Visual Studio Code?
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.试图避免 XY 问题,我的问题处于非常高的级别:我在 VS Code 工作区中使用 R 和 Python 代码文件工作,我经常需要调试其中一个。 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我想用 F5 来
.py
file当编辑器在.py
文件中处于活动状态时,启动 Python 调试器.R
file当编辑器在.R
文件中处于活动状态时,启动 R 调试器I 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.使用"compound"
启动配置,启动 R 和 Python 启动配置,并停止除一个之外的所有启动配置。 This can be done using a "prelaunchTask"
for each, but non-zero return codes create error message that I don't like.这可以使用每个"prelaunchTask"
来完成,但非零返回码会创建我不喜欢的错误消息。"when": "editorLangId == 'python'"
), but which command for debugging to start and how to pass the launch configuration?使用与编辑器相关的键映射( "when": "editorLangId == 'python'"
),但是要启动哪个调试命令以及如何传递启动配置? There is vscode.startDebug
which takes arguments ( https://github.com/microsoft/vscode/issues/4615 ), but I cannot keybind to that.有vscode.startDebug
需要 arguments ( https://github.com/microsoft/vscode/issues/4615 ),但我不能绑定到那个。 And then there is workbench.action.debug.start
which seems to ignore arguments.然后是workbench.action.debug.start
似乎忽略了 arguments。 And then there is vscode.commands.executeCommand
to which I cannot keybind, either.然后是vscode.commands.executeCommand
,我也无法对其进行键绑定。After much fiddling, here is one solution following idea 2:经过一番摆弄,这是遵循想法 2 的一种解决方案:
settings.json
(launch configs could be put into launch.json
): settings.json
(启动配置可以放入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
: 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$'",
},
],
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.