Visual studio code 如何使vscode不等待完成预启动任务?
我在VisualStudio代码中有一个调试设置,在这里我运行一个外部二进制文件,它可以执行我的JS文件(使用duktape)。调试适配器目前只支持附加请求(不支持启动),因此我必须先运行二进制文件,然后才能调试JS脚本 为了避免手动启动应用程序,我为其创建了一个任务,并在launch.json文件中设置:Visual studio code 如何使vscode不等待完成预启动任务?,visual-studio-code,vscode-tasks,vscode-debugger,Visual Studio Code,Vscode Tasks,Vscode Debugger,我在VisualStudio代码中有一个调试设置,在这里我运行一个外部二进制文件,它可以执行我的JS文件(使用duktape)。调试适配器目前只支持附加请求(不支持启动),因此我必须先运行二进制文件,然后才能调试JS脚本 为了避免手动启动应用程序,我为其创建了一个任务,并在launch.json文件中设置: { “版本”:“0.2.0”, “配置”:[{ “名称”:“附上MGA”, “类型”:“duk”, “预启动任务”:“调试mga”, “请求”:“附上”, “地址”:“本地主机”, “港口”
{
“版本”:“0.2.0”,
“配置”:[{
“名称”:“附上MGA”,
“类型”:“duk”,
“预启动任务”:“调试mga”,
“请求”:“附上”,
“地址”:“本地主机”,
“港口”:9091,
“localRoot”:“${workspaceRoot}”,
“stopOnEntry”:false,
“调试日志”:true
}]
}
任务的定义如下:
{
“版本”:“0.1.0”,
“command”:“并提出了此任务配置。但是,它对我不起作用
{
“版本”:“2.0.0”,
“任务”:[
{
“标签”:“启动mga”,
“类型”:“外壳”,
“命令”:“/mga”,
“args”:[
“config/main.json”,
“--调试器”
],
“isBackground”:正确,
“问题匹配者”:{
“所有者”:“自定义”,
“模式”:{
“regexp”:“\uuuuuuuuuuuuuuuuuuu”
},
“背景”:{
“activeOnStart”:正确,
“beginsPattern”:“^.*正在等待调试连接。*$”,
“endsPattern”:“^.*诸如此类。*$”
},
},
}
]
}
启动的应用程序打印等待消息,然后无限期地等待调试连接。可能问题与应用程序(这是一个类似于JSP的终端应用程序),用C++编写,
< P>强>后台/监视任务<强> > /P>
一些工具支持在后台运行,同时监视文件系统的更改,然后在磁盘上的文件更改时触发操作。使用Gulp
这种功能是通过npm模块Gulp watch提供的。TypeScript编译器tsc
通过--watch命令
li内置了对此的支持ne选项
为了提供后台任务在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.
查看输出显示以下模式:
- 当检测到
文件更改时,编译器将运行。开始增量编译…
将打印到控制台
编译完成后,编译器停止。监视文件更改。
打印到控制台
- 报告了这两个字符串之间的问题
- 编译器也会在初始启动后运行(未检测到打印
文件更改。正在启动增量编译…
到控制台)
要捕获此信息,问题匹配者可以提供背景属性
对于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\\."
}
{
"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\\."
}
}
}
]
}
除了问题匹配器上的background
属性外,任务本身必须标记为isBackground
,以便任务在后台继续运行
在监视模式下运行的tsc
任务的完整手工tasks.json
如下所示:
"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\\."
}
{
"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:内容取自
编辑-1
任务需要作为守护进程启动,然后只有isBackground
会有帮助
"isShellCommand": true,
"command": "<absolute path to>/mga --config xyz abc &",
“isShellCommand”:true,
“命令”:“/mga--config xyz abc&”,
这对我很有效
注:所有这些都是必需的,尽管没有一项是重要的:
problemMatcher.pattern.regexp
problemMatcher.pattern.file
problemMatcher.pattern.location
problemMatcher.pattern.message
problemMatcher.background.activeOnStart
problemMatcher.background.beginsPattern
problemMatcher.background.endsPattern
不幸的是,isBackground
没有帮助。vscode仍在等待启动前任务完成。@MikeLischke,请检查编辑是否有帮助,直到运气不佳。更改为您在编辑中建议的内容后,我只收到错误消息:无法启动外部程序/mga--debugger config/main.json&.spawn/mga--debugger config/main.json&enoint
。非常奇怪。你在使用哪个操作系统?我在macOS上。但是,我需要一个在Linux、Windows和macOS上工作的解决方案。这是真的!你必须指定模式内容,尽管这并不重要。这确实有效,我很惊讶。不知道为什么我没有早些时候尝试这个解决方案。我完全不知道抱歉,这对Angular非常有效,虽然chrome启动太早,但热模块重新加载可确保在“ng服务”就绪时自动刷新页面