vscode keyboard shortcut for launch configuration

后端 未结 2 1678
不思量自难忘°
不思量自难忘° 2021-01-04 01:35

In vscode, I have a launch.json with more than one configuration.

Is there a way to assign a keyboard shortcut to a specific configuration?, I\'ve not been able to f

2条回答
  •  迷失自我
    2021-01-04 02:27

    Update: I just created an extension Launch Configs which allows you to set up a keybinding for any launch configuration in your launch.json. Multiple keybindings for different launch configs if you wish. Example settings:

     "launches": {
    
      "RunNodeCurrentFile": "Launch File",
      "RunCompound1": "Launch file and start chrome"
    },
    

    So with the extension you can set the value to the name of your desired launch.json configuration to run/debug. And then keybindings to trigger those configurations.

    {
      "key": "alt+f",
      "command": "launches.RunNodeCurrentFile"
    },
    {
      "key": "alt+g",
      "command": "launches.RunCompound1"
    }
    

    See my answer at https://github.com/microsoft/vscode/issues/97921

    This keybinding works:

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

    but unfortunately not by simply referring to an existing config in your launch.json - by name for example. The referred config - here First Debugger can, but doesn't have to be in your launch.json. In any case all the args must appear in your keybinding.

    At this point I can't get it to successfully find the preLaunchTask listed in the keybinding - it always fails to find it although it exists and the error popup can take you directly there!?

    I'll raise that as an issue depending on any response at the issue listed at the top of this answer. Caveat: there may be other parts of a launch config that don't currently work from a keybinding. Test them.

提交回复
热议问题