San*_*mar 3 visual-studio-code vscode-tasks vscode-debugger
我有一个launch.json如下所示的调试启动配置 ( )。
{
"version": "0.2.0",
"configurations": [
{
"name": "Current TS File",
"type": "node",
"request": "launch",
"preLaunchTask": "Pre Debug Task",
"postDebugTask": "Stop Watch Styles",
"args": ["${relativeFile}"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector",
}
]
}
Run Code Online (Sandbox Code Playgroud)
我的任务配置(tasks.json)就像
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "next:copy",
"label": "Copy Files",
"problemMatcher": []
},
{
"type": "npm",
"script": "styles:tsw",
"label": "Watch Styles",
"problemMatcher": [],
},
{
"label": "Pre Debug Task",
"isBackground": true,
"dependsOn" :[
"Copy Files",
"Watch Styles"
]
},
{
"label": "Stop Watch Styles",
// No sure what should come here
}
]
}
Run Code Online (Sandbox Code Playgroud)
尝试在 中停止监视进程postDebugTask,是否可以通过Watch Styles在 tasks.json 中提供名称 ( ) 作为参数来终止任务。观察样式是一个持续运行的过程,请建议在调试完成后是否有其他方法终止任务。
这将在调试停止后终止所有任务
或者在这种情况下,只是build_runner watch......
启动文件
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"preLaunchTask": "flutter: build_runner watch",
"postDebugTask": "Terminate All Tasks"
}
]
}
Run Code Online (Sandbox Code Playgroud)
任务文件
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Terminate All Tasks",
"command": "echo ${input:terminate}",
"type": "shell",
"problemMatcher": []
}
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "terminateAll"
}
]
}
Run Code Online (Sandbox Code Playgroud)
更多信息:https : //code.visualstudio.com/docs/editor/variables-reference#_command-variables
这对我有用:
{
"label": "postdebugKill",
"type": "process",
"command":[
"${command:workbench.action.tasks.terminate}",
"${command:workbench.action.acceptSelectedQuickOpenItem}",
],
},
Run Code Online (Sandbox Code Playgroud)
第一个"${command:workbench.action.tasks.terminate}"将弹出一个面板,要求您选择要终止的任务。因此,如果您有多个正在运行的任务并且想要选择一个,则只需使用此命令。
第二个"${command:workbench.action.acceptSelectedQuickOpenItem}"将终止上述面板中选定的任务。(因此您甚至不会看到终止面板。)如果您只有一个正在运行的任务,那么当您调用该postdebugKill任务时,它将被自动选择并因此终止。否则,首先列出的任务将被终止。同样,如果您有多个其他任务正在运行并且您想要选择终止哪个任务,请不要包含第二个命令。
我不知道有什么方法可以列出,也许可以通过一个args选项来列出运行时要终止的任务的标签名称。如果有这个功能就好了。
[postdebugKill名字可以是任何你想要的。]
要调用调试后任务,您的 launch.json 配置可能如下所示:
{
"type": "node",
"request": "launch",
"name": "Gulp: serve",
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
"args": [
"serve"
],
// "preLaunchTask": "someTask",
"postDebugTask": "postdebugKill"
},
Run Code Online (Sandbox Code Playgroud)
停止该"Gulp: serve"调试会话后,"postdebugKill"将触发该任务。因此,如果我使用了"preLaunchTask"启动任务或只是在启动"Gulp: serve"调试会话之前启动了任务运行,那么该任务preLaunchTask就会被终止。
vscode 最近添加了在任务中运行 vscode 命令的功能。这里有一些最小的信息:使用任务文档中的命令。
| 归档时间: |
|
| 查看次数: |
4012 次 |
| 最近记录: |