How to make vscode not wait for the preLaunchTask to end?

I have a debug setting in Visual Studio code where I run an external binary that can execute my JS files (using duktape). Currently, the debug adapter only supports connection requests (does not start), so I have to run the binary before I can debug JS scripts.

In order not to launch the application manually, I created a task for it and installed this 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 as follows:

 { "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 that vscode is waiting for the task to complete before running, while the application is waiting for the debugger to join. Catch 22.

How can I avoid vscode waiting for the pre-launch task to complete?

Update

In the meantime, I read the vscode task page and came up with this task configuration. However, this does not 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 running application prints a wait message and then waits endlessly for a debugging connection. Maybe the problem is with the application (which looks like Node.js, for example, a terminal application) written in C ++?

+8
visual-studio-code
source share
2 answers

Background / Watching Tasks

Some tools support running in the background while viewing the file system for changes, and then trigger the action when the file on the disk changes. With Gulp this functionality is provided through the npm gulp -watch module. The TypeScript tsc compiler supports this feature with the --watch command option.

In order to provide feedback that the background task is active in the VS code and creates the problem results, additional information must be used to determine these state changes in the output signal. Take the tsc compiler as an example. When the compiler starts in view mode, it displays the following additional information on the console:

 > tsc --watch 12:30:36 PM - Compilation complete. Watching for file changes. 

When you modify the file on the disk that contains the problem, the following output appears:

 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. 

Looking at the output, you will see the following pattern:

  • The compiler starts when File change detected. Starting incremental compilation... File change detected. Starting incremental compilation... is printed on the console.
  • The compiler stops when Compilation complete. Watching for file changes. Compilation complete. Watching for file changes. printed on the console.
  • Between these two lines problems are reported.
  • The compiler also starts after the initial start (without printing File change detected. Starting incremental compilation... on the console).

To capture this information, a match for the problems can provide the background property.

For the tsc compiler tsc corresponding background property is as follows:

 "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\\." } 

In addition to the background property, when problems coincide, the task itself must be marked as isBackground so that the task continues to run in the background.

The full manual tasks.json for the tsc task working in view mode is as follows:

 { "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: Content taken from https://code.visualstudio.com/docs/editor/tasks

Edit-1

The task should be launched as a daemon, then only isBackground will help. So you will have something like

 "isShellCommand": true, "command": "<absolute path to>/mga --config xyz abc &", 
+2
source share

How to try to make it a background by adding: "isBackground": true

0
source share

All Articles