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 &",