我在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的终端应用程序)有关?
答案 0 :(得分:5)
背景/观看任务
某些工具支持在后台运行,同时观察文件系统的更改,然后在磁盘上更改文件时触发操作。使用Gulp
这样的功能是通过npm模块gulp-watch提供的。 TypeScript编译器tsc
通过--watch command
行选项内置了对此的支持。
为了提供后台任务在VS代码中处于活动状态并产生问题结果的反馈,问题匹配器必须使用其他信息来检测输出中的这些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
,以便任务在后台继续运行。
在观察模式下运行的tasks.json
任务的完整手工tsc
如下所示:
{
"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 &",
答案 1 :(得分:4)
这对我有用。
请注意,尽管这些都不重要,但所有这些都是必需的:
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": ".",
}
}
]
}
]
}
答案 2 :(得分:0)
如何通过添加以下内容来尝试使其成为后台作业:
"isBackground": true