如何让vscode不等待完成preLaunchTask?
我在Visual Studio代码中运行一个可以执行我的JS文件(使用duktape)的外部二进制文件的调试设置。调试适配器当前仅支持附加请求(不启动),所以我必须在调试JS脚本之前运行二进制文件。如何让vscode不等待完成preLaunchTask?
为了避免启动应用程序手动我创建了一个任务,并设置在我launch.json文件:
{
"version": "0.2.0",
"configurations": [{
"name": "Attach MGA",
"type": "duk",
"preLaunchTask": "debug mga",
"request": "attach",
"address": "localhost",
"port": 9091,
"localRoot": "${workspaceRoot}",
"stopOnEntry": false,
"debugLog": true
}]
}
的任务是定义这样:
{
"version": "0.1.0",
"command": "<absolute path to>/mga",
"isShellCommand": false,
"showOutput": "always",
"suppressTaskName": true,
"tasks": [{
"taskName": "debug mga",
"args": ["--debugger", "main.json"]
}]
}
现在的问题是,当应用程序等待调试器连接时,vscode会等待预启动任务完成。 Catch 22.
如何避免vscode等待预启动任务完成?
更新:
同时我已经the vscode task page念起来完成这个任务的配置上来。不过,它不适合我
{
"version": "2.0.0",
"tasks": [
{
"label": "launch-mga",
"type": "shell",
"command": "<absolute path to>/mga",
"args": [
"config/main.json",
"--debugger"
],
"isBackground": true,
"problemMatcher": {
"owner": "custom",
"pattern": {
"regexp": "_____"
},
"background": {
"activeOnStart": true,
"beginsPattern": "^.*Waiting for debug connection.*$",
"endsPattern": "^.*blah.*$"
},
},
}
]
}
启动的应用程序打印工作等待消息,然后等待无休止的调试连接。也许这个问题与用C++编写的应用程序(这有点类似于终端应用程序的Node.js)有关?
如何试图通过增加使其后台作业: "isBackground": true
背景/看任务
有些工具在后台支持运行一边看文件系统的更改,然后触发动作当文件在磁盘上更改时。通过Gulp
这样的功能通过npm模块gulp-watch提供。 TypeScript编译器tsc
通过--watch command
行选项内置了对此的支持。
为了提供在VS代码中激活后台任务并生成问题结果的反馈,问题匹配器必须使用附加信息来检测输出中的这些变化。我们以tsc
编译器为例。当编译器在观看模式启动,它打印到控制台以下附加信息:
> tsc --watch
12:30:36 PM - Compilation complete. Watching for file changes.
当它包含一个问题磁盘上的文件的变化,会出现以下的输出:
12:32:35 PM - File change detected. Starting incremental compilation...
src/messages.ts(276,9): error TS2304: Cannot find name 'candidate'.
12:32:35 PM - Compilation complete. Watching for file changes.
展望在输出处显示以下模式:
- 编译器在
File change detected. Starting incremental compilation...
打印到控制台时运行。 - 编译器在
Compilation complete. Watching for file changes.
打印到控制台时停止。 - 在这两个字符串之间会报告问题。
- 编译器也在初始启动时运行一次(不向控制台打印
File change detected. Starting incremental compilation...
)。
要捕获此信息,问题匹配器可以提供background
属性。
对于tsc
编译器,一个合适的background
属性看起来是这样的:
"background": {
"activeOnStart": true,
"beginsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - File change detected\\. Starting incremental compilation\\.\\.\\.",
"endsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - Compilation complete\\. Watching for file changes\\."
}
除了对问题匹配的background
性质,任务本身具有作为isBackground
以便任务继续运行被标记在背景中。
全手工制作的手表模式下运行的tsc
任务tasks.json
看起来是这样的:
{
"version": "2.0.0",
"tasks": [
{
"label": "watch",
"command": "tsc",
"args": ["--watch"],
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"fileLocation": "relative",
"pattern": {
"regexp": "^([^\\s].*)\\((\\d+|\\,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
},
"background": {
"activeOnStart": true,
"beginsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - File change detected\\. Starting incremental compilation\\.\\.\\.",
"endsPattern": "^\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}(?: AM| PM)? - Compilation complete\\. Watching for file changes\\."
}
}
}
]
}
PS:从https://code.visualstudio.com/docs/editor/tasks采取内容
编辑-1
的任务需要作为守护进程启动,然后只有isBackground
会帮助。所以你会有类似的东西
"isShellCommand": true,
"command": "<absolute path to>/mga --config xyz abc &",
不幸的是,'isBackground'没有帮助。 vscode仍在等待预启动任务完成。 –
@MikeLischke,请检查编辑,看看它是否有帮助 –
Stil没有运气。在更改为您在编辑中推荐的内容后,我只会收到错误消息:'无法启动外部程序/mga --debugger config/main.json&。 spawn /mga --debugger config/main.json&ENOENT'。很奇怪。 –
这没有帮助。 vscode仍在等待预启动任务完成。 –