用于启动配置的vscode键盘快捷键

tru*_*ru7 7 visual-studio-code vscode-settings

在vscode中,我有一个具有多个配置的launch.json.

有没有办法为特定配置分配键盘快捷键?,我无法找到任何信息,谢谢!

Ste*_*t_R 7

Almost, but not quite.

To my knowledge there is no vs-code command to start debugging a given launch configuration.

What you can do instead is point a keyboard shortcut at the workbench.action.debug.selectandstart command which will pop-up a dialogue for you to select the configuration and hit enter. In practice this can be done very quickly as you only need to start typing the first letter or two of your launch config or use the arrows

屏幕抓图

为了使这个命中Ctrl+ kCtrl+ s(至少这是Windows默认的快捷方式,你总是可以在命令面板中搜索“按键绑定”如果这并不为你工作)。

搜索workbench.action.debug.selectandstart命令,然后右键单击或单击编辑图标以更改键绑定:

screengrab2


Mar*_*ark 7

更新:我刚刚创建了一个扩展Launch Configs,它允许您为launch.json. 如果您愿意,可以为不同的启动配置设置多个键绑定。示例设置:

 "launches": {

  "RunNodeCurrentFile": "Launch File",
  "RunCompound1": "Launch file and start chrome"
},
Run Code Online (Sandbox Code Playgroud)

因此,通过扩展,您可以将值设置为name所需的 launch.json 配置以运行/调试。然后通过键绑定来触发这些配置。

{
  "key": "alt+f",
  "command": "launches.RunNodeCurrentFile"
},
{
  "key": "alt+g",
  "command": "launches.RunCompound1"
}
Run Code Online (Sandbox Code Playgroud)

https://github.com/microsoft/vscode/issues/97921查看我的回答

此键绑定有效:

{
  "key": "alt+j",                            // whatever keybinding you like
  "command": "debug.startFromConfig",
  "args": {
      "type": "node",
      "request": "launch",
      "name": "First Debugger",
      "program": "${workspaceFolder}/test.js",
      "console": "integratedTerminal",
      //"preLaunchTask": "echo Builtin Variables"  // can't get it to find a pre-launch task
  }
}
Run Code Online (Sandbox Code Playgroud)

但不幸的是,不是简单地引用 launch.json 中的现有配置 -name例如。引用的配置 - 这里First Debugger可以,但不必在您的 launch.json 中。在任何情况下,所有的都args必须出现在您的键绑定中。

在这一点上,我无法成功找到preLaunchTask键绑定中列出的内容 - 尽管它存在,但它总是无法找到它,并且错误弹出窗口可以直接将您带到那里!?

我将根据对此答案顶部列出的问题的任何回应将其作为一个问题提出。警告:启动配置的其他部分目前可能无法通过键绑定工作。测试它们。