Search code examples
visual-studio-codeconfigremote-debugging

Map input string to numeric value in launch.json file


I have the following launch.json file:

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

What I'm trying to achieve is: map a specific environment to a port. For example, I want that if a user select "development" environment, the value that will be printed inside the port field is 5000.

Is this possible?


Solution

  • You can use the extension 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"
          }
        }
      ]
    }