Search code examples
vscode-debuggervscode-tasks

How can I reuse configuration parts VS Code launch configurations?


I have a launch.json file in my project like this.

And I set up multiple configurations to run a nodejs script for building and deploying my app which works fine.

The problem is that there could be a lot of configurations while the name and args properties are the only difference, but I need to repeat all other codes.

What can I do to reuse a configuration?

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Deploy Dev",
      "program": "${workspaceFolder}/.vscode/deploy.js",
      "args": ["arg1ForDev", "arg2ForDev", "arg3ForDev", "arg4ForDev"],
      "cwd": "${workspaceFolder}",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Deploy Test",
      "program": "${workspaceFolder}/.vscode/deploy.js",
      "args": ["arg1ForTest", "arg2ForTest", "arg3ForTest", "arg4ForTest"],
      "cwd": "${workspaceFolder}",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    },
    // ...more configurations below
  ]
}

I asked GPT, searched on github issues and vscode documentation, still didn't find a solution.


Solution

  • As far as I know, at the time of this writing, this is not possible in vanilla VS Code. But there's a feature-request issue ticket for it: Shared properties in launch.json #53557. It requests either a way to specify a property's default value, or do extension/inheritance with configurations. It's currently closed as "out of scope", but you can still give it a thumbs up to show support for it. Please avoid making noisy comments there like ones that just consist of "+1" / bump" / "me too". Instead, if you want to say something, provide some constructive input to the design discussion after first reading through the existing discussion and voting on it.

    Note: For readers who are instead interested in having a global launch config that is shared across workspaces, see Is it possible to have a global launch.json file?.

    By the way, for your reference / learning purposes, I found that issue ticket by googling "github vscode issues launch configuration inheritance".