将输入字符串映射到 launch.json 文件中的数值

Map input string to numeric value in launch.json file

我有以下 launch.json 文件:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Service1",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "127.0.0.1",
                "port": "${input:envType}"
            },
            ... 
        },
        ...
    ],
    "inputs": [
        {
            "type": "pickString",
            "id": "envType",
            "description": "Which env do you want to debug?",
            "options": [
              "development",
              "staging",
              "live",
            ],
            "default": "development"
          },
    ]

我想要实现的是:将特定环境映射到端口。 例如,我希望如果用户 select “开发”环境,将在端口字段内打印的值为 5000。

这可能吗?

您可以使用扩展 Command Variable v1.18.0

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Service1",
      "type": "python",
      "request": "attach",
      "connect": {
        "host": "127.0.0.1",
        "port": "${input:envType}"
      }
    }
  ],
  "inputs": [
    {
      "id": "envType",
      "type": "command",
      "command": "extension.commandvariable.pickStringRemember",
      "args": {
        "description": "Which env do you want to debug?",
        "options": [
          ["development", "5000"],
          ["staging", "5100"],
          ["live", "5200"]
        ],
        "default": "5000"
      }
    }
  ]
}