14

I want to do something similar to whats outlined in this documentation for selecting a process, except I want to just be able to input any string:

{
    "name": "Attach to Process",
    "type": "node",
    "request": "attach",
    "processId": "${command:PickProcess}",
    "port": 9229
}

Is there a command that I can use to get any user input? Ideally I could do something like this:

{
  "name": "Launch Chrome Debug",
  "type": "chrome",
  "request": "launch",
  "url": "http://localhost:8080/?id=${command:UserInput}",
  "webRoot": "${workspaceRoot}",
}

That way I could specify the "id" param when I launch the debugger.

1 Answer 1

27

v1.30 has added this functionality: input variables during tasks and debug.

For user input variables, we introduced a new variable category input, which results in this syntax: ${input:variableName}. This simple syntax is not sufficient to present meaningful UI to the end user, so we've introduced a new inputs section in launch.json and tasks.json, where additional configuration attributes are specified.

input example

Here is the list of supported attributes:

id - The corresponding variable name for which these attributes are used.

type - The type of user input widget. In this release, promptString (for a string InputBox) and pickString (for a string Quick Pick) are supported.

description - Descriptive text shown to the user.

default - The default value to use if the user just presses Enter.

A first example shows how to use a user input variable in a task configuration (tasks.json):

{
    "tasks": [
        {
            "label": "Echo input",
            "type": "shell",
            "command": "echo ${input:echoPrompt}"
        }
    ],
    "inputs": [
        {
            "id": "echoPrompt",
            "description": "Please enter a value",
            "default": "default echo text",
            "type": "promptString"
        }
    ]
}

Another example shows a user input variable for selecting between two options in a debug configuration (launch.json):

{
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/${input:pickProgram}"
        }
    ],
    "inputs": [
        {
            "id": "pickProgram",
            "description": "Select client or server",
            "type": "pickString",
            "options": ["client.js", "server.js"],
            "default": "client.js"
        }
    ]
}

We plan to combine user input variables with the existing command-based variables so that user input variables can be contributed by extensions.

Sign up to request clarification or add additional context in comments.

2 Comments

This is great! Thanks for making me aware
this is great. For the second config, I wonder if there is some way to run a task that would save the last input (when using promptString) and then update the input default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.