sve*_*ven 8 visual-studio-code
我正在尝试创建一个启动配置,其中环境变量由 shell 脚本动态确定。尽管命令变量可以通过 启动任务workbench.action.tasks.runTask,但似乎无法指定要运行的任务。在这方面,输入变量似乎更灵活一些,但我似乎无法让它发挥作用。这是我得到的:
启动.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"XXX": "${input:foo}"
},
"args": []
}
],
"inputs": [
{
"type": "command",
"id": "foo",
"command": "workbench.action.tasks.runTask",
"args": {
"args": "bar",
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
任务.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "bar",
"type": "shell",
"command": "find /dev -name 'myspecialdevice*' -maxdepth 1"
}
]
}
Run Code Online (Sandbox Code Playgroud)
问题是仍然会询问用户要运行哪个任务。我inputs.args对launch.json的部分最不安全。我真的不知道键值应该是什么。也许实现有助于解决这个问题?
这个答案实际上与使用 vscode 任务无关,但您的介绍句子提供了动机/要解决的问题。
我遇到了同样的问题,想知道vscode 的输入类型:command。它提供了一种嵌入(自定义)vscode 命令的方法——这看起来像是一种在此处嵌入(自定义)扩展的强大机制。但我没有找到一个简单地执行 shell 脚本并将其返回标准输出的内置命令。因此,恕我直言,需要一个捕获 shell 命令输出的扩展来实现这一目的。
例如https://marketplace.visualstudio.com/items?itemName=augustocdias.tasks-shell-inputshellCommand.execute提供了一个完全执行此操作的
命令。
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"XXX": "${input:foo}"
},
"args": []
}
],
"inputs": [
{
"id": "foo",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "find /dev -name 'myspecialdevice*' -maxdepth 1",
"cwd": "${workspaceFolder}",
/* To prevent user from selecting output (if there is just
one line printed by command), un-comment next line */
//"useSingleResult": true
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
(灵感来自/sf/answers/4125152251/)
在你的中launch.json,尝试替换
"args": {
"args": "bar",
}
Run Code Online (Sandbox Code Playgroud)
和
"args": "bar"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1454 次 |
| 最近记录: |