Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

visual studio code - How to make vscode not wait for finishing a preLaunchTask?

I have a debug setup in Visual Studio code where I run an external binary which can execute my JS files (using duktape). The debug adapter currently only supports attach requests (not launch) so I have to run the binary before I can debug the JS scripts.

In order to avoid having to start the application manually I created a task for it and set that in my launch.json file:

{
    "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
    }]
}

The task is defined so:

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

The problem is now that vscode waits for the pre launch task to finish, while the application waits for a debugger to attach. Catch 22.

How can I avoid that vscode waits for the pre launch task to finish?

Update:

Meanwhile I have read up on the vscode task page and came up with this task configuration. Still, it doesn't work for me

{
    "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.*$"
                },
            },
        }
    ]
}

The launched application prints the wait message and then waits endlessly for a debug connection. Maybe the problem has to do with the application (which is kinda Node.js like terminal app), written in C++?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This worked for me.

Note all these are required, even though none are important:

  • 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": ".",
          }
        }
      ]
    }
  ]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...