Jul*_*ian 5 customization task visual-studio-code
我试图弄清楚如何在可通过下拉列表选择的特定文件夹/文件上运行 VS Code 任务。
例子:
结构:
ws
|
+-- .env
| |
| +-- ...
|
+-- src
|
+-- dir1
| |
| +-- file 1.1
| +-- ...
| +-- file 1.n
+-- dir2
| |
| +-- file 2.1
| +-- ...
| +-- file 2.n
| +-- dir2.2
| |
| +-- file 2.2.1
| +-- ...
| +-- file 2.2.n
+-- ...
|
+-- dirn
|
+-- file n.1
+-- ...
Run Code Online (Sandbox Code Playgroud)
有办法让这项工作发挥作用吗?如果没有,是否有其他方法可以使类似的工作正常进行?感谢您的帮助。
进一步的问题:
我试图通过任务“Lint all”同时运行多个 linter。此任务取决于另外两项任务。为了避免并行执行,“Lint all”具有“dependsOrder”:“sequence”,但不知何故,下拉列表仅出现在第一个子任务中。此外,仅执行第一个子任务,然后执行停止。现在我有两个问题:
{
"version": "2.0.0",
"tasks": [
{
"label": "Lint all",
"detail": "Run all linters",
"dependsOrder": "sequence",
"dependsOn":["Cpplint", "Pylint"],
"problemMatcher": []
},
{
"label": "Cpplint",
"type": "shell",
"command": "cpplint --recursive ${input:selectDir}",
"problemMatcher": []
},
{
"label": "Pylint",
"type": "shell",
"command": "pylint ${input:selectDir}",
"problemMatcher": []
}
],
"inputs": [
{
"id": "selectDir",
"type": "command",
"command": "extension.commandvariable.pickStringRemember",
"args": {
"description": "Which directory to Lint?",
"options": [
["All", "src/"],
["Rerun task", "${remember:toRemember}"],
["Pick directory", "${pickFile:directory}"]
],
"default": null,
"pickFile": {
"directory": {
"description": "Which directory?",
"include": "src/**",
"showDirs": true,
"keyRemember":"toRemember"
}
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
您可以使用一个${input}变量
{
"version": "2.0.0",
"tasks": [
{
"label": "cpp lint",
"type": "shell",
"command": "cpplint ${input:selectDir}"
}
],
"inputs": [
{
"id": "selectDir",
"type": "pickString",
"description": "What directory to lint?",
"options": [
{"label": "All", "value": "" },
"dir1",
"dir2",
"dir3"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
编辑
使用扩展命令变量v1.35.0,您可以获得动态目录列表。
{
"version": "2.0.0",
"tasks": [
{
"label": "cpp lint",
"type": "shell",
"command": "cpplint ${input:selectDir}"
}
],
"inputs": [
{
"id": "selectDir",
"type": "command",
"command": "extension.commandvariable.pickStringRemember",
"args": {
"description": "Which directory to Lint for C++?",
"options": [
["Use previous directory", "${remember:srcSubDir}"],
["All", "all"],
["Pick directory", "${pickFile:srcSubDir}"]
],
"default": null,
"pickFile": {
"srcSubDir": {
"description": "Which directory?",
"include": "src/**/*.{cpp,h}",
"showDirs": true,
"keyRemember": "srcSubDir"
}
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果您选择一个src子目录,您将获得该目录的完整路径。我创建了一个问题来获取与工作空间相关的结果。您可以使用该extension.commandvariable.transform命令删除工作区文件夹部分。
编辑2
在命令变量 v1.35.1 中:
pickStringRemember。现在存储变量替换后的值。pickString修复了和UI的转义pickFile以中止任务。pickFile将所选文件存储在某个名称下pickString使用/记住前面的选项pickFiledefault向示例中添加属性pickString以转义 UI| 归档时间: |
|
| 查看次数: |
3740 次 |
| 最近记录: |