如何使vscode不等待完成preLaunchTask?

Mik*_*hke 17 visual-studio-code vscode-tasks vscode-debugger

我在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
    }]
}
Run Code Online (Sandbox Code Playgroud)

任务定义如下:

{
    "version": "0.1.0",
    "command": "<absolute path to>/mga",
    "isShellCommand": false,
    "showOutput": "always",
    "suppressTaskName": true,
    "tasks": [{
        "taskName": "debug mga",
        "args": ["--debugger", "main.json"]
    }]
}
Run Code Online (Sandbox Code Playgroud)

现在问题是vscode等待预启动任务完成,而应用程序等待调试器附加.赶上22.

如何避免vscode等待预启动任务完成?

更新:

与此同时,我已经阅读了vscode任务页面,并提出了此任务配置.不过,它对我不起作用

{
    "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.*$"
                },
            },
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

启动的应用程序打印等待消息,然后无休止地等待调试连接.也许这个问题与用C++编写的应用程序(有点像Node.js的终端应用程序)有关?

mik*_*att 8

这对我有用。

请注意,所有这些都是必需的,即使它们都不重要:

  • 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": ".",
          }
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

  • 这是真的!您必须指定模式内容,即使它并不重要。乌尔格 (2认同)
  • 最近这种情况有改变吗?我觉得这_曾经_起作用,但对我来说只持续了一天,现在不起作用......我在 /sf/ask/4791278901/ 上发布了我自己的问题,但因为你是我的这里的基线我想我应该发表评论:-) (2认同)
  • 今天的 VSCode 更新似乎再次打破了这一点。 (2认同)
  • 又坏了,以前还好好的 (2认同)

Tar*_*ani 6

后台/观看任务

一些工具支持在后台运行,同时监视文件系统的更改,然后在磁盘上的文件更改时触发操作。有了Gulp这样的功能是通过NPM模块一饮而尽手表提供。TypeScript编译器tsc通过--watch commandline选项内置了对此的支持。

为了提供反馈,表明VS Code中有后台任务处于活动状态并产生问题结果,问题匹配者必须使用其他信息来检测state输出中的这些更改。让我们以tsc编译器为例。在监视模式下启动编译器时,它将以下附加信息打印到控制台:

> tsc --watch
12:30:36 PM - Compilation complete. Watching for file changes.
Run Code Online (Sandbox Code Playgroud)

当磁盘上的文件更改包含问题时,将显示以下输出:

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.
Run Code Online (Sandbox Code Playgroud)

查看输出显示以下模式:

  • 编译器在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\\."
}
Run Code Online (Sandbox Code Playgroud)

除了background问题匹配器上的属性之外,还必须将任务本身标记为,isBackground以便任务在后台继续运行。

tasks.jsontsc在监视模式下运行的任务手工制作的完整外观如下所示:

{
    "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\\."
                }
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

PS:内容取自https://code.visualstudio.com/docs/editor/tasks

编辑1

该任务需要作为守护程序启动,然后才有isBackground帮助。所以你会有类似的东西

"isShellCommand": true,
"command": "<absolute path to>/mga --config xyz abc &",
Run Code Online (Sandbox Code Playgroud)