Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode: command for user input in debug launch config

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.

like image 998
NSjonas Avatar asked Jan 28 '23 20:01

NSjonas


1 Answers

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.

like image 52
Mark Avatar answered Mar 22 '23 23:03

Mark