如何在VSCode中定义launch.json中的全局变量?

How to define a global variable in launch.json in VSCode?

在VSCode的lauch.json文件中,我使用了多种配置来调试不同的文件。其中一些变量在配置之间是通用的。 我想知道是否可以在 launch.json 中定义一个全局变量并在文件的不同位置使用它?

例如,我正在寻找一种方法来定义 variable_common 一次并在 config 1config 2 中使用它:

    "configurations": [
        {
            "name": "Python: config 1",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": ["variable_1", "variable_2", "variable_common"]
        },

        {
            "name": "Python: config 2",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": ["variable_3", "variable_4", "variable_common"]
        }
]

使用扩展程序 Command Variable 您可以创建自定义变量

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: config 1",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "justMyCode": true,
      "args": ["variable_1", "variable_2", "${input:VAR_COMMON}"]
    },
    {
      "name": "Python: config 2",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "justMyCode": true,
      "args": ["variable_3", "variable_4", "${input:VAR_COMMON}"]
    }
  ],
  "inputs": [
    {
      "id": "VAR_COMMON",
      "type": "command",
      "command": "extension.commandvariable.transform",
      "args": { "text": "common_arg" }
    }
  ]
}