如何让 vscode 不等待完成 preLaunchTask?
How to make vscode not wait for finishing a preLaunchTask?
我在 Visual Studio 代码中有一个调试设置,其中我 运行 一个可以执行我的 JS 文件的外部二进制文件(使用 duktape)。调试适配器目前只支持附加请求(不启动)所以我必须 运行 二进制文件才能调试 JS 脚本。
为了避免必须手动启动应用程序,我为其创建了一个任务并将其设置在我的 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 等待预启动任务完成,而应用程序等待调试器附加。赶上 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 像终端应用程序)有关?
后台/看任务
有些工具支持 运行 在后台监视文件系统的变化,然后在磁盘上的文件发生变化时触发操作。在 Gulp
中,此类功能是通过 npm 模块 gulp-watch 提供的。 TypeScript 编译器 tsc
通过 --watch command
行选项内置了对此的支持。
为了提供后台任务在 VS Code 中处于活动状态并产生问题结果的反馈,问题匹配器必须使用其他信息来检测输出中的这些 state
变化。我们以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 &",
这对我有用。
请注意所有这些都是必需的,即使 none 很重要:
problemMatcher.pattern.regexp
problemMatcher.pattern.file
problemMatcher.pattern.location
problemMatcher.pattern.message
problemMatcher.background.activeOnStart
problemMatcher.background.beginsPattern
problemMatcher.background.endsPattern
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build-extras",
"type": "shell",
"isBackground": true,
"command": "./script/build-extras",
// This task is run before some debug tasks.
// Problem is, it's a watch script, and since it never exits, VSCode
// complains. All this is needed so VSCode just lets it run.
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
}
]
}
我在 Visual Studio 代码中有一个调试设置,其中我 运行 一个可以执行我的 JS 文件的外部二进制文件(使用 duktape)。调试适配器目前只支持附加请求(不启动)所以我必须 运行 二进制文件才能调试 JS 脚本。
为了避免必须手动启动应用程序,我为其创建了一个任务并将其设置在我的 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 等待预启动任务完成,而应用程序等待调试器附加。赶上 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 像终端应用程序)有关?
后台/看任务
有些工具支持 运行 在后台监视文件系统的变化,然后在磁盘上的文件发生变化时触发操作。在 Gulp
中,此类功能是通过 npm 模块 gulp-watch 提供的。 TypeScript 编译器 tsc
通过 --watch command
行选项内置了对此的支持。
为了提供后台任务在 VS Code 中处于活动状态并产生问题结果的反馈,问题匹配器必须使用其他信息来检测输出中的这些 state
变化。我们以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 &",
这对我有用。
请注意所有这些都是必需的,即使 none 很重要:
problemMatcher.pattern.regexp
problemMatcher.pattern.file
problemMatcher.pattern.location
problemMatcher.pattern.message
problemMatcher.background.activeOnStart
problemMatcher.background.beginsPattern
problemMatcher.background.endsPattern
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build-extras",
"type": "shell",
"isBackground": true,
"command": "./script/build-extras",
// This task is run before some debug tasks.
// Problem is, it's a watch script, and since it never exits, VSCode
// complains. All this is needed so VSCode just lets it run.
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
}
]
}