lor*_*hog 6 visual-studio-code vscode-debugger
In a project there are a number of helper utilities. In the launch and tasks json files they are configured to allow the user to select the particular utility to build or debug. What I would like to do is have the selection from launch to be passed to the tasks and the task use that selection. The launch.json configuration file looks like:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug: <Utility App>",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/apps/${input:utility}/${input:utility}",
"args": ["--notimeout", "--pit"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/apps/${input:utility}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "make utility",
},
"inputs": [
{
"type": "pickString",
"id": "utility",
"description": "Which utility app do you want to run?",
"options": [
"utility_1",
"utility_2",
"utility_3",
"utility_4",
]
},
]
}
Run Code Online (Sandbox Code Playgroud)
The tasks.json configuration file looks like:
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make utility",
"type": "process",
"command": "make",
"args": [ "${input:BuildUtility}" ],
"group": "build",
"problemMatcher": "$gcc"
},
],
"inputs": [
{
"type": "pickString",
"id": "BuildUtility",
"description": "Which utility do you want to build?",
"options": [
"utility_1",
"utility_2",
"utility_3",
"utility_4",
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
How would I pass the selection made from launch via preLaunchTask so the task uses that selection, effectively overriding "${input:BuildUtility}"
so the user wouldn't be promoted to make a selection for the "args"
field? Bonus would be having the tasks still ask for a selection if nothing was passed to it? Thanks.
小智 0
Visual Studio 代码现在通过新的输入类型支持这一点pickString
。
pickString
:显示“快速选择”下拉列表,让用户从多个选项中进行选择。
以下是如何创建选择输入的示例:
{
"inputs": [
{
"type": "pickString",
"id": "myString",
"description": "Pick an option:",
"options": [
"foo",
"bar",
"baz"
],
"default": "foo"
}
]
}
Run Code Online (Sandbox Code Playgroud)