@theia/task 1.45.1 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +193 -193
  2. package/lib/browser/index.d.ts +6 -6
  3. package/lib/browser/index.js +33 -33
  4. package/lib/browser/process/process-task-contribution.d.ts +6 -6
  5. package/lib/browser/process/process-task-contribution.js +43 -43
  6. package/lib/browser/process/process-task-frontend-module.d.ts +2 -2
  7. package/lib/browser/process/process-task-frontend-module.js +27 -27
  8. package/lib/browser/process/process-task-resolver.d.ts +17 -17
  9. package/lib/browser/process/process-task-resolver.js +101 -101
  10. package/lib/browser/provided-task-configurations.d.ts +43 -43
  11. package/lib/browser/provided-task-configurations.js +213 -213
  12. package/lib/browser/provided-task-configurations.spec.d.ts +1 -1
  13. package/lib/browser/provided-task-configurations.spec.js +43 -43
  14. package/lib/browser/quick-open-task.d.ts +144 -144
  15. package/lib/browser/quick-open-task.d.ts.map +1 -1
  16. package/lib/browser/quick-open-task.js +752 -748
  17. package/lib/browser/quick-open-task.js.map +1 -1
  18. package/lib/browser/task-configuration-manager.d.ts +64 -64
  19. package/lib/browser/task-configuration-manager.js +261 -261
  20. package/lib/browser/task-configuration-model.d.ts +32 -32
  21. package/lib/browser/task-configuration-model.js +79 -79
  22. package/lib/browser/task-configurations.d.ts +127 -127
  23. package/lib/browser/task-configurations.js +486 -486
  24. package/lib/browser/task-contribution.d.ts +182 -182
  25. package/lib/browser/task-contribution.js +206 -206
  26. package/lib/browser/task-definition-registry.d.ts +38 -38
  27. package/lib/browser/task-definition-registry.js +134 -134
  28. package/lib/browser/task-definition-registry.spec.d.ts +1 -1
  29. package/lib/browser/task-definition-registry.spec.js +170 -170
  30. package/lib/browser/task-frontend-contribution.d.ts +56 -56
  31. package/lib/browser/task-frontend-contribution.js +358 -358
  32. package/lib/browser/task-frontend-module.d.ts +5 -5
  33. package/lib/browser/task-frontend-module.js +79 -79
  34. package/lib/browser/task-name-resolver.d.ts +13 -13
  35. package/lib/browser/task-name-resolver.js +67 -67
  36. package/lib/browser/task-node.d.ts +9 -9
  37. package/lib/browser/task-node.js +17 -17
  38. package/lib/browser/task-preferences.d.ts +4 -4
  39. package/lib/browser/task-preferences.js +40 -40
  40. package/lib/browser/task-problem-matcher-registry.d.ts +40 -40
  41. package/lib/browser/task-problem-matcher-registry.js +309 -309
  42. package/lib/browser/task-problem-pattern-registry.d.ts +23 -23
  43. package/lib/browser/task-problem-pattern-registry.js +210 -210
  44. package/lib/browser/task-schema-updater.d.ts +58 -58
  45. package/lib/browser/task-schema-updater.js +688 -688
  46. package/lib/browser/task-service.d.ts +279 -279
  47. package/lib/browser/task-service.js +1119 -1119
  48. package/lib/browser/task-source-resolver.d.ts +9 -9
  49. package/lib/browser/task-source-resolver.js +51 -51
  50. package/lib/browser/task-templates.d.ts +13 -13
  51. package/lib/browser/task-templates.js +161 -161
  52. package/lib/browser/task-terminal-widget-manager.d.ts +44 -44
  53. package/lib/browser/task-terminal-widget-manager.js +228 -228
  54. package/lib/browser/tasks-monaco-contribution.d.ts +1 -1
  55. package/lib/browser/tasks-monaco-contribution.js +27 -27
  56. package/lib/common/index.d.ts +4 -4
  57. package/lib/common/index.js +31 -31
  58. package/lib/common/problem-matcher-protocol.d.ts +124 -124
  59. package/lib/common/problem-matcher-protocol.js +132 -132
  60. package/lib/common/process/task-protocol.d.ts +68 -68
  61. package/lib/common/process/task-protocol.js +33 -33
  62. package/lib/common/task-common-module.d.ts +7 -7
  63. package/lib/common/task-common-module.js +33 -33
  64. package/lib/common/task-protocol.d.ts +192 -192
  65. package/lib/common/task-protocol.js +137 -137
  66. package/lib/common/task-util.d.ts +22 -22
  67. package/lib/common/task-util.js +46 -46
  68. package/lib/common/task-watcher.d.ts +17 -17
  69. package/lib/common/task-watcher.js +86 -86
  70. package/lib/node/custom/custom-task-runner-backend-module.d.ts +2 -2
  71. package/lib/node/custom/custom-task-runner-backend-module.js +36 -36
  72. package/lib/node/custom/custom-task-runner-contribution.d.ts +6 -6
  73. package/lib/node/custom/custom-task-runner-contribution.js +42 -42
  74. package/lib/node/custom/custom-task-runner.d.ts +15 -15
  75. package/lib/node/custom/custom-task-runner.js +69 -69
  76. package/lib/node/custom/custom-task.d.ts +20 -20
  77. package/lib/node/custom/custom-task.js +78 -78
  78. package/lib/node/index.d.ts +3 -3
  79. package/lib/node/index.js +30 -30
  80. package/lib/node/process/process-task-runner-backend-module.d.ts +2 -2
  81. package/lib/node/process/process-task-runner-backend-module.js +36 -36
  82. package/lib/node/process/process-task-runner-contribution.d.ts +6 -6
  83. package/lib/node/process/process-task-runner-contribution.js +43 -43
  84. package/lib/node/process/process-task-runner.d.ts +60 -60
  85. package/lib/node/process/process-task-runner.js +355 -355
  86. package/lib/node/process/process-task.d.ts +26 -26
  87. package/lib/node/process/process-task.js +135 -135
  88. package/lib/node/process/process-task.spec.d.ts +1 -1
  89. package/lib/node/process/process-task.spec.js +29 -29
  90. package/lib/node/task-abstract-line-matcher.d.ts +49 -49
  91. package/lib/node/task-abstract-line-matcher.js +273 -273
  92. package/lib/node/task-backend-application-contribution.d.ts +8 -8
  93. package/lib/node/task-backend-application-contribution.js +48 -48
  94. package/lib/node/task-backend-module.d.ts +3 -3
  95. package/lib/node/task-backend-module.js +50 -50
  96. package/lib/node/task-line-matchers.d.ts +27 -27
  97. package/lib/node/task-line-matchers.js +121 -121
  98. package/lib/node/task-manager.d.ts +55 -55
  99. package/lib/node/task-manager.js +135 -135
  100. package/lib/node/task-problem-collector.d.ts +10 -10
  101. package/lib/node/task-problem-collector.js +57 -57
  102. package/lib/node/task-problem-collector.spec.d.ts +1 -1
  103. package/lib/node/task-problem-collector.spec.js +310 -310
  104. package/lib/node/task-runner-protocol.d.ts +16 -16
  105. package/lib/node/task-runner-protocol.js +19 -19
  106. package/lib/node/task-runner.d.ts +50 -50
  107. package/lib/node/task-runner.js +97 -97
  108. package/lib/node/task-server.d.ts +39 -39
  109. package/lib/node/task-server.js +237 -237
  110. package/lib/node/task-server.slow-spec.d.ts +1 -1
  111. package/lib/node/task-server.slow-spec.js +395 -395
  112. package/lib/node/task.d.ts +50 -50
  113. package/lib/node/task.js +77 -77
  114. package/lib/node/test/task-test-container.d.ts +2 -2
  115. package/lib/node/test/task-test-container.js +58 -58
  116. package/package.json +14 -14
  117. package/src/browser/index.ts +22 -22
  118. package/src/browser/process/process-task-contribution.ts +31 -31
  119. package/src/browser/process/process-task-frontend-module.ts +27 -27
  120. package/src/browser/process/process-task-resolver.ts +89 -89
  121. package/src/browser/provided-task-configurations.spec.ts +46 -46
  122. package/src/browser/provided-task-configurations.ts +213 -213
  123. package/src/browser/quick-open-task.ts +831 -827
  124. package/src/browser/style/index.css +19 -19
  125. package/src/browser/task-configuration-manager.ts +256 -256
  126. package/src/browser/task-configuration-model.ts +101 -101
  127. package/src/browser/task-configurations.ts +508 -508
  128. package/src/browser/task-contribution.ts +266 -266
  129. package/src/browser/task-definition-registry.spec.ts +203 -203
  130. package/src/browser/task-definition-registry.ts +131 -131
  131. package/src/browser/task-frontend-contribution.ts +402 -402
  132. package/src/browser/task-frontend-module.ts +86 -86
  133. package/src/browser/task-name-resolver.ts +55 -55
  134. package/src/browser/task-node.ts +37 -37
  135. package/src/browser/task-preferences.ts +40 -40
  136. package/src/browser/task-problem-matcher-registry.ts +308 -308
  137. package/src/browser/task-problem-pattern-registry.ts +196 -196
  138. package/src/browser/task-schema-updater.ts +701 -701
  139. package/src/browser/task-service.ts +1164 -1164
  140. package/src/browser/task-source-resolver.ts +36 -36
  141. package/src/browser/task-templates.ts +168 -168
  142. package/src/browser/task-terminal-widget-manager.ts +224 -224
  143. package/src/browser/tasks-monaco-contribution.ts +27 -27
  144. package/src/common/index.ts +20 -20
  145. package/src/common/problem-matcher-protocol.ts +234 -234
  146. package/src/common/process/task-protocol.ts +97 -97
  147. package/src/common/task-common-module.ts +34 -34
  148. package/src/common/task-protocol.ts +317 -317
  149. package/src/common/task-util.ts +43 -43
  150. package/src/common/task-watcher.ts +78 -78
  151. package/src/node/custom/custom-task-runner-backend-module.ts +37 -37
  152. package/src/node/custom/custom-task-runner-contribution.ts +30 -30
  153. package/src/node/custom/custom-task-runner.ts +60 -60
  154. package/src/node/custom/custom-task.ts +73 -73
  155. package/src/node/index.ts +19 -19
  156. package/src/node/process/process-task-runner-backend-module.ts +37 -37
  157. package/src/node/process/process-task-runner-contribution.ts +31 -31
  158. package/src/node/process/process-task-runner.ts +371 -371
  159. package/src/node/process/process-task.spec.ts +30 -30
  160. package/src/node/process/process-task.ts +144 -144
  161. package/src/node/task-abstract-line-matcher.ts +312 -312
  162. package/src/node/task-backend-application-contribution.ts +36 -36
  163. package/src/node/task-backend-module.ts +57 -57
  164. package/src/node/task-line-matchers.ts +127 -127
  165. package/src/node/task-manager.ts +129 -129
  166. package/src/node/task-problem-collector.spec.ts +338 -338
  167. package/src/node/task-problem-collector.ts +62 -62
  168. package/src/node/task-runner-protocol.ts +33 -33
  169. package/src/node/task-runner.ts +96 -96
  170. package/src/node/task-server.slow-spec.ts +444 -444
  171. package/src/node/task-server.ts +263 -263
  172. package/src/node/task.ts +103 -103
  173. package/src/node/test/task-test-container.ts +63 -63
@@ -1,1164 +1,1164 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { ApplicationShell, FrontendApplication, QuickPickValue, WidgetManager, WidgetOpenMode } from '@theia/core/lib/browser';
18
- import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
19
- import { CommandService, ILogger } from '@theia/core/lib/common';
20
- import { MessageService } from '@theia/core/lib/common/message-service';
21
- import { Deferred } from '@theia/core/lib/common/promise-util';
22
- import { QuickPickItemOrSeparator, QuickPickService } from '@theia/core/lib/common/quick-pick-service';
23
- import { LabelProvider } from '@theia/core/lib/browser/label-provider';
24
- import URI from '@theia/core/lib/common/uri';
25
- import { EditorManager } from '@theia/editor/lib/browser';
26
- import { ProblemManager } from '@theia/markers/lib/browser/problem/problem-manager';
27
- import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
28
- import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
29
- import { TerminalWidgetFactoryOptions } from '@theia/terminal/lib/browser/terminal-widget-impl';
30
- import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
31
- import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
32
- import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
33
- import { DiagnosticSeverity, Range } from '@theia/core/shared/vscode-languageserver-protocol';
34
- import {
35
- ApplyToKind,
36
- BackgroundTaskEndedEvent,
37
- DependsOrder,
38
- NamedProblemMatcher,
39
- ProblemMatchData,
40
- ProblemMatcher,
41
- RevealKind,
42
- RunTaskOption,
43
- TaskConfiguration,
44
- TaskConfigurationScope,
45
- TaskCustomization,
46
- TaskExitedEvent,
47
- TaskIdentifier,
48
- TaskInfo,
49
- TaskOutputPresentation,
50
- TaskOutputProcessedEvent,
51
- TaskServer,
52
- asVariableName
53
- } from '../common';
54
- import { TaskWatcher } from '../common/task-watcher';
55
- import { ProvidedTaskConfigurations } from './provided-task-configurations';
56
- import { TaskConfigurationClient, TaskConfigurations } from './task-configurations';
57
- import { TaskResolverRegistry } from './task-contribution';
58
- import { TaskDefinitionRegistry } from './task-definition-registry';
59
- import { TaskNameResolver } from './task-name-resolver';
60
- import { TaskSourceResolver } from './task-source-resolver';
61
- import { ProblemMatcherRegistry } from './task-problem-matcher-registry';
62
- import { TaskSchemaUpdater } from './task-schema-updater';
63
- import { TaskConfigurationManager } from './task-configuration-manager';
64
- import { PROBLEMS_WIDGET_ID, ProblemWidget } from '@theia/markers/lib/browser/problem/problem-widget';
65
- import { TaskNode } from './task-node';
66
- import { MonacoWorkspace } from '@theia/monaco/lib/browser/monaco-workspace';
67
- import { TaskTerminalWidgetManager } from './task-terminal-widget-manager';
68
- import { ShellTerminalServerProxy } from '@theia/terminal/lib/common/shell-terminal-protocol';
69
- import { Mutex } from 'async-mutex';
70
-
71
- export interface QuickPickProblemMatcherItem {
72
- problemMatchers: NamedProblemMatcher[] | undefined;
73
- learnMore?: boolean;
74
- }
75
-
76
- interface TaskGraphNode {
77
- taskConfiguration: TaskConfiguration;
78
- node: TaskNode;
79
- }
80
-
81
- export enum TaskEndedTypes {
82
- TaskExited,
83
- BackgroundTaskEnded
84
- }
85
-
86
- export interface TaskEndedInfo {
87
- taskEndedType: TaskEndedTypes,
88
- value: number | boolean | undefined
89
- }
90
-
91
- export interface LastRunTaskInfo {
92
- resolvedTask?: TaskConfiguration;
93
- option?: RunTaskOption
94
- }
95
-
96
- @injectable()
97
- export class TaskService implements TaskConfigurationClient {
98
-
99
- /**
100
- * The last executed task.
101
- */
102
- protected lastTask: LastRunTaskInfo = { resolvedTask: undefined, option: undefined };
103
- protected cachedRecentTasks: TaskConfiguration[] = [];
104
- protected runningTasks = new Map<number, {
105
- exitCode: Deferred<number | undefined>,
106
- terminateSignal: Deferred<string | undefined>,
107
- isBackgroundTaskEnded: Deferred<boolean | undefined>
108
- }>();
109
-
110
- protected taskStartingLock: Mutex = new Mutex();
111
-
112
- @inject(FrontendApplication)
113
- protected readonly app: FrontendApplication;
114
-
115
- @inject(ApplicationShell)
116
- protected readonly shell: ApplicationShell;
117
-
118
- @inject(TaskServer)
119
- protected readonly taskServer: TaskServer;
120
-
121
- @inject(ILogger) @named('task')
122
- protected readonly logger: ILogger;
123
-
124
- @inject(WidgetManager)
125
- protected readonly widgetManager: WidgetManager;
126
-
127
- @inject(TaskWatcher)
128
- protected readonly taskWatcher: TaskWatcher;
129
-
130
- @inject(MessageService)
131
- protected readonly messageService: MessageService;
132
-
133
- @inject(WorkspaceService)
134
- protected readonly workspaceService: WorkspaceService;
135
-
136
- @inject(TaskConfigurations)
137
- protected readonly taskConfigurations: TaskConfigurations;
138
-
139
- @inject(ProvidedTaskConfigurations)
140
- protected readonly providedTaskConfigurations: ProvidedTaskConfigurations;
141
-
142
- @inject(VariableResolverService)
143
- protected readonly variableResolverService: VariableResolverService;
144
-
145
- @inject(TaskResolverRegistry)
146
- protected readonly taskResolverRegistry: TaskResolverRegistry;
147
-
148
- @inject(TerminalService)
149
- protected readonly terminalService: TerminalService;
150
-
151
- @inject(EditorManager)
152
- protected readonly editorManager: EditorManager;
153
-
154
- @inject(ProblemManager)
155
- protected readonly problemManager: ProblemManager;
156
-
157
- @inject(TaskDefinitionRegistry)
158
- protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
159
-
160
- @inject(ProblemMatcherRegistry)
161
- protected readonly problemMatcherRegistry: ProblemMatcherRegistry;
162
-
163
- @inject(QuickPickService)
164
- protected readonly quickPickService: QuickPickService;
165
-
166
- @inject(OpenerService)
167
- protected readonly openerService: OpenerService;
168
-
169
- @inject(ShellTerminalServerProxy)
170
- protected readonly shellTerminalServer: ShellTerminalServerProxy;
171
-
172
- @inject(TaskNameResolver)
173
- protected readonly taskNameResolver: TaskNameResolver;
174
-
175
- @inject(TaskSourceResolver)
176
- protected readonly taskSourceResolver: TaskSourceResolver;
177
-
178
- @inject(TaskSchemaUpdater)
179
- protected readonly taskSchemaUpdater: TaskSchemaUpdater;
180
-
181
- @inject(TaskConfigurationManager)
182
- protected readonly taskConfigurationManager: TaskConfigurationManager;
183
-
184
- @inject(CommandService)
185
- protected readonly commands: CommandService;
186
-
187
- @inject(LabelProvider)
188
- protected readonly labelProvider: LabelProvider;
189
-
190
- @inject(MonacoWorkspace)
191
- protected monacoWorkspace: MonacoWorkspace;
192
-
193
- @inject(TaskTerminalWidgetManager)
194
- protected readonly taskTerminalWidgetManager: TaskTerminalWidgetManager;
195
-
196
- @postConstruct()
197
- protected init(): void {
198
- this.getRunningTasks().then(tasks =>
199
- tasks.forEach(task => {
200
- if (!this.runningTasks.has(task.taskId)) {
201
- this.runningTasks.set(task.taskId, {
202
- exitCode: new Deferred<number | undefined>(), terminateSignal: new Deferred<string | undefined>(),
203
- isBackgroundTaskEnded: new Deferred<boolean | undefined>()
204
- });
205
- }
206
- }));
207
-
208
- // notify user that task has started
209
- this.taskWatcher.onTaskCreated((event: TaskInfo) => {
210
- if (!this.isEventForThisClient(event.ctx)) {
211
- return;
212
- }
213
- this.runningTasks.set(event.taskId, {
214
- exitCode: new Deferred<number | undefined>(),
215
- terminateSignal: new Deferred<string | undefined>(),
216
- isBackgroundTaskEnded: new Deferred<boolean | undefined>()
217
- });
218
- });
219
-
220
- this.taskWatcher.onOutputProcessed(async (event: TaskOutputProcessedEvent) => {
221
- if (!this.isEventForThisClient(event.ctx)) {
222
- return;
223
- }
224
- if (event.problems) {
225
- const runningTasksInfo: TaskInfo[] = await this.getRunningTasks();
226
- // check if the task is active
227
- const matchedRunningTaskInfo = runningTasksInfo.find(taskInfo => {
228
- const taskConfig = taskInfo.config;
229
- return this.taskDefinitionRegistry.compareTasks(taskConfig, event.config);
230
- });
231
- const isTaskActiveAndOutputSilent = matchedRunningTaskInfo &&
232
- matchedRunningTaskInfo.config.presentation && matchedRunningTaskInfo.config.presentation.reveal === RevealKind.Silent;
233
- event.problems.forEach(problem => {
234
- const existingMarkers = this.problemManager.findMarkers({ owner: problem.description.owner });
235
- const uris = new Set<string>();
236
- existingMarkers.forEach(marker => uris.add(marker.uri));
237
- if (ProblemMatchData.is(problem) && problem.resource) {
238
- // When task.presentation.reveal === RevealKind.Silent, put focus on the terminal only if it is an error
239
- if (isTaskActiveAndOutputSilent && problem.marker.severity === DiagnosticSeverity.Error) {
240
- const terminalId = matchedRunningTaskInfo!.terminalId;
241
- if (terminalId) {
242
- const terminal = this.terminalService.getByTerminalId(terminalId);
243
- if (terminal) {
244
- const focus = !!matchedRunningTaskInfo!.config.presentation!.focus;
245
- if (focus) { // assign focus to the terminal if presentation.focus is true
246
- this.terminalService.open(terminal, { mode: 'activate' });
247
- } else { // show the terminal but not assign focus
248
- this.terminalService.open(terminal, { mode: 'reveal' });
249
- }
250
- }
251
- }
252
- }
253
- const uri = problem.resource.withScheme(problem.resource.scheme);
254
- const document = this.monacoWorkspace.getTextDocument(uri.toString());
255
- if (problem.description.applyTo === ApplyToKind.openDocuments && !!document ||
256
- problem.description.applyTo === ApplyToKind.closedDocuments && !document ||
257
- problem.description.applyTo === ApplyToKind.allDocuments
258
- ) {
259
- if (uris.has(uri.toString())) {
260
- const newData = [
261
- ...existingMarkers
262
- .filter(marker => marker.uri === uri.toString())
263
- .map(markerData => markerData.data),
264
- problem.marker
265
- ];
266
- this.problemManager.setMarkers(uri, problem.description.owner, newData);
267
- } else {
268
- this.problemManager.setMarkers(uri, problem.description.owner, [problem.marker]);
269
- }
270
- }
271
- } else { // should have received an event for finding the "background task begins" pattern
272
- uris.forEach(uriString => this.problemManager.setMarkers(new URI(uriString), problem.description.owner, []));
273
- }
274
- });
275
- }
276
- });
277
-
278
- this.taskWatcher.onBackgroundTaskEnded((event: BackgroundTaskEndedEvent) => {
279
- if (!this.isEventForThisClient(event.ctx)) {
280
- return;
281
- }
282
-
283
- if (!this.runningTasks.has(event.taskId)) {
284
- this.runningTasks.set(event.taskId, {
285
- exitCode: new Deferred<number | undefined>(),
286
- terminateSignal: new Deferred<string | undefined>(),
287
- isBackgroundTaskEnded: new Deferred<boolean | undefined>()
288
- });
289
- }
290
- this.runningTasks.get(event.taskId)!.isBackgroundTaskEnded.resolve(true);
291
- });
292
-
293
- // notify user that task has finished
294
- this.taskWatcher.onTaskExit((event: TaskExitedEvent) => {
295
- if (!this.isEventForThisClient(event.ctx)) {
296
- return;
297
- }
298
- if (!this.runningTasks.has(event.taskId)) {
299
- this.runningTasks.set(event.taskId, {
300
- exitCode: new Deferred<number | undefined>(),
301
- terminateSignal: new Deferred<string | undefined>(),
302
- isBackgroundTaskEnded: new Deferred<boolean | undefined>()
303
- });
304
- }
305
- this.runningTasks.get(event.taskId)!.exitCode.resolve(event.code);
306
- this.runningTasks.get(event.taskId)!.terminateSignal.resolve(event.signal);
307
- setTimeout(() => this.runningTasks.delete(event.taskId), 60 * 1000);
308
-
309
- const taskConfig = event.config;
310
- const taskIdentifier = taskConfig ? this.getTaskIdentifier(taskConfig) : event.taskId.toString();
311
- if (event.code !== undefined) {
312
- if (event.code !== 0) {
313
- const eventTaskConfig = event.config;
314
- if (eventTaskConfig && eventTaskConfig.presentation && eventTaskConfig.presentation.reveal === RevealKind.Silent && event.terminalId) {
315
- const terminal = this.terminalService.getByTerminalId(event.terminalId);
316
- const focus = !!eventTaskConfig.presentation.focus;
317
- if (terminal) {
318
- if (focus) { // assign focus to the terminal if presentation.focus is true
319
- this.terminalService.open(terminal, { mode: 'activate' });
320
- } else { // show the terminal but not assign focus
321
- this.terminalService.open(terminal, { mode: 'reveal' });
322
- }
323
- }
324
- }
325
- this.messageService.error(`Task '${taskIdentifier}' has exited with code ${event.code}.`);
326
- }
327
- } else if (event.signal !== undefined) {
328
- this.messageService.info(`Task '${taskIdentifier}' was terminated by signal ${event.signal}.`);
329
- } else {
330
- console.error('Invalid TaskExitedEvent received, neither code nor signal is set.');
331
- }
332
- });
333
- }
334
-
335
- protected getTaskIdentifier(taskConfig: TaskConfiguration): string {
336
- const taskName = this.taskNameResolver.resolve(taskConfig);
337
- const sourceStrUri = this.taskSourceResolver.resolve(taskConfig);
338
- return `${taskName} (${this.labelProvider.getName(new URI(sourceStrUri))})`;
339
- }
340
-
341
- /**
342
- * Client should call this method to indicate that a new user-level action related to tasks has been started,
343
- * like invoking "Run Task..."
344
- * This method returns a token that can be used with various methods in this service.
345
- * As long as a client uses the same token, task providers will only asked once to contribute
346
- * tasks and the set of tasks will be cached. Each time the a new token is used, the cache of
347
- * contributed tasks is cleared.
348
- * @returns a token to be used for task-related actions
349
- */
350
- startUserAction(): number {
351
- return this.providedTaskConfigurations.startUserAction();
352
- }
353
-
354
- /**
355
- * Returns an array of the task configurations configured in tasks.json and provided by the extensions.
356
- * @param token The cache token for the user interaction in progress
357
- */
358
- async getTasks(token: number): Promise<TaskConfiguration[]> {
359
- const configuredTasks = await this.getConfiguredTasks(token);
360
- const providedTasks = await this.getProvidedTasks(token);
361
- const notCustomizedProvidedTasks = providedTasks.filter(provided =>
362
- !configuredTasks.some(configured => this.taskDefinitionRegistry.compareTasks(configured, provided))
363
- );
364
- return [...configuredTasks, ...notCustomizedProvidedTasks];
365
- }
366
-
367
- /**
368
- * Returns an array of the valid task configurations which are configured in tasks.json files
369
- * @param token The cache token for the user interaction in progress
370
- *
371
- */
372
- async getConfiguredTasks(token: number): Promise<TaskConfiguration[]> {
373
- const invalidTaskConfig = this.taskConfigurations.getInvalidTaskConfigurations()[0];
374
- if (invalidTaskConfig) {
375
- const widget = <ProblemWidget>await this.widgetManager.getOrCreateWidget(PROBLEMS_WIDGET_ID);
376
- const isProblemsWidgetVisible = widget && widget.isVisible;
377
- const currentEditorUri = this.editorManager.currentEditor && this.editorManager.currentEditor.editor.getResourceUri();
378
- let isInvalidTaskConfigFileOpen = false;
379
- if (currentEditorUri) {
380
- const folderUri = this.workspaceService.getWorkspaceRootUri(currentEditorUri);
381
- if (folderUri && folderUri.toString() === invalidTaskConfig._scope) {
382
- isInvalidTaskConfigFileOpen = true;
383
- }
384
- }
385
- const warningMessage = 'Invalid task configurations are found. Open tasks.json and find details in the Problems view.';
386
- if (!isProblemsWidgetVisible || !isInvalidTaskConfigFileOpen) {
387
- this.messageService.warn(warningMessage, 'Open').then(actionOpen => {
388
- if (actionOpen) {
389
- if (invalidTaskConfig && invalidTaskConfig._scope) {
390
- this.taskConfigurationManager.openConfiguration(invalidTaskConfig._scope);
391
- }
392
- if (!isProblemsWidgetVisible) {
393
- this.commands.executeCommand('problemsView:toggle');
394
- }
395
- }
396
- });
397
- } else {
398
- this.messageService.warn(warningMessage);
399
- }
400
- }
401
-
402
- const validTaskConfigs = await this.taskConfigurations.getTasks(token);
403
- return validTaskConfigs;
404
- }
405
-
406
- /**
407
- * Returns an array that contains the task configurations provided by the task providers for the specified task type.
408
- * @param token The cache token for the user interaction in progress
409
- * @param type The task type (filter) associated to the returning TaskConfigurations
410
- *
411
- * '*' indicates all tasks regardless of the type
412
- */
413
- getProvidedTasks(token: number, type?: string): Promise<TaskConfiguration[]> {
414
- return this.providedTaskConfigurations.getTasks(token, type);
415
- }
416
-
417
- addRecentTasks(tasks: TaskConfiguration | TaskConfiguration[]): void {
418
- if (Array.isArray(tasks)) {
419
- tasks.forEach(task => this.addRecentTasks(task));
420
- } else {
421
- const ind = this.cachedRecentTasks.findIndex(recent => this.taskDefinitionRegistry.compareTasks(recent, tasks));
422
- if (ind >= 0) {
423
- this.cachedRecentTasks.splice(ind, 1);
424
- }
425
- this.cachedRecentTasks.unshift(tasks);
426
- }
427
- }
428
-
429
- get recentTasks(): TaskConfiguration[] {
430
- return this.cachedRecentTasks;
431
- }
432
-
433
- set recentTasks(recent: TaskConfiguration[]) {
434
- this.cachedRecentTasks = recent;
435
- }
436
-
437
- /**
438
- * Clears the list of recently used tasks.
439
- */
440
- clearRecentTasks(): void {
441
- this.cachedRecentTasks = [];
442
- }
443
-
444
- /**
445
- * Open user ser
446
- */
447
- openUserTasks(): Promise<void> {
448
- return this.taskConfigurations.openUserTasks();
449
- }
450
-
451
- /**
452
- * Returns a task configuration provided by an extension by task source, scope and label.
453
- * If there are no task configuration, returns undefined.
454
- * @param token The cache token for the user interaction in progress
455
- * @param source The source for configured tasks
456
- * @param label The label of the task to find
457
- * @param scope The task scope to look in
458
- */
459
- async getProvidedTask(token: number, source: string, label: string, scope: TaskConfigurationScope): Promise<TaskConfiguration | undefined> {
460
- return this.providedTaskConfigurations.getTask(token, source, label, scope);
461
- }
462
-
463
- /** Returns an array of running tasks 'TaskInfo' objects */
464
- getRunningTasks(): Promise<TaskInfo[]> {
465
- return this.taskServer.getTasks(this.getContext());
466
- }
467
-
468
- async customExecutionComplete(id: number, exitCode: number | undefined): Promise<void> {
469
- return this.taskServer.customExecutionComplete(id, exitCode);
470
- }
471
-
472
- /** Returns an array of task types that are registered, including the default types */
473
- getRegisteredTaskTypes(): Promise<string[]> {
474
- return this.taskSchemaUpdater.getRegisteredTaskTypes();
475
- }
476
-
477
- /**
478
- * Get the last executed task.
479
- *
480
- * @returns the last executed task or `undefined`.
481
- */
482
- getLastTask(): LastRunTaskInfo {
483
- return this.lastTask;
484
- }
485
-
486
- /**
487
- * Runs a task, by task configuration label.
488
- * Note, it looks for a task configured in tasks.json only.
489
- * @param token The cache token for the user interaction in progress
490
- * @param scope The scope where to look for tasks
491
- * @param taskLabel the label to look for
492
- */
493
- async runConfiguredTask(token: number, scope: TaskConfigurationScope, taskLabel: string): Promise<void> {
494
- const task = this.taskConfigurations.getTask(scope, taskLabel);
495
- if (!task) {
496
- this.logger.error(`Can't get task launch configuration for label: ${taskLabel}`);
497
- return;
498
- }
499
-
500
- this.run(token, task._source, taskLabel, scope);
501
- }
502
-
503
- /**
504
- * Run the last executed task.
505
- * @param token The cache token for the user interaction in progress
506
- */
507
- async runLastTask(token: number): Promise<TaskInfo | undefined> {
508
- if (!this.lastTask?.resolvedTask) {
509
- return;
510
- }
511
- if (!this.lastTask.resolvedTask.runOptions?.reevaluateOnRerun) {
512
- return this.runResolvedTask(this.lastTask.resolvedTask, this.lastTask.option);
513
- }
514
- const { _source, label, _scope } = this.lastTask.resolvedTask;
515
- return this.run(token, _source, label, _scope);
516
- }
517
-
518
- /**
519
- * Runs a task, by the source and label of the task configuration.
520
- * It looks for configured and detected tasks.
521
- * @param token The cache token for the user interaction in progress
522
- * @param source The source for configured tasks
523
- * @param taskLabel The label to look for
524
- * @param scope The scope where to look for tasks
525
- */
526
- async run(token: number, source: string, taskLabel: string, scope: TaskConfigurationScope): Promise<TaskInfo | undefined> {
527
- let task: TaskConfiguration | undefined;
528
- task = this.taskConfigurations.getTask(scope, taskLabel);
529
- if (!task) { // if a configured task cannot be found, search from detected tasks
530
- task = await this.getProvidedTask(token, source, taskLabel, scope);
531
- if (!task) { // find from the customized detected tasks
532
- task = await this.taskConfigurations.getCustomizedTask(token, scope, taskLabel);
533
- }
534
- if (!task) {
535
- this.logger.error(`Can't get task launch configuration for label: ${taskLabel}`);
536
- return;
537
- }
538
- }
539
- const customizationObject = await this.getTaskCustomization(task);
540
-
541
- if (!customizationObject.problemMatcher) {
542
- // ask the user what s/he wants to use to parse the task output
543
- const items = this.getCustomizeProblemMatcherItems();
544
- const selected = await this.quickPickService.show(items, {
545
- placeholder: 'Select for which kind of errors and warnings to scan the task output'
546
- });
547
- if (selected && ('value' in selected)) {
548
- if (selected.value?.problemMatchers) {
549
- let matcherNames: string[] = [];
550
- if (selected.value.problemMatchers && selected.value.problemMatchers.length === 0) { // never parse output for this task
551
- matcherNames = [];
552
- } else if (selected.value.problemMatchers && selected.value.problemMatchers.length > 0) { // continue with user-selected parser
553
- matcherNames = selected.value.problemMatchers.map(matcher => matcher.name);
554
- }
555
- customizationObject.problemMatcher = matcherNames;
556
-
557
- // write the selected matcher (or the decision of "never parse") into the `tasks.json`
558
- this.updateTaskConfiguration(token, task, { problemMatcher: matcherNames });
559
- } else if (selected.value?.learnMore) { // user wants to learn more about parsing task output
560
- open(this.openerService, new URI('https://code.visualstudio.com/docs/editor/tasks#_processing-task-output-with-problem-matchers'));
561
- }
562
- // else, continue the task with no parser
563
- } else { // do not start the task in case that the user did not select any item from the list
564
- return;
565
- }
566
- }
567
-
568
- const resolvedMatchers = await this.resolveProblemMatchers(task, customizationObject);
569
- const runTaskOption: RunTaskOption = {
570
- customization: { ...customizationObject, ...{ problemMatcher: resolvedMatchers } }
571
- };
572
-
573
- if (task.dependsOn) {
574
- return this.runCompoundTask(token, task, runTaskOption);
575
- } else {
576
- return this.runTask(task, runTaskOption).catch(error => {
577
- console.error('Error at launching task', error);
578
- return undefined;
579
- });
580
- }
581
- }
582
-
583
- /**
584
- * Runs a compound task
585
- * @param token The cache token for the user interaction in progress
586
- * @param task The task to be executed
587
- * @param option options for executing the task
588
- */
589
- async runCompoundTask(token: number, task: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
590
- const tasks = await this.getWorkspaceTasks(token, task._scope);
591
- try {
592
- const rootNode = new TaskNode(task, [], []);
593
- this.detectDirectedAcyclicGraph(task, rootNode, tasks);
594
- } catch (error) {
595
- console.error(`Error at launching task '${task.label}'`, error);
596
- this.messageService.error(error.message);
597
- return undefined;
598
- }
599
- return this.runTasksGraph(task, tasks, option).catch(error => {
600
- console.error(`Error at launching task '${task.label}'`, error);
601
- return undefined;
602
- });
603
- }
604
-
605
- /**
606
- * A recursive function that runs a task and all its sub tasks that it depends on.
607
- * A task can be executed only when all of its dependencies have been executed, or when it doesn’t have any dependencies at all.
608
- */
609
- async runTasksGraph(task: TaskConfiguration, tasks: TaskConfiguration[], option?: RunTaskOption): Promise<TaskInfo | undefined> {
610
- if (task && task.dependsOn) {
611
- // In case it is an array of task dependencies
612
- if (Array.isArray(task.dependsOn) && task.dependsOn.length > 0) {
613
- const dependentTasks: { 'task': TaskConfiguration; 'taskCustomization': TaskCustomization; 'resolvedMatchers': ProblemMatcher[] | undefined }[] = [];
614
- for (let i = 0; i < task.dependsOn.length; i++) {
615
- // It may be a string (a task label) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
616
- const taskIdentifier = task.dependsOn[i];
617
- const dependentTask = this.getDependentTask(taskIdentifier, tasks);
618
- const taskCustomization = await this.getTaskCustomization(dependentTask);
619
- const resolvedMatchers = await this.resolveProblemMatchers(dependentTask, taskCustomization);
620
- dependentTasks.push({ 'task': dependentTask, 'taskCustomization': taskCustomization, 'resolvedMatchers': resolvedMatchers });
621
- // In case the 'dependsOrder' is 'sequence'
622
- if (task.dependsOrder && task.dependsOrder === DependsOrder.Sequence) {
623
- await this.runTasksGraph(dependentTask, tasks, {
624
- customization: { ...taskCustomization, ...{ problemMatcher: resolvedMatchers } }
625
- });
626
- }
627
- }
628
- // In case the 'dependsOrder' is 'parallel'
629
- if (((!task.dependsOrder) || (task.dependsOrder && task.dependsOrder === DependsOrder.Parallel))) {
630
- const promises = dependentTasks.map(item =>
631
- this.runTasksGraph(item.task, tasks, {
632
- customization: { ...item.taskCustomization, ...{ problemMatcher: item.resolvedMatchers } }
633
- })
634
- );
635
- await Promise.all(promises);
636
- }
637
- } else if (!Array.isArray(task.dependsOn)) {
638
- // In case it is a string (a task label) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
639
- const taskIdentifier = task.dependsOn;
640
- const dependentTask = this.getDependentTask(taskIdentifier, tasks);
641
- const taskCustomization = await this.getTaskCustomization(dependentTask);
642
- const resolvedMatchers = await this.resolveProblemMatchers(dependentTask, taskCustomization);
643
- await this.runTasksGraph(dependentTask, tasks, {
644
- customization: { ...taskCustomization, ...{ problemMatcher: resolvedMatchers } }
645
- });
646
- }
647
- }
648
-
649
- const taskInfo = await this.runTask(task, option);
650
- if (taskInfo) {
651
- const getExitCodePromise: Promise<TaskEndedInfo> = this.getExitCode(taskInfo.taskId).then(result => ({ taskEndedType: TaskEndedTypes.TaskExited, value: result }));
652
- const isBackgroundTaskEndedPromise: Promise<TaskEndedInfo> = this.isBackgroundTaskEnded(taskInfo.taskId).then(result =>
653
- ({ taskEndedType: TaskEndedTypes.BackgroundTaskEnded, value: result }));
654
-
655
- // After start running the task, we wait for the task process to exit and if it is a background task, we also wait for a feedback
656
- // that a background task is active, as soon as one of the promises fulfills, we can continue and analyze the results.
657
- const taskEndedInfo: TaskEndedInfo = await Promise.race([getExitCodePromise, isBackgroundTaskEndedPromise]);
658
-
659
- if ((taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value !== 0) ||
660
- (taskEndedInfo.taskEndedType === TaskEndedTypes.BackgroundTaskEnded && !taskEndedInfo.value)) {
661
- throw new Error('The task: ' + task.label + ' terminated with exit code ' + taskEndedInfo.value + '.');
662
- }
663
- }
664
- return taskInfo;
665
- }
666
-
667
- /**
668
- * Creates a graph of dependencies tasks from the root task and verify there is no DAG (Directed Acyclic Graph).
669
- * In case of detection of a circular dependency, an error is thrown with a message which describes the detected circular reference.
670
- */
671
- detectDirectedAcyclicGraph(task: TaskConfiguration, taskNode: TaskNode, tasks: TaskConfiguration[]): void {
672
- if (task && task.dependsOn) {
673
- // In case the 'dependsOn' is an array
674
- if (Array.isArray(task.dependsOn) && task.dependsOn.length > 0) {
675
- for (let i = 0; i < task.dependsOn.length; i++) {
676
- const childNode = this.createChildTaskNode(task, taskNode, task.dependsOn[i], tasks);
677
- this.detectDirectedAcyclicGraph(childNode.taskConfiguration, childNode.node, tasks);
678
- }
679
- } else if (!Array.isArray(task.dependsOn)) {
680
- const childNode = this.createChildTaskNode(task, taskNode, task.dependsOn, tasks);
681
- this.detectDirectedAcyclicGraph(childNode.taskConfiguration, childNode.node, tasks);
682
- }
683
- }
684
- }
685
-
686
- // 'childTaskIdentifier' may be a string (a task label) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
687
- createChildTaskNode(task: TaskConfiguration, taskNode: TaskNode, childTaskIdentifier: string | TaskIdentifier, tasks: TaskConfiguration[]): TaskGraphNode {
688
- const childTaskConfiguration = this.getDependentTask(childTaskIdentifier, tasks);
689
-
690
- // If current task and child task are identical or if
691
- // one of the child tasks is identical to one of the current task ancestors, then raise an error
692
- if (this.taskDefinitionRegistry.compareTasks(task, childTaskConfiguration) ||
693
- taskNode.parentsID.filter(t => this.taskDefinitionRegistry.compareTasks(childTaskConfiguration, t)).length > 0) {
694
- const fromNode = task.label;
695
- const toNode = childTaskConfiguration.label;
696
- throw new Error('Circular reference detected: ' + fromNode + ' --> ' + toNode);
697
- }
698
- const childNode = new TaskNode(childTaskConfiguration, [], Object.assign([], taskNode.parentsID));
699
- childNode.addParentDependency(taskNode.taskId);
700
- taskNode.addChildDependency(childNode);
701
- return { 'taskConfiguration': childTaskConfiguration, 'node': childNode };
702
- }
703
-
704
- /**
705
- * Gets task configuration by task label or by a JSON object which represents a task identifier
706
- *
707
- * @param taskIdentifier The task label (string) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
708
- * @param tasks an array of the task configurations
709
- * @returns the correct TaskConfiguration object which matches the taskIdentifier
710
- */
711
- getDependentTask(taskIdentifier: string | TaskIdentifier, tasks: TaskConfiguration[]): TaskConfiguration {
712
- const notEnoughDataError = 'The information provided in the "dependsOn" is not enough for matching the correct task !';
713
- let currentTaskChildConfiguration: TaskConfiguration;
714
- if (typeof (taskIdentifier) !== 'string') {
715
- // TaskIdentifier object does not support tasks of type 'shell' (The same behavior as in VS Code).
716
- // So if we want the 'dependsOn' property to include tasks of type 'shell',
717
- // then we must mention their labels (in the 'dependsOn' property) and not to create a task identifier object for them.
718
- currentTaskChildConfiguration = this.getTaskByTaskIdentifier(taskIdentifier, tasks);
719
- if (!currentTaskChildConfiguration.type) {
720
- this.messageService.error(notEnoughDataError);
721
- throw new Error(notEnoughDataError);
722
- }
723
- return currentTaskChildConfiguration;
724
- } else {
725
- currentTaskChildConfiguration = tasks.filter(t => taskIdentifier === this.taskNameResolver.resolve(t))[0];
726
- return currentTaskChildConfiguration;
727
- }
728
- }
729
-
730
- /**
731
- * Gets the matched task from an array of task configurations by TaskIdentifier.
732
- * In case that more than one task configuration matches, we returns the first one.
733
- *
734
- * @param taskIdentifier The task label (string) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
735
- * @param tasks An array of task configurations.
736
- * @returns The correct TaskConfiguration object which matches the taskIdentifier.
737
- */
738
- getTaskByTaskIdentifier(taskIdentifier: TaskIdentifier, tasks: TaskConfiguration[]): TaskConfiguration {
739
- const requiredProperties = Object.keys(taskIdentifier);
740
- const taskWithAllProperties = tasks.find(task => requiredProperties.every(property => task.hasOwnProperty(property) && task[property] === taskIdentifier[property]));
741
- return taskWithAllProperties ?? { label: '', _scope: '', type: '' }; // Fall back to empty TaskConfiguration
742
- }
743
-
744
- async runTask(task: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
745
- console.debug('entering runTask');
746
- const releaseLock = await this.taskStartingLock.acquire();
747
- console.debug('got lock');
748
-
749
- try {
750
- // resolve problemMatchers
751
- if (!option && task.problemMatcher) {
752
- const customizationObject: TaskCustomization = { type: task.taskType, problemMatcher: task.problemMatcher, runOptions: task.runOptions };
753
- const resolvedMatchers = await this.resolveProblemMatchers(task, customizationObject);
754
- option = {
755
- customization: { ...customizationObject, ...{ problemMatcher: resolvedMatchers } }
756
- };
757
- }
758
-
759
- const runningTasksInfo: TaskInfo[] = await this.getRunningTasks();
760
- // check if the task is active
761
- const matchedRunningTaskInfo = runningTasksInfo.find(taskInfo => {
762
- const taskConfig = taskInfo.config;
763
- return this.taskDefinitionRegistry.compareTasks(taskConfig, task);
764
- });
765
- console.debug(`running task ${JSON.stringify(task)}, already running = ${!!matchedRunningTaskInfo}`);
766
-
767
- if (matchedRunningTaskInfo) { // the task is active
768
- releaseLock();
769
- console.debug('released lock');
770
- const taskName = this.taskNameResolver.resolve(task);
771
- const terminalId = matchedRunningTaskInfo.terminalId;
772
- if (terminalId) {
773
- const terminal = this.terminalService.getByTerminalId(terminalId);
774
- if (terminal) {
775
- if (TaskOutputPresentation.shouldSetFocusToTerminal(task)) { // assign focus to the terminal if presentation.focus is true
776
- this.terminalService.open(terminal, { mode: 'activate' });
777
- } else if (TaskOutputPresentation.shouldAlwaysRevealTerminal(task)) { // show the terminal but not assign focus
778
- this.terminalService.open(terminal, { mode: 'reveal' });
779
- }
780
- }
781
- }
782
- const selectedAction = await this.messageService.info(`The task '${taskName}' is already active`, 'Terminate Task', 'Restart Task');
783
- if (selectedAction === 'Terminate Task') {
784
- await this.terminateTask(matchedRunningTaskInfo);
785
- } else if (selectedAction === 'Restart Task') {
786
- return this.restartTask(matchedRunningTaskInfo, option);
787
- }
788
- } else { // run task as the task is not active
789
- console.debug('task about to start');
790
- const taskInfo = await this.doRunTask(task, option);
791
- releaseLock();
792
- console.debug('release lock 2');
793
- return taskInfo;
794
- }
795
- } catch (e) {
796
- releaseLock();
797
- throw e;
798
- }
799
- }
800
-
801
- /**
802
- * Terminates a task that is actively running.
803
- * @param activeTaskInfo the TaskInfo of the task that is actively running
804
- */
805
- async terminateTask(activeTaskInfo: TaskInfo): Promise<void> {
806
- const taskId = activeTaskInfo.taskId;
807
- return this.kill(taskId);
808
- }
809
-
810
- /**
811
- * Terminates a task that is actively running, and restarts it.
812
- * @param activeTaskInfo the TaskInfo of the task that is actively running
813
- */
814
- async restartTask(activeTaskInfo: TaskInfo, option?: RunTaskOption): Promise<TaskInfo | undefined> {
815
- await this.terminateTask(activeTaskInfo);
816
- return this.doRunTask(activeTaskInfo.config, option);
817
- }
818
-
819
- protected async doRunTask(task: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
820
- let overridePropertiesFunction: (task: TaskConfiguration) => void = () => { };
821
- if (option && option.customization) {
822
- const taskDefinition = this.taskDefinitionRegistry.getDefinition(task);
823
- if (taskDefinition) { // use the customization object to override the task config
824
- overridePropertiesFunction = tsk => {
825
- Object.keys(option.customization!).forEach(customizedProperty => {
826
- // properties used to define the task cannot be customized
827
- if (customizedProperty !== 'type' && !taskDefinition.properties.all.some(pDefinition => pDefinition === customizedProperty)) {
828
- tsk[customizedProperty] = option.customization![customizedProperty];
829
- }
830
- });
831
- };
832
- }
833
- }
834
- overridePropertiesFunction(task);
835
- this.addRecentTasks(task);
836
- try {
837
- const resolver = await this.taskResolverRegistry.getTaskResolver(task.type);
838
- const resolvedTask = resolver ? await resolver.resolveTask(task) : task;
839
- const executionResolver = this.taskResolverRegistry.getExecutionResolver(resolvedTask.taskType || resolvedTask.type);
840
- overridePropertiesFunction(resolvedTask);
841
- const taskToRun = executionResolver ? await executionResolver.resolveTask(resolvedTask) : resolvedTask;
842
-
843
- await this.removeProblemMarkers(option);
844
- return this.runResolvedTask(taskToRun, option);
845
- } catch (error) {
846
- const errMessage = `Error resolving task '${task.label}': ${error}`;
847
- this.logger.error(errMessage);
848
- }
849
- return undefined;
850
- }
851
-
852
- /**
853
- * Runs the first task with the given label.
854
- *
855
- * @param token The cache token for the user interaction in progress
856
- * @param taskLabel The label of the task to be executed
857
- */
858
- async runTaskByLabel(token: number, taskLabel: string): Promise<TaskInfo | undefined> {
859
- const tasks: TaskConfiguration[] = await this.getTasks(token);
860
- for (const task of tasks) {
861
- if (task.label === taskLabel) {
862
- return this.runTask(task);
863
- }
864
- }
865
- return;
866
- }
867
-
868
- /**
869
- * Runs a task identified by the given identifier, but only if found in the given workspace folder
870
- *
871
- * @param token The cache token for the user interaction in progress
872
- * @param workspaceFolderUri The folder to restrict the search to
873
- * @param taskIdentifier The identifier to look for
874
- */
875
- async runWorkspaceTask(token: number, workspaceFolderUri: string | undefined, taskIdentifier: string | TaskIdentifier): Promise<TaskInfo | undefined> {
876
- const tasks = await this.getWorkspaceTasks(token, workspaceFolderUri);
877
- const task = this.getDependentTask(taskIdentifier, tasks);
878
- if (!task) {
879
- return undefined;
880
- }
881
-
882
- const taskCustomization = await this.getTaskCustomization(task);
883
- const resolvedMatchers = await this.resolveProblemMatchers(task, taskCustomization);
884
- try {
885
- const rootNode = new TaskNode(task, [], []);
886
- this.detectDirectedAcyclicGraph(task, rootNode, tasks);
887
- } catch (error) {
888
- this.logger.error(error.message);
889
- this.messageService.error(error.message);
890
- return undefined;
891
- }
892
- return this.runTasksGraph(task, tasks, {
893
- customization: { ...taskCustomization, ...{ problemMatcher: resolvedMatchers } }
894
- }).catch(error => {
895
- console.log(error.message);
896
- return undefined;
897
- });
898
- }
899
-
900
- /**
901
- * Updates the task configuration in the `tasks.json`.
902
- * The task config, together with updates, will be written into the `tasks.json` if it is not found in the file.
903
- *
904
- * @param token The cache token for the user interaction in progress
905
- * @param task task that the updates will be applied to
906
- * @param update the updates to be applied
907
- */
908
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
909
- async updateTaskConfiguration(token: number, task: TaskConfiguration, update: { [name: string]: any }): Promise<void> {
910
- if (update.problemMatcher) {
911
- if (Array.isArray(update.problemMatcher)) {
912
- update.problemMatcher.forEach((_name, index) => update.problemMatcher[index] = asVariableName(update.problemMatcher[index]));
913
- } else {
914
- update.problemMatcher = asVariableName(update.problemMatcher);
915
- }
916
- }
917
- this.taskConfigurations.updateTaskConfig(token, task, update);
918
- }
919
-
920
- protected async getWorkspaceTasks(token: number, restrictToFolder: TaskConfigurationScope | undefined): Promise<TaskConfiguration[]> {
921
- const tasks = await this.getTasks(token);
922
- // if we pass undefined, return everything, otherwise only tasks with the same uri or workspace/global scope tasks
923
- return tasks.filter(t => typeof t._scope !== 'string' || t._scope === restrictToFolder);
924
- }
925
-
926
- protected async resolveProblemMatchers(task: TaskConfiguration, customizationObject: TaskCustomization): Promise<ProblemMatcher[] | undefined> {
927
- const notResolvedMatchers = customizationObject.problemMatcher ?
928
- (Array.isArray(customizationObject.problemMatcher) ? customizationObject.problemMatcher : [customizationObject.problemMatcher]) : undefined;
929
- let resolvedMatchers: ProblemMatcher[] | undefined = [];
930
- if (notResolvedMatchers) {
931
- // resolve matchers before passing them to the server
932
- for (const matcher of notResolvedMatchers) {
933
- let resolvedMatcher: ProblemMatcher | undefined;
934
- await this.problemMatcherRegistry.onReady();
935
- if (typeof matcher === 'string') {
936
- resolvedMatcher = this.problemMatcherRegistry.get(matcher);
937
- } else {
938
- resolvedMatcher = await this.problemMatcherRegistry.getProblemMatcherFromContribution(matcher);
939
- }
940
- if (resolvedMatcher) {
941
- const scope = task._scope || task._source;
942
- if (resolvedMatcher.filePrefix && scope) {
943
- const options = {
944
- context: new URI(scope).withScheme('file'),
945
- configurationSection: 'tasks'
946
- };
947
- const resolvedPrefix = await this.variableResolverService.resolve(resolvedMatcher.filePrefix, options);
948
- Object.assign(resolvedMatcher, { filePrefix: resolvedPrefix });
949
- }
950
- resolvedMatchers.push(resolvedMatcher);
951
- }
952
- }
953
- } else {
954
- resolvedMatchers = undefined;
955
- }
956
- return resolvedMatchers;
957
- }
958
-
959
- protected async getTaskCustomization(task: TaskConfiguration): Promise<TaskCustomization> {
960
- const customizationObject: TaskCustomization = { type: '', _scope: task._scope, runOptions: task.runOptions };
961
- const customizationFound = this.taskConfigurations.getCustomizationForTask(task);
962
- if (customizationFound) {
963
- Object.assign(customizationObject, customizationFound);
964
- } else {
965
- Object.assign(customizationObject, {
966
- type: task.type,
967
- problemMatcher: task.problemMatcher
968
- });
969
- }
970
- return customizationObject;
971
- }
972
-
973
- protected async removeProblemMarkers(option?: RunTaskOption): Promise<void> {
974
- if (option && option.customization) {
975
- const matchersFromOption = option.customization.problemMatcher || [];
976
- for (const matcher of matchersFromOption) {
977
- if (matcher && matcher.owner) {
978
- const existingMarkers = this.problemManager.findMarkers({ owner: matcher.owner });
979
- const uris = new Set<string>();
980
- existingMarkers.forEach(marker => uris.add(marker.uri));
981
- uris.forEach(uriString => this.problemManager.setMarkers(new URI(uriString), matcher.owner, []));
982
- }
983
- }
984
- }
985
- }
986
-
987
- /**
988
- * Runs the resolved task and opens terminal widget if the task is based on a terminal process
989
- * @param resolvedTask the resolved task
990
- * @param option options to run the resolved task
991
- */
992
- protected async runResolvedTask(resolvedTask: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
993
- const taskLabel = resolvedTask.label;
994
- let taskInfo: TaskInfo | undefined;
995
- try {
996
- taskInfo = await this.taskServer.run(resolvedTask, this.getContext(), option);
997
- this.lastTask = { resolvedTask, option };
998
- this.logger.debug(`Task created. Task id: ${taskInfo.taskId}`);
999
-
1000
- /**
1001
- * open terminal widget if the task is based on a terminal process (type: 'shell' or 'process')
1002
- *
1003
- * @todo Use a different mechanism to determine if the task should be attached?
1004
- * Reason: Maybe a new task type wants to also be displayed in a terminal.
1005
- */
1006
- if (typeof taskInfo.terminalId === 'number') {
1007
- await this.attach(taskInfo.terminalId, taskInfo);
1008
- }
1009
- return taskInfo;
1010
- } catch (error) {
1011
- const errorStr = `Error launching task '${taskLabel}': ${error.message}`;
1012
- this.logger.error(errorStr);
1013
- this.messageService.error(errorStr);
1014
- if (taskInfo && typeof taskInfo.terminalId === 'number') {
1015
- this.shellTerminalServer.onAttachAttempted(taskInfo.terminalId);
1016
- }
1017
- }
1018
- }
1019
-
1020
- protected getCustomizeProblemMatcherItems(): Array<QuickPickValue<QuickPickProblemMatcherItem> | QuickPickItemOrSeparator> {
1021
- const items: Array<QuickPickValue<QuickPickProblemMatcherItem> | QuickPickItemOrSeparator> = [];
1022
- items.push({
1023
- label: 'Continue without scanning the task output',
1024
- value: { problemMatchers: undefined }
1025
- });
1026
- items.push({
1027
- label: 'Never scan the task output',
1028
- value: { problemMatchers: [] }
1029
- });
1030
- items.push({
1031
- label: 'Learn more about scanning the task output',
1032
- value: { problemMatchers: undefined, learnMore: true }
1033
- });
1034
- items.push({ type: 'separator', label: 'registered parsers' });
1035
-
1036
- const registeredProblemMatchers = this.problemMatcherRegistry.getAll();
1037
- items.push(...registeredProblemMatchers.map(matcher =>
1038
- ({
1039
- label: matcher.label,
1040
- value: { problemMatchers: [matcher] },
1041
- description: asVariableName(matcher.name)
1042
- })
1043
- ));
1044
- return items;
1045
- }
1046
-
1047
- /**
1048
- * Run selected text in the last active terminal.
1049
- */
1050
- async runSelectedText(): Promise<void> {
1051
- if (!this.editorManager.currentEditor) { return; }
1052
- const startLine = this.editorManager.currentEditor.editor.selection.start.line;
1053
- const startCharacter = this.editorManager.currentEditor.editor.selection.start.character;
1054
- const endLine = this.editorManager.currentEditor.editor.selection.end.line;
1055
- const endCharacter = this.editorManager.currentEditor.editor.selection.end.character;
1056
- let selectedRange: Range = Range.create(startLine, startCharacter, endLine, endCharacter);
1057
- // if no text is selected, default to selecting entire line
1058
- if (startLine === endLine && startCharacter === endCharacter) {
1059
- selectedRange = Range.create(startLine, 0, endLine + 1, 0);
1060
- }
1061
- const selectedText: string = this.editorManager.currentEditor.editor.document.getText(selectedRange).trimRight() + '\n';
1062
- let terminal = this.terminalService.lastUsedTerminal;
1063
- if (!terminal || terminal.kind !== 'user' || (await terminal.hasChildProcesses())) {
1064
- terminal = <TerminalWidget>await this.terminalService.newTerminal(<TerminalWidgetFactoryOptions>{ created: new Date().toString() });
1065
- await terminal.start();
1066
- this.terminalService.open(terminal);
1067
- }
1068
- terminal.sendText(selectedText);
1069
- }
1070
-
1071
- async attach(terminalId: number, taskInfo: TaskInfo): Promise<number | void> {
1072
- let widgetOpenMode: WidgetOpenMode = 'open';
1073
- if (taskInfo) {
1074
- const terminalWidget = this.terminalService.getByTerminalId(terminalId);
1075
- if (terminalWidget) {
1076
- this.messageService.error('Task is already running in terminal');
1077
- return this.terminalService.open(terminalWidget, { mode: 'activate' });
1078
- }
1079
- if (TaskOutputPresentation.shouldAlwaysRevealTerminal(taskInfo.config)) {
1080
- if (TaskOutputPresentation.shouldSetFocusToTerminal(taskInfo.config)) { // assign focus to the terminal if presentation.focus is true
1081
- widgetOpenMode = 'activate';
1082
- } else { // show the terminal but not assign focus
1083
- widgetOpenMode = 'reveal';
1084
- }
1085
- }
1086
- }
1087
- const { taskId } = taskInfo;
1088
- // Create / find a terminal widget to display an execution output of a task that was launched as a command inside a shell.
1089
- const widget = await this.taskTerminalWidgetManager.open({
1090
- created: new Date().toString(),
1091
- id: this.getTerminalWidgetId(terminalId),
1092
- title: taskInfo
1093
- ? `Task: ${taskInfo.config.label}`
1094
- : `Task: #${taskId}`,
1095
- destroyTermOnClose: true,
1096
- useServerTitle: false
1097
- }, {
1098
- widgetOptions: { area: 'bottom' },
1099
- mode: widgetOpenMode,
1100
- taskInfo
1101
- });
1102
- return widget.start(terminalId);
1103
- }
1104
-
1105
- protected getTerminalWidgetId(terminalId: number): string | undefined {
1106
- const terminalWidget = this.terminalService.getByTerminalId(terminalId);
1107
- if (terminalWidget) {
1108
- return terminalWidget.id;
1109
- }
1110
- }
1111
-
1112
- /**
1113
- * Opens an editor to configure the given task.
1114
- *
1115
- * @param token The cache token for the user interaction in progress
1116
- * @param task The task to configure
1117
- */
1118
- async configure(token: number, task: TaskConfiguration): Promise<void> {
1119
- Object.assign(task, { label: this.taskNameResolver.resolve(task) });
1120
- await this.taskConfigurations.configure(token, task);
1121
- }
1122
-
1123
- protected isEventForThisClient(context: string | undefined): boolean {
1124
- if (context === this.getContext()) {
1125
- return true;
1126
- }
1127
- return false;
1128
- }
1129
-
1130
- taskConfigurationChanged(event: string[]): void {
1131
- // do nothing for now
1132
- }
1133
-
1134
- protected getContext(): string | undefined {
1135
- return this.workspaceService.workspace?.resource.toString();
1136
- }
1137
-
1138
- /** Kill task for a given id if task is found */
1139
- async kill(id: number): Promise<void> {
1140
- try {
1141
- await this.taskServer.kill(id);
1142
- } catch (error) {
1143
- this.logger.error(`Error killing task '${id}': ${error}`);
1144
- this.messageService.error(`Error killing task '${id}': ${error}`);
1145
- return;
1146
- }
1147
- this.logger.debug(`Task killed. Task id: ${id}`);
1148
- }
1149
-
1150
- async isBackgroundTaskEnded(id: number): Promise<boolean | undefined> {
1151
- const completedTask = this.runningTasks.get(id);
1152
- return completedTask && completedTask.isBackgroundTaskEnded!.promise;
1153
- }
1154
-
1155
- async getExitCode(id: number): Promise<number | undefined> {
1156
- const completedTask = this.runningTasks.get(id);
1157
- return completedTask && completedTask.exitCode.promise;
1158
- }
1159
-
1160
- async getTerminateSignal(id: number): Promise<string | undefined> {
1161
- const completedTask = this.runningTasks.get(id);
1162
- return completedTask && completedTask.terminateSignal.promise;
1163
- }
1164
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { ApplicationShell, FrontendApplication, QuickPickValue, WidgetManager, WidgetOpenMode } from '@theia/core/lib/browser';
18
+ import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
19
+ import { CommandService, ILogger } from '@theia/core/lib/common';
20
+ import { MessageService } from '@theia/core/lib/common/message-service';
21
+ import { Deferred } from '@theia/core/lib/common/promise-util';
22
+ import { QuickPickItemOrSeparator, QuickPickService } from '@theia/core/lib/common/quick-pick-service';
23
+ import { LabelProvider } from '@theia/core/lib/browser/label-provider';
24
+ import URI from '@theia/core/lib/common/uri';
25
+ import { EditorManager } from '@theia/editor/lib/browser';
26
+ import { ProblemManager } from '@theia/markers/lib/browser/problem/problem-manager';
27
+ import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
28
+ import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
29
+ import { TerminalWidgetFactoryOptions } from '@theia/terminal/lib/browser/terminal-widget-impl';
30
+ import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
31
+ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
32
+ import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
33
+ import { DiagnosticSeverity, Range } from '@theia/core/shared/vscode-languageserver-protocol';
34
+ import {
35
+ ApplyToKind,
36
+ BackgroundTaskEndedEvent,
37
+ DependsOrder,
38
+ NamedProblemMatcher,
39
+ ProblemMatchData,
40
+ ProblemMatcher,
41
+ RevealKind,
42
+ RunTaskOption,
43
+ TaskConfiguration,
44
+ TaskConfigurationScope,
45
+ TaskCustomization,
46
+ TaskExitedEvent,
47
+ TaskIdentifier,
48
+ TaskInfo,
49
+ TaskOutputPresentation,
50
+ TaskOutputProcessedEvent,
51
+ TaskServer,
52
+ asVariableName
53
+ } from '../common';
54
+ import { TaskWatcher } from '../common/task-watcher';
55
+ import { ProvidedTaskConfigurations } from './provided-task-configurations';
56
+ import { TaskConfigurationClient, TaskConfigurations } from './task-configurations';
57
+ import { TaskResolverRegistry } from './task-contribution';
58
+ import { TaskDefinitionRegistry } from './task-definition-registry';
59
+ import { TaskNameResolver } from './task-name-resolver';
60
+ import { TaskSourceResolver } from './task-source-resolver';
61
+ import { ProblemMatcherRegistry } from './task-problem-matcher-registry';
62
+ import { TaskSchemaUpdater } from './task-schema-updater';
63
+ import { TaskConfigurationManager } from './task-configuration-manager';
64
+ import { PROBLEMS_WIDGET_ID, ProblemWidget } from '@theia/markers/lib/browser/problem/problem-widget';
65
+ import { TaskNode } from './task-node';
66
+ import { MonacoWorkspace } from '@theia/monaco/lib/browser/monaco-workspace';
67
+ import { TaskTerminalWidgetManager } from './task-terminal-widget-manager';
68
+ import { ShellTerminalServerProxy } from '@theia/terminal/lib/common/shell-terminal-protocol';
69
+ import { Mutex } from 'async-mutex';
70
+
71
+ export interface QuickPickProblemMatcherItem {
72
+ problemMatchers: NamedProblemMatcher[] | undefined;
73
+ learnMore?: boolean;
74
+ }
75
+
76
+ interface TaskGraphNode {
77
+ taskConfiguration: TaskConfiguration;
78
+ node: TaskNode;
79
+ }
80
+
81
+ export enum TaskEndedTypes {
82
+ TaskExited,
83
+ BackgroundTaskEnded
84
+ }
85
+
86
+ export interface TaskEndedInfo {
87
+ taskEndedType: TaskEndedTypes,
88
+ value: number | boolean | undefined
89
+ }
90
+
91
+ export interface LastRunTaskInfo {
92
+ resolvedTask?: TaskConfiguration;
93
+ option?: RunTaskOption
94
+ }
95
+
96
+ @injectable()
97
+ export class TaskService implements TaskConfigurationClient {
98
+
99
+ /**
100
+ * The last executed task.
101
+ */
102
+ protected lastTask: LastRunTaskInfo = { resolvedTask: undefined, option: undefined };
103
+ protected cachedRecentTasks: TaskConfiguration[] = [];
104
+ protected runningTasks = new Map<number, {
105
+ exitCode: Deferred<number | undefined>,
106
+ terminateSignal: Deferred<string | undefined>,
107
+ isBackgroundTaskEnded: Deferred<boolean | undefined>
108
+ }>();
109
+
110
+ protected taskStartingLock: Mutex = new Mutex();
111
+
112
+ @inject(FrontendApplication)
113
+ protected readonly app: FrontendApplication;
114
+
115
+ @inject(ApplicationShell)
116
+ protected readonly shell: ApplicationShell;
117
+
118
+ @inject(TaskServer)
119
+ protected readonly taskServer: TaskServer;
120
+
121
+ @inject(ILogger) @named('task')
122
+ protected readonly logger: ILogger;
123
+
124
+ @inject(WidgetManager)
125
+ protected readonly widgetManager: WidgetManager;
126
+
127
+ @inject(TaskWatcher)
128
+ protected readonly taskWatcher: TaskWatcher;
129
+
130
+ @inject(MessageService)
131
+ protected readonly messageService: MessageService;
132
+
133
+ @inject(WorkspaceService)
134
+ protected readonly workspaceService: WorkspaceService;
135
+
136
+ @inject(TaskConfigurations)
137
+ protected readonly taskConfigurations: TaskConfigurations;
138
+
139
+ @inject(ProvidedTaskConfigurations)
140
+ protected readonly providedTaskConfigurations: ProvidedTaskConfigurations;
141
+
142
+ @inject(VariableResolverService)
143
+ protected readonly variableResolverService: VariableResolverService;
144
+
145
+ @inject(TaskResolverRegistry)
146
+ protected readonly taskResolverRegistry: TaskResolverRegistry;
147
+
148
+ @inject(TerminalService)
149
+ protected readonly terminalService: TerminalService;
150
+
151
+ @inject(EditorManager)
152
+ protected readonly editorManager: EditorManager;
153
+
154
+ @inject(ProblemManager)
155
+ protected readonly problemManager: ProblemManager;
156
+
157
+ @inject(TaskDefinitionRegistry)
158
+ protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
159
+
160
+ @inject(ProblemMatcherRegistry)
161
+ protected readonly problemMatcherRegistry: ProblemMatcherRegistry;
162
+
163
+ @inject(QuickPickService)
164
+ protected readonly quickPickService: QuickPickService;
165
+
166
+ @inject(OpenerService)
167
+ protected readonly openerService: OpenerService;
168
+
169
+ @inject(ShellTerminalServerProxy)
170
+ protected readonly shellTerminalServer: ShellTerminalServerProxy;
171
+
172
+ @inject(TaskNameResolver)
173
+ protected readonly taskNameResolver: TaskNameResolver;
174
+
175
+ @inject(TaskSourceResolver)
176
+ protected readonly taskSourceResolver: TaskSourceResolver;
177
+
178
+ @inject(TaskSchemaUpdater)
179
+ protected readonly taskSchemaUpdater: TaskSchemaUpdater;
180
+
181
+ @inject(TaskConfigurationManager)
182
+ protected readonly taskConfigurationManager: TaskConfigurationManager;
183
+
184
+ @inject(CommandService)
185
+ protected readonly commands: CommandService;
186
+
187
+ @inject(LabelProvider)
188
+ protected readonly labelProvider: LabelProvider;
189
+
190
+ @inject(MonacoWorkspace)
191
+ protected monacoWorkspace: MonacoWorkspace;
192
+
193
+ @inject(TaskTerminalWidgetManager)
194
+ protected readonly taskTerminalWidgetManager: TaskTerminalWidgetManager;
195
+
196
+ @postConstruct()
197
+ protected init(): void {
198
+ this.getRunningTasks().then(tasks =>
199
+ tasks.forEach(task => {
200
+ if (!this.runningTasks.has(task.taskId)) {
201
+ this.runningTasks.set(task.taskId, {
202
+ exitCode: new Deferred<number | undefined>(), terminateSignal: new Deferred<string | undefined>(),
203
+ isBackgroundTaskEnded: new Deferred<boolean | undefined>()
204
+ });
205
+ }
206
+ }));
207
+
208
+ // notify user that task has started
209
+ this.taskWatcher.onTaskCreated((event: TaskInfo) => {
210
+ if (!this.isEventForThisClient(event.ctx)) {
211
+ return;
212
+ }
213
+ this.runningTasks.set(event.taskId, {
214
+ exitCode: new Deferred<number | undefined>(),
215
+ terminateSignal: new Deferred<string | undefined>(),
216
+ isBackgroundTaskEnded: new Deferred<boolean | undefined>()
217
+ });
218
+ });
219
+
220
+ this.taskWatcher.onOutputProcessed(async (event: TaskOutputProcessedEvent) => {
221
+ if (!this.isEventForThisClient(event.ctx)) {
222
+ return;
223
+ }
224
+ if (event.problems) {
225
+ const runningTasksInfo: TaskInfo[] = await this.getRunningTasks();
226
+ // check if the task is active
227
+ const matchedRunningTaskInfo = runningTasksInfo.find(taskInfo => {
228
+ const taskConfig = taskInfo.config;
229
+ return this.taskDefinitionRegistry.compareTasks(taskConfig, event.config);
230
+ });
231
+ const isTaskActiveAndOutputSilent = matchedRunningTaskInfo &&
232
+ matchedRunningTaskInfo.config.presentation && matchedRunningTaskInfo.config.presentation.reveal === RevealKind.Silent;
233
+ event.problems.forEach(problem => {
234
+ const existingMarkers = this.problemManager.findMarkers({ owner: problem.description.owner });
235
+ const uris = new Set<string>();
236
+ existingMarkers.forEach(marker => uris.add(marker.uri));
237
+ if (ProblemMatchData.is(problem) && problem.resource) {
238
+ // When task.presentation.reveal === RevealKind.Silent, put focus on the terminal only if it is an error
239
+ if (isTaskActiveAndOutputSilent && problem.marker.severity === DiagnosticSeverity.Error) {
240
+ const terminalId = matchedRunningTaskInfo!.terminalId;
241
+ if (terminalId) {
242
+ const terminal = this.terminalService.getByTerminalId(terminalId);
243
+ if (terminal) {
244
+ const focus = !!matchedRunningTaskInfo!.config.presentation!.focus;
245
+ if (focus) { // assign focus to the terminal if presentation.focus is true
246
+ this.terminalService.open(terminal, { mode: 'activate' });
247
+ } else { // show the terminal but not assign focus
248
+ this.terminalService.open(terminal, { mode: 'reveal' });
249
+ }
250
+ }
251
+ }
252
+ }
253
+ const uri = problem.resource.withScheme(problem.resource.scheme);
254
+ const document = this.monacoWorkspace.getTextDocument(uri.toString());
255
+ if (problem.description.applyTo === ApplyToKind.openDocuments && !!document ||
256
+ problem.description.applyTo === ApplyToKind.closedDocuments && !document ||
257
+ problem.description.applyTo === ApplyToKind.allDocuments
258
+ ) {
259
+ if (uris.has(uri.toString())) {
260
+ const newData = [
261
+ ...existingMarkers
262
+ .filter(marker => marker.uri === uri.toString())
263
+ .map(markerData => markerData.data),
264
+ problem.marker
265
+ ];
266
+ this.problemManager.setMarkers(uri, problem.description.owner, newData);
267
+ } else {
268
+ this.problemManager.setMarkers(uri, problem.description.owner, [problem.marker]);
269
+ }
270
+ }
271
+ } else { // should have received an event for finding the "background task begins" pattern
272
+ uris.forEach(uriString => this.problemManager.setMarkers(new URI(uriString), problem.description.owner, []));
273
+ }
274
+ });
275
+ }
276
+ });
277
+
278
+ this.taskWatcher.onBackgroundTaskEnded((event: BackgroundTaskEndedEvent) => {
279
+ if (!this.isEventForThisClient(event.ctx)) {
280
+ return;
281
+ }
282
+
283
+ if (!this.runningTasks.has(event.taskId)) {
284
+ this.runningTasks.set(event.taskId, {
285
+ exitCode: new Deferred<number | undefined>(),
286
+ terminateSignal: new Deferred<string | undefined>(),
287
+ isBackgroundTaskEnded: new Deferred<boolean | undefined>()
288
+ });
289
+ }
290
+ this.runningTasks.get(event.taskId)!.isBackgroundTaskEnded.resolve(true);
291
+ });
292
+
293
+ // notify user that task has finished
294
+ this.taskWatcher.onTaskExit((event: TaskExitedEvent) => {
295
+ if (!this.isEventForThisClient(event.ctx)) {
296
+ return;
297
+ }
298
+ if (!this.runningTasks.has(event.taskId)) {
299
+ this.runningTasks.set(event.taskId, {
300
+ exitCode: new Deferred<number | undefined>(),
301
+ terminateSignal: new Deferred<string | undefined>(),
302
+ isBackgroundTaskEnded: new Deferred<boolean | undefined>()
303
+ });
304
+ }
305
+ this.runningTasks.get(event.taskId)!.exitCode.resolve(event.code);
306
+ this.runningTasks.get(event.taskId)!.terminateSignal.resolve(event.signal);
307
+ setTimeout(() => this.runningTasks.delete(event.taskId), 60 * 1000);
308
+
309
+ const taskConfig = event.config;
310
+ const taskIdentifier = taskConfig ? this.getTaskIdentifier(taskConfig) : event.taskId.toString();
311
+ if (event.code !== undefined) {
312
+ if (event.code !== 0) {
313
+ const eventTaskConfig = event.config;
314
+ if (eventTaskConfig && eventTaskConfig.presentation && eventTaskConfig.presentation.reveal === RevealKind.Silent && event.terminalId) {
315
+ const terminal = this.terminalService.getByTerminalId(event.terminalId);
316
+ const focus = !!eventTaskConfig.presentation.focus;
317
+ if (terminal) {
318
+ if (focus) { // assign focus to the terminal if presentation.focus is true
319
+ this.terminalService.open(terminal, { mode: 'activate' });
320
+ } else { // show the terminal but not assign focus
321
+ this.terminalService.open(terminal, { mode: 'reveal' });
322
+ }
323
+ }
324
+ }
325
+ this.messageService.error(`Task '${taskIdentifier}' has exited with code ${event.code}.`);
326
+ }
327
+ } else if (event.signal !== undefined) {
328
+ this.messageService.info(`Task '${taskIdentifier}' was terminated by signal ${event.signal}.`);
329
+ } else {
330
+ console.error('Invalid TaskExitedEvent received, neither code nor signal is set.');
331
+ }
332
+ });
333
+ }
334
+
335
+ protected getTaskIdentifier(taskConfig: TaskConfiguration): string {
336
+ const taskName = this.taskNameResolver.resolve(taskConfig);
337
+ const sourceStrUri = this.taskSourceResolver.resolve(taskConfig);
338
+ return `${taskName} (${this.labelProvider.getName(new URI(sourceStrUri))})`;
339
+ }
340
+
341
+ /**
342
+ * Client should call this method to indicate that a new user-level action related to tasks has been started,
343
+ * like invoking "Run Task..."
344
+ * This method returns a token that can be used with various methods in this service.
345
+ * As long as a client uses the same token, task providers will only asked once to contribute
346
+ * tasks and the set of tasks will be cached. Each time the a new token is used, the cache of
347
+ * contributed tasks is cleared.
348
+ * @returns a token to be used for task-related actions
349
+ */
350
+ startUserAction(): number {
351
+ return this.providedTaskConfigurations.startUserAction();
352
+ }
353
+
354
+ /**
355
+ * Returns an array of the task configurations configured in tasks.json and provided by the extensions.
356
+ * @param token The cache token for the user interaction in progress
357
+ */
358
+ async getTasks(token: number): Promise<TaskConfiguration[]> {
359
+ const configuredTasks = await this.getConfiguredTasks(token);
360
+ const providedTasks = await this.getProvidedTasks(token);
361
+ const notCustomizedProvidedTasks = providedTasks.filter(provided =>
362
+ !configuredTasks.some(configured => this.taskDefinitionRegistry.compareTasks(configured, provided))
363
+ );
364
+ return [...configuredTasks, ...notCustomizedProvidedTasks];
365
+ }
366
+
367
+ /**
368
+ * Returns an array of the valid task configurations which are configured in tasks.json files
369
+ * @param token The cache token for the user interaction in progress
370
+ *
371
+ */
372
+ async getConfiguredTasks(token: number): Promise<TaskConfiguration[]> {
373
+ const invalidTaskConfig = this.taskConfigurations.getInvalidTaskConfigurations()[0];
374
+ if (invalidTaskConfig) {
375
+ const widget = <ProblemWidget>await this.widgetManager.getOrCreateWidget(PROBLEMS_WIDGET_ID);
376
+ const isProblemsWidgetVisible = widget && widget.isVisible;
377
+ const currentEditorUri = this.editorManager.currentEditor && this.editorManager.currentEditor.editor.getResourceUri();
378
+ let isInvalidTaskConfigFileOpen = false;
379
+ if (currentEditorUri) {
380
+ const folderUri = this.workspaceService.getWorkspaceRootUri(currentEditorUri);
381
+ if (folderUri && folderUri.toString() === invalidTaskConfig._scope) {
382
+ isInvalidTaskConfigFileOpen = true;
383
+ }
384
+ }
385
+ const warningMessage = 'Invalid task configurations are found. Open tasks.json and find details in the Problems view.';
386
+ if (!isProblemsWidgetVisible || !isInvalidTaskConfigFileOpen) {
387
+ this.messageService.warn(warningMessage, 'Open').then(actionOpen => {
388
+ if (actionOpen) {
389
+ if (invalidTaskConfig && invalidTaskConfig._scope) {
390
+ this.taskConfigurationManager.openConfiguration(invalidTaskConfig._scope);
391
+ }
392
+ if (!isProblemsWidgetVisible) {
393
+ this.commands.executeCommand('problemsView:toggle');
394
+ }
395
+ }
396
+ });
397
+ } else {
398
+ this.messageService.warn(warningMessage);
399
+ }
400
+ }
401
+
402
+ const validTaskConfigs = await this.taskConfigurations.getTasks(token);
403
+ return validTaskConfigs;
404
+ }
405
+
406
+ /**
407
+ * Returns an array that contains the task configurations provided by the task providers for the specified task type.
408
+ * @param token The cache token for the user interaction in progress
409
+ * @param type The task type (filter) associated to the returning TaskConfigurations
410
+ *
411
+ * '*' indicates all tasks regardless of the type
412
+ */
413
+ getProvidedTasks(token: number, type?: string): Promise<TaskConfiguration[]> {
414
+ return this.providedTaskConfigurations.getTasks(token, type);
415
+ }
416
+
417
+ addRecentTasks(tasks: TaskConfiguration | TaskConfiguration[]): void {
418
+ if (Array.isArray(tasks)) {
419
+ tasks.forEach(task => this.addRecentTasks(task));
420
+ } else {
421
+ const ind = this.cachedRecentTasks.findIndex(recent => this.taskDefinitionRegistry.compareTasks(recent, tasks));
422
+ if (ind >= 0) {
423
+ this.cachedRecentTasks.splice(ind, 1);
424
+ }
425
+ this.cachedRecentTasks.unshift(tasks);
426
+ }
427
+ }
428
+
429
+ get recentTasks(): TaskConfiguration[] {
430
+ return this.cachedRecentTasks;
431
+ }
432
+
433
+ set recentTasks(recent: TaskConfiguration[]) {
434
+ this.cachedRecentTasks = recent;
435
+ }
436
+
437
+ /**
438
+ * Clears the list of recently used tasks.
439
+ */
440
+ clearRecentTasks(): void {
441
+ this.cachedRecentTasks = [];
442
+ }
443
+
444
+ /**
445
+ * Open user ser
446
+ */
447
+ openUserTasks(): Promise<void> {
448
+ return this.taskConfigurations.openUserTasks();
449
+ }
450
+
451
+ /**
452
+ * Returns a task configuration provided by an extension by task source, scope and label.
453
+ * If there are no task configuration, returns undefined.
454
+ * @param token The cache token for the user interaction in progress
455
+ * @param source The source for configured tasks
456
+ * @param label The label of the task to find
457
+ * @param scope The task scope to look in
458
+ */
459
+ async getProvidedTask(token: number, source: string, label: string, scope: TaskConfigurationScope): Promise<TaskConfiguration | undefined> {
460
+ return this.providedTaskConfigurations.getTask(token, source, label, scope);
461
+ }
462
+
463
+ /** Returns an array of running tasks 'TaskInfo' objects */
464
+ getRunningTasks(): Promise<TaskInfo[]> {
465
+ return this.taskServer.getTasks(this.getContext());
466
+ }
467
+
468
+ async customExecutionComplete(id: number, exitCode: number | undefined): Promise<void> {
469
+ return this.taskServer.customExecutionComplete(id, exitCode);
470
+ }
471
+
472
+ /** Returns an array of task types that are registered, including the default types */
473
+ getRegisteredTaskTypes(): Promise<string[]> {
474
+ return this.taskSchemaUpdater.getRegisteredTaskTypes();
475
+ }
476
+
477
+ /**
478
+ * Get the last executed task.
479
+ *
480
+ * @returns the last executed task or `undefined`.
481
+ */
482
+ getLastTask(): LastRunTaskInfo {
483
+ return this.lastTask;
484
+ }
485
+
486
+ /**
487
+ * Runs a task, by task configuration label.
488
+ * Note, it looks for a task configured in tasks.json only.
489
+ * @param token The cache token for the user interaction in progress
490
+ * @param scope The scope where to look for tasks
491
+ * @param taskLabel the label to look for
492
+ */
493
+ async runConfiguredTask(token: number, scope: TaskConfigurationScope, taskLabel: string): Promise<void> {
494
+ const task = this.taskConfigurations.getTask(scope, taskLabel);
495
+ if (!task) {
496
+ this.logger.error(`Can't get task launch configuration for label: ${taskLabel}`);
497
+ return;
498
+ }
499
+
500
+ this.run(token, task._source, taskLabel, scope);
501
+ }
502
+
503
+ /**
504
+ * Run the last executed task.
505
+ * @param token The cache token for the user interaction in progress
506
+ */
507
+ async runLastTask(token: number): Promise<TaskInfo | undefined> {
508
+ if (!this.lastTask?.resolvedTask) {
509
+ return;
510
+ }
511
+ if (!this.lastTask.resolvedTask.runOptions?.reevaluateOnRerun) {
512
+ return this.runResolvedTask(this.lastTask.resolvedTask, this.lastTask.option);
513
+ }
514
+ const { _source, label, _scope } = this.lastTask.resolvedTask;
515
+ return this.run(token, _source, label, _scope);
516
+ }
517
+
518
+ /**
519
+ * Runs a task, by the source and label of the task configuration.
520
+ * It looks for configured and detected tasks.
521
+ * @param token The cache token for the user interaction in progress
522
+ * @param source The source for configured tasks
523
+ * @param taskLabel The label to look for
524
+ * @param scope The scope where to look for tasks
525
+ */
526
+ async run(token: number, source: string, taskLabel: string, scope: TaskConfigurationScope): Promise<TaskInfo | undefined> {
527
+ let task: TaskConfiguration | undefined;
528
+ task = this.taskConfigurations.getTask(scope, taskLabel);
529
+ if (!task) { // if a configured task cannot be found, search from detected tasks
530
+ task = await this.getProvidedTask(token, source, taskLabel, scope);
531
+ if (!task) { // find from the customized detected tasks
532
+ task = await this.taskConfigurations.getCustomizedTask(token, scope, taskLabel);
533
+ }
534
+ if (!task) {
535
+ this.logger.error(`Can't get task launch configuration for label: ${taskLabel}`);
536
+ return;
537
+ }
538
+ }
539
+ const customizationObject = await this.getTaskCustomization(task);
540
+
541
+ if (!customizationObject.problemMatcher) {
542
+ // ask the user what s/he wants to use to parse the task output
543
+ const items = this.getCustomizeProblemMatcherItems();
544
+ const selected = await this.quickPickService.show(items, {
545
+ placeholder: 'Select for which kind of errors and warnings to scan the task output'
546
+ });
547
+ if (selected && ('value' in selected)) {
548
+ if (selected.value?.problemMatchers) {
549
+ let matcherNames: string[] = [];
550
+ if (selected.value.problemMatchers && selected.value.problemMatchers.length === 0) { // never parse output for this task
551
+ matcherNames = [];
552
+ } else if (selected.value.problemMatchers && selected.value.problemMatchers.length > 0) { // continue with user-selected parser
553
+ matcherNames = selected.value.problemMatchers.map(matcher => matcher.name);
554
+ }
555
+ customizationObject.problemMatcher = matcherNames;
556
+
557
+ // write the selected matcher (or the decision of "never parse") into the `tasks.json`
558
+ this.updateTaskConfiguration(token, task, { problemMatcher: matcherNames });
559
+ } else if (selected.value?.learnMore) { // user wants to learn more about parsing task output
560
+ open(this.openerService, new URI('https://code.visualstudio.com/docs/editor/tasks#_processing-task-output-with-problem-matchers'));
561
+ }
562
+ // else, continue the task with no parser
563
+ } else { // do not start the task in case that the user did not select any item from the list
564
+ return;
565
+ }
566
+ }
567
+
568
+ const resolvedMatchers = await this.resolveProblemMatchers(task, customizationObject);
569
+ const runTaskOption: RunTaskOption = {
570
+ customization: { ...customizationObject, ...{ problemMatcher: resolvedMatchers } }
571
+ };
572
+
573
+ if (task.dependsOn) {
574
+ return this.runCompoundTask(token, task, runTaskOption);
575
+ } else {
576
+ return this.runTask(task, runTaskOption).catch(error => {
577
+ console.error('Error at launching task', error);
578
+ return undefined;
579
+ });
580
+ }
581
+ }
582
+
583
+ /**
584
+ * Runs a compound task
585
+ * @param token The cache token for the user interaction in progress
586
+ * @param task The task to be executed
587
+ * @param option options for executing the task
588
+ */
589
+ async runCompoundTask(token: number, task: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
590
+ const tasks = await this.getWorkspaceTasks(token, task._scope);
591
+ try {
592
+ const rootNode = new TaskNode(task, [], []);
593
+ this.detectDirectedAcyclicGraph(task, rootNode, tasks);
594
+ } catch (error) {
595
+ console.error(`Error at launching task '${task.label}'`, error);
596
+ this.messageService.error(error.message);
597
+ return undefined;
598
+ }
599
+ return this.runTasksGraph(task, tasks, option).catch(error => {
600
+ console.error(`Error at launching task '${task.label}'`, error);
601
+ return undefined;
602
+ });
603
+ }
604
+
605
+ /**
606
+ * A recursive function that runs a task and all its sub tasks that it depends on.
607
+ * A task can be executed only when all of its dependencies have been executed, or when it doesn’t have any dependencies at all.
608
+ */
609
+ async runTasksGraph(task: TaskConfiguration, tasks: TaskConfiguration[], option?: RunTaskOption): Promise<TaskInfo | undefined> {
610
+ if (task && task.dependsOn) {
611
+ // In case it is an array of task dependencies
612
+ if (Array.isArray(task.dependsOn) && task.dependsOn.length > 0) {
613
+ const dependentTasks: { 'task': TaskConfiguration; 'taskCustomization': TaskCustomization; 'resolvedMatchers': ProblemMatcher[] | undefined }[] = [];
614
+ for (let i = 0; i < task.dependsOn.length; i++) {
615
+ // It may be a string (a task label) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
616
+ const taskIdentifier = task.dependsOn[i];
617
+ const dependentTask = this.getDependentTask(taskIdentifier, tasks);
618
+ const taskCustomization = await this.getTaskCustomization(dependentTask);
619
+ const resolvedMatchers = await this.resolveProblemMatchers(dependentTask, taskCustomization);
620
+ dependentTasks.push({ 'task': dependentTask, 'taskCustomization': taskCustomization, 'resolvedMatchers': resolvedMatchers });
621
+ // In case the 'dependsOrder' is 'sequence'
622
+ if (task.dependsOrder && task.dependsOrder === DependsOrder.Sequence) {
623
+ await this.runTasksGraph(dependentTask, tasks, {
624
+ customization: { ...taskCustomization, ...{ problemMatcher: resolvedMatchers } }
625
+ });
626
+ }
627
+ }
628
+ // In case the 'dependsOrder' is 'parallel'
629
+ if (((!task.dependsOrder) || (task.dependsOrder && task.dependsOrder === DependsOrder.Parallel))) {
630
+ const promises = dependentTasks.map(item =>
631
+ this.runTasksGraph(item.task, tasks, {
632
+ customization: { ...item.taskCustomization, ...{ problemMatcher: item.resolvedMatchers } }
633
+ })
634
+ );
635
+ await Promise.all(promises);
636
+ }
637
+ } else if (!Array.isArray(task.dependsOn)) {
638
+ // In case it is a string (a task label) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
639
+ const taskIdentifier = task.dependsOn;
640
+ const dependentTask = this.getDependentTask(taskIdentifier, tasks);
641
+ const taskCustomization = await this.getTaskCustomization(dependentTask);
642
+ const resolvedMatchers = await this.resolveProblemMatchers(dependentTask, taskCustomization);
643
+ await this.runTasksGraph(dependentTask, tasks, {
644
+ customization: { ...taskCustomization, ...{ problemMatcher: resolvedMatchers } }
645
+ });
646
+ }
647
+ }
648
+
649
+ const taskInfo = await this.runTask(task, option);
650
+ if (taskInfo) {
651
+ const getExitCodePromise: Promise<TaskEndedInfo> = this.getExitCode(taskInfo.taskId).then(result => ({ taskEndedType: TaskEndedTypes.TaskExited, value: result }));
652
+ const isBackgroundTaskEndedPromise: Promise<TaskEndedInfo> = this.isBackgroundTaskEnded(taskInfo.taskId).then(result =>
653
+ ({ taskEndedType: TaskEndedTypes.BackgroundTaskEnded, value: result }));
654
+
655
+ // After start running the task, we wait for the task process to exit and if it is a background task, we also wait for a feedback
656
+ // that a background task is active, as soon as one of the promises fulfills, we can continue and analyze the results.
657
+ const taskEndedInfo: TaskEndedInfo = await Promise.race([getExitCodePromise, isBackgroundTaskEndedPromise]);
658
+
659
+ if ((taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value !== 0) ||
660
+ (taskEndedInfo.taskEndedType === TaskEndedTypes.BackgroundTaskEnded && !taskEndedInfo.value)) {
661
+ throw new Error('The task: ' + task.label + ' terminated with exit code ' + taskEndedInfo.value + '.');
662
+ }
663
+ }
664
+ return taskInfo;
665
+ }
666
+
667
+ /**
668
+ * Creates a graph of dependencies tasks from the root task and verify there is no DAG (Directed Acyclic Graph).
669
+ * In case of detection of a circular dependency, an error is thrown with a message which describes the detected circular reference.
670
+ */
671
+ detectDirectedAcyclicGraph(task: TaskConfiguration, taskNode: TaskNode, tasks: TaskConfiguration[]): void {
672
+ if (task && task.dependsOn) {
673
+ // In case the 'dependsOn' is an array
674
+ if (Array.isArray(task.dependsOn) && task.dependsOn.length > 0) {
675
+ for (let i = 0; i < task.dependsOn.length; i++) {
676
+ const childNode = this.createChildTaskNode(task, taskNode, task.dependsOn[i], tasks);
677
+ this.detectDirectedAcyclicGraph(childNode.taskConfiguration, childNode.node, tasks);
678
+ }
679
+ } else if (!Array.isArray(task.dependsOn)) {
680
+ const childNode = this.createChildTaskNode(task, taskNode, task.dependsOn, tasks);
681
+ this.detectDirectedAcyclicGraph(childNode.taskConfiguration, childNode.node, tasks);
682
+ }
683
+ }
684
+ }
685
+
686
+ // 'childTaskIdentifier' may be a string (a task label) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
687
+ createChildTaskNode(task: TaskConfiguration, taskNode: TaskNode, childTaskIdentifier: string | TaskIdentifier, tasks: TaskConfiguration[]): TaskGraphNode {
688
+ const childTaskConfiguration = this.getDependentTask(childTaskIdentifier, tasks);
689
+
690
+ // If current task and child task are identical or if
691
+ // one of the child tasks is identical to one of the current task ancestors, then raise an error
692
+ if (this.taskDefinitionRegistry.compareTasks(task, childTaskConfiguration) ||
693
+ taskNode.parentsID.filter(t => this.taskDefinitionRegistry.compareTasks(childTaskConfiguration, t)).length > 0) {
694
+ const fromNode = task.label;
695
+ const toNode = childTaskConfiguration.label;
696
+ throw new Error('Circular reference detected: ' + fromNode + ' --> ' + toNode);
697
+ }
698
+ const childNode = new TaskNode(childTaskConfiguration, [], Object.assign([], taskNode.parentsID));
699
+ childNode.addParentDependency(taskNode.taskId);
700
+ taskNode.addChildDependency(childNode);
701
+ return { 'taskConfiguration': childTaskConfiguration, 'node': childNode };
702
+ }
703
+
704
+ /**
705
+ * Gets task configuration by task label or by a JSON object which represents a task identifier
706
+ *
707
+ * @param taskIdentifier The task label (string) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
708
+ * @param tasks an array of the task configurations
709
+ * @returns the correct TaskConfiguration object which matches the taskIdentifier
710
+ */
711
+ getDependentTask(taskIdentifier: string | TaskIdentifier, tasks: TaskConfiguration[]): TaskConfiguration {
712
+ const notEnoughDataError = 'The information provided in the "dependsOn" is not enough for matching the correct task !';
713
+ let currentTaskChildConfiguration: TaskConfiguration;
714
+ if (typeof (taskIdentifier) !== 'string') {
715
+ // TaskIdentifier object does not support tasks of type 'shell' (The same behavior as in VS Code).
716
+ // So if we want the 'dependsOn' property to include tasks of type 'shell',
717
+ // then we must mention their labels (in the 'dependsOn' property) and not to create a task identifier object for them.
718
+ currentTaskChildConfiguration = this.getTaskByTaskIdentifier(taskIdentifier, tasks);
719
+ if (!currentTaskChildConfiguration.type) {
720
+ this.messageService.error(notEnoughDataError);
721
+ throw new Error(notEnoughDataError);
722
+ }
723
+ return currentTaskChildConfiguration;
724
+ } else {
725
+ currentTaskChildConfiguration = tasks.filter(t => taskIdentifier === this.taskNameResolver.resolve(t))[0];
726
+ return currentTaskChildConfiguration;
727
+ }
728
+ }
729
+
730
+ /**
731
+ * Gets the matched task from an array of task configurations by TaskIdentifier.
732
+ * In case that more than one task configuration matches, we returns the first one.
733
+ *
734
+ * @param taskIdentifier The task label (string) or a JSON object which represents a TaskIdentifier (e.g. {"type":"npm", "script":"script1"})
735
+ * @param tasks An array of task configurations.
736
+ * @returns The correct TaskConfiguration object which matches the taskIdentifier.
737
+ */
738
+ getTaskByTaskIdentifier(taskIdentifier: TaskIdentifier, tasks: TaskConfiguration[]): TaskConfiguration {
739
+ const requiredProperties = Object.keys(taskIdentifier);
740
+ const taskWithAllProperties = tasks.find(task => requiredProperties.every(property => task.hasOwnProperty(property) && task[property] === taskIdentifier[property]));
741
+ return taskWithAllProperties ?? { label: '', _scope: '', type: '' }; // Fall back to empty TaskConfiguration
742
+ }
743
+
744
+ async runTask(task: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
745
+ console.debug('entering runTask');
746
+ const releaseLock = await this.taskStartingLock.acquire();
747
+ console.debug('got lock');
748
+
749
+ try {
750
+ // resolve problemMatchers
751
+ if (!option && task.problemMatcher) {
752
+ const customizationObject: TaskCustomization = { type: task.taskType, problemMatcher: task.problemMatcher, runOptions: task.runOptions };
753
+ const resolvedMatchers = await this.resolveProblemMatchers(task, customizationObject);
754
+ option = {
755
+ customization: { ...customizationObject, ...{ problemMatcher: resolvedMatchers } }
756
+ };
757
+ }
758
+
759
+ const runningTasksInfo: TaskInfo[] = await this.getRunningTasks();
760
+ // check if the task is active
761
+ const matchedRunningTaskInfo = runningTasksInfo.find(taskInfo => {
762
+ const taskConfig = taskInfo.config;
763
+ return this.taskDefinitionRegistry.compareTasks(taskConfig, task);
764
+ });
765
+ console.debug(`running task ${JSON.stringify(task)}, already running = ${!!matchedRunningTaskInfo}`);
766
+
767
+ if (matchedRunningTaskInfo) { // the task is active
768
+ releaseLock();
769
+ console.debug('released lock');
770
+ const taskName = this.taskNameResolver.resolve(task);
771
+ const terminalId = matchedRunningTaskInfo.terminalId;
772
+ if (terminalId) {
773
+ const terminal = this.terminalService.getByTerminalId(terminalId);
774
+ if (terminal) {
775
+ if (TaskOutputPresentation.shouldSetFocusToTerminal(task)) { // assign focus to the terminal if presentation.focus is true
776
+ this.terminalService.open(terminal, { mode: 'activate' });
777
+ } else if (TaskOutputPresentation.shouldAlwaysRevealTerminal(task)) { // show the terminal but not assign focus
778
+ this.terminalService.open(terminal, { mode: 'reveal' });
779
+ }
780
+ }
781
+ }
782
+ const selectedAction = await this.messageService.info(`The task '${taskName}' is already active`, 'Terminate Task', 'Restart Task');
783
+ if (selectedAction === 'Terminate Task') {
784
+ await this.terminateTask(matchedRunningTaskInfo);
785
+ } else if (selectedAction === 'Restart Task') {
786
+ return this.restartTask(matchedRunningTaskInfo, option);
787
+ }
788
+ } else { // run task as the task is not active
789
+ console.debug('task about to start');
790
+ const taskInfo = await this.doRunTask(task, option);
791
+ releaseLock();
792
+ console.debug('release lock 2');
793
+ return taskInfo;
794
+ }
795
+ } catch (e) {
796
+ releaseLock();
797
+ throw e;
798
+ }
799
+ }
800
+
801
+ /**
802
+ * Terminates a task that is actively running.
803
+ * @param activeTaskInfo the TaskInfo of the task that is actively running
804
+ */
805
+ async terminateTask(activeTaskInfo: TaskInfo): Promise<void> {
806
+ const taskId = activeTaskInfo.taskId;
807
+ return this.kill(taskId);
808
+ }
809
+
810
+ /**
811
+ * Terminates a task that is actively running, and restarts it.
812
+ * @param activeTaskInfo the TaskInfo of the task that is actively running
813
+ */
814
+ async restartTask(activeTaskInfo: TaskInfo, option?: RunTaskOption): Promise<TaskInfo | undefined> {
815
+ await this.terminateTask(activeTaskInfo);
816
+ return this.doRunTask(activeTaskInfo.config, option);
817
+ }
818
+
819
+ protected async doRunTask(task: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
820
+ let overridePropertiesFunction: (task: TaskConfiguration) => void = () => { };
821
+ if (option && option.customization) {
822
+ const taskDefinition = this.taskDefinitionRegistry.getDefinition(task);
823
+ if (taskDefinition) { // use the customization object to override the task config
824
+ overridePropertiesFunction = tsk => {
825
+ Object.keys(option.customization!).forEach(customizedProperty => {
826
+ // properties used to define the task cannot be customized
827
+ if (customizedProperty !== 'type' && !taskDefinition.properties.all.some(pDefinition => pDefinition === customizedProperty)) {
828
+ tsk[customizedProperty] = option.customization![customizedProperty];
829
+ }
830
+ });
831
+ };
832
+ }
833
+ }
834
+ overridePropertiesFunction(task);
835
+ this.addRecentTasks(task);
836
+ try {
837
+ const resolver = await this.taskResolverRegistry.getTaskResolver(task.type);
838
+ const resolvedTask = resolver ? await resolver.resolveTask(task) : task;
839
+ const executionResolver = this.taskResolverRegistry.getExecutionResolver(resolvedTask.taskType || resolvedTask.type);
840
+ overridePropertiesFunction(resolvedTask);
841
+ const taskToRun = executionResolver ? await executionResolver.resolveTask(resolvedTask) : resolvedTask;
842
+
843
+ await this.removeProblemMarkers(option);
844
+ return this.runResolvedTask(taskToRun, option);
845
+ } catch (error) {
846
+ const errMessage = `Error resolving task '${task.label}': ${error}`;
847
+ this.logger.error(errMessage);
848
+ }
849
+ return undefined;
850
+ }
851
+
852
+ /**
853
+ * Runs the first task with the given label.
854
+ *
855
+ * @param token The cache token for the user interaction in progress
856
+ * @param taskLabel The label of the task to be executed
857
+ */
858
+ async runTaskByLabel(token: number, taskLabel: string): Promise<TaskInfo | undefined> {
859
+ const tasks: TaskConfiguration[] = await this.getTasks(token);
860
+ for (const task of tasks) {
861
+ if (task.label === taskLabel) {
862
+ return this.runTask(task);
863
+ }
864
+ }
865
+ return;
866
+ }
867
+
868
+ /**
869
+ * Runs a task identified by the given identifier, but only if found in the given workspace folder
870
+ *
871
+ * @param token The cache token for the user interaction in progress
872
+ * @param workspaceFolderUri The folder to restrict the search to
873
+ * @param taskIdentifier The identifier to look for
874
+ */
875
+ async runWorkspaceTask(token: number, workspaceFolderUri: string | undefined, taskIdentifier: string | TaskIdentifier): Promise<TaskInfo | undefined> {
876
+ const tasks = await this.getWorkspaceTasks(token, workspaceFolderUri);
877
+ const task = this.getDependentTask(taskIdentifier, tasks);
878
+ if (!task) {
879
+ return undefined;
880
+ }
881
+
882
+ const taskCustomization = await this.getTaskCustomization(task);
883
+ const resolvedMatchers = await this.resolveProblemMatchers(task, taskCustomization);
884
+ try {
885
+ const rootNode = new TaskNode(task, [], []);
886
+ this.detectDirectedAcyclicGraph(task, rootNode, tasks);
887
+ } catch (error) {
888
+ this.logger.error(error.message);
889
+ this.messageService.error(error.message);
890
+ return undefined;
891
+ }
892
+ return this.runTasksGraph(task, tasks, {
893
+ customization: { ...taskCustomization, ...{ problemMatcher: resolvedMatchers } }
894
+ }).catch(error => {
895
+ console.log(error.message);
896
+ return undefined;
897
+ });
898
+ }
899
+
900
+ /**
901
+ * Updates the task configuration in the `tasks.json`.
902
+ * The task config, together with updates, will be written into the `tasks.json` if it is not found in the file.
903
+ *
904
+ * @param token The cache token for the user interaction in progress
905
+ * @param task task that the updates will be applied to
906
+ * @param update the updates to be applied
907
+ */
908
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
909
+ async updateTaskConfiguration(token: number, task: TaskConfiguration, update: { [name: string]: any }): Promise<void> {
910
+ if (update.problemMatcher) {
911
+ if (Array.isArray(update.problemMatcher)) {
912
+ update.problemMatcher.forEach((_name, index) => update.problemMatcher[index] = asVariableName(update.problemMatcher[index]));
913
+ } else {
914
+ update.problemMatcher = asVariableName(update.problemMatcher);
915
+ }
916
+ }
917
+ this.taskConfigurations.updateTaskConfig(token, task, update);
918
+ }
919
+
920
+ protected async getWorkspaceTasks(token: number, restrictToFolder: TaskConfigurationScope | undefined): Promise<TaskConfiguration[]> {
921
+ const tasks = await this.getTasks(token);
922
+ // if we pass undefined, return everything, otherwise only tasks with the same uri or workspace/global scope tasks
923
+ return tasks.filter(t => typeof t._scope !== 'string' || t._scope === restrictToFolder);
924
+ }
925
+
926
+ protected async resolveProblemMatchers(task: TaskConfiguration, customizationObject: TaskCustomization): Promise<ProblemMatcher[] | undefined> {
927
+ const notResolvedMatchers = customizationObject.problemMatcher ?
928
+ (Array.isArray(customizationObject.problemMatcher) ? customizationObject.problemMatcher : [customizationObject.problemMatcher]) : undefined;
929
+ let resolvedMatchers: ProblemMatcher[] | undefined = [];
930
+ if (notResolvedMatchers) {
931
+ // resolve matchers before passing them to the server
932
+ for (const matcher of notResolvedMatchers) {
933
+ let resolvedMatcher: ProblemMatcher | undefined;
934
+ await this.problemMatcherRegistry.onReady();
935
+ if (typeof matcher === 'string') {
936
+ resolvedMatcher = this.problemMatcherRegistry.get(matcher);
937
+ } else {
938
+ resolvedMatcher = await this.problemMatcherRegistry.getProblemMatcherFromContribution(matcher);
939
+ }
940
+ if (resolvedMatcher) {
941
+ const scope = task._scope || task._source;
942
+ if (resolvedMatcher.filePrefix && scope) {
943
+ const options = {
944
+ context: new URI(scope).withScheme('file'),
945
+ configurationSection: 'tasks'
946
+ };
947
+ const resolvedPrefix = await this.variableResolverService.resolve(resolvedMatcher.filePrefix, options);
948
+ Object.assign(resolvedMatcher, { filePrefix: resolvedPrefix });
949
+ }
950
+ resolvedMatchers.push(resolvedMatcher);
951
+ }
952
+ }
953
+ } else {
954
+ resolvedMatchers = undefined;
955
+ }
956
+ return resolvedMatchers;
957
+ }
958
+
959
+ protected async getTaskCustomization(task: TaskConfiguration): Promise<TaskCustomization> {
960
+ const customizationObject: TaskCustomization = { type: '', _scope: task._scope, runOptions: task.runOptions };
961
+ const customizationFound = this.taskConfigurations.getCustomizationForTask(task);
962
+ if (customizationFound) {
963
+ Object.assign(customizationObject, customizationFound);
964
+ } else {
965
+ Object.assign(customizationObject, {
966
+ type: task.type,
967
+ problemMatcher: task.problemMatcher
968
+ });
969
+ }
970
+ return customizationObject;
971
+ }
972
+
973
+ protected async removeProblemMarkers(option?: RunTaskOption): Promise<void> {
974
+ if (option && option.customization) {
975
+ const matchersFromOption = option.customization.problemMatcher || [];
976
+ for (const matcher of matchersFromOption) {
977
+ if (matcher && matcher.owner) {
978
+ const existingMarkers = this.problemManager.findMarkers({ owner: matcher.owner });
979
+ const uris = new Set<string>();
980
+ existingMarkers.forEach(marker => uris.add(marker.uri));
981
+ uris.forEach(uriString => this.problemManager.setMarkers(new URI(uriString), matcher.owner, []));
982
+ }
983
+ }
984
+ }
985
+ }
986
+
987
+ /**
988
+ * Runs the resolved task and opens terminal widget if the task is based on a terminal process
989
+ * @param resolvedTask the resolved task
990
+ * @param option options to run the resolved task
991
+ */
992
+ protected async runResolvedTask(resolvedTask: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
993
+ const taskLabel = resolvedTask.label;
994
+ let taskInfo: TaskInfo | undefined;
995
+ try {
996
+ taskInfo = await this.taskServer.run(resolvedTask, this.getContext(), option);
997
+ this.lastTask = { resolvedTask, option };
998
+ this.logger.debug(`Task created. Task id: ${taskInfo.taskId}`);
999
+
1000
+ /**
1001
+ * open terminal widget if the task is based on a terminal process (type: 'shell' or 'process')
1002
+ *
1003
+ * @todo Use a different mechanism to determine if the task should be attached?
1004
+ * Reason: Maybe a new task type wants to also be displayed in a terminal.
1005
+ */
1006
+ if (typeof taskInfo.terminalId === 'number') {
1007
+ await this.attach(taskInfo.terminalId, taskInfo);
1008
+ }
1009
+ return taskInfo;
1010
+ } catch (error) {
1011
+ const errorStr = `Error launching task '${taskLabel}': ${error.message}`;
1012
+ this.logger.error(errorStr);
1013
+ this.messageService.error(errorStr);
1014
+ if (taskInfo && typeof taskInfo.terminalId === 'number') {
1015
+ this.shellTerminalServer.onAttachAttempted(taskInfo.terminalId);
1016
+ }
1017
+ }
1018
+ }
1019
+
1020
+ protected getCustomizeProblemMatcherItems(): Array<QuickPickValue<QuickPickProblemMatcherItem> | QuickPickItemOrSeparator> {
1021
+ const items: Array<QuickPickValue<QuickPickProblemMatcherItem> | QuickPickItemOrSeparator> = [];
1022
+ items.push({
1023
+ label: 'Continue without scanning the task output',
1024
+ value: { problemMatchers: undefined }
1025
+ });
1026
+ items.push({
1027
+ label: 'Never scan the task output',
1028
+ value: { problemMatchers: [] }
1029
+ });
1030
+ items.push({
1031
+ label: 'Learn more about scanning the task output',
1032
+ value: { problemMatchers: undefined, learnMore: true }
1033
+ });
1034
+ items.push({ type: 'separator', label: 'registered parsers' });
1035
+
1036
+ const registeredProblemMatchers = this.problemMatcherRegistry.getAll();
1037
+ items.push(...registeredProblemMatchers.map(matcher =>
1038
+ ({
1039
+ label: matcher.label,
1040
+ value: { problemMatchers: [matcher] },
1041
+ description: asVariableName(matcher.name)
1042
+ })
1043
+ ));
1044
+ return items;
1045
+ }
1046
+
1047
+ /**
1048
+ * Run selected text in the last active terminal.
1049
+ */
1050
+ async runSelectedText(): Promise<void> {
1051
+ if (!this.editorManager.currentEditor) { return; }
1052
+ const startLine = this.editorManager.currentEditor.editor.selection.start.line;
1053
+ const startCharacter = this.editorManager.currentEditor.editor.selection.start.character;
1054
+ const endLine = this.editorManager.currentEditor.editor.selection.end.line;
1055
+ const endCharacter = this.editorManager.currentEditor.editor.selection.end.character;
1056
+ let selectedRange: Range = Range.create(startLine, startCharacter, endLine, endCharacter);
1057
+ // if no text is selected, default to selecting entire line
1058
+ if (startLine === endLine && startCharacter === endCharacter) {
1059
+ selectedRange = Range.create(startLine, 0, endLine + 1, 0);
1060
+ }
1061
+ const selectedText: string = this.editorManager.currentEditor.editor.document.getText(selectedRange).trimRight() + '\n';
1062
+ let terminal = this.terminalService.lastUsedTerminal;
1063
+ if (!terminal || terminal.kind !== 'user' || (await terminal.hasChildProcesses())) {
1064
+ terminal = <TerminalWidget>await this.terminalService.newTerminal(<TerminalWidgetFactoryOptions>{ created: new Date().toString() });
1065
+ await terminal.start();
1066
+ this.terminalService.open(terminal);
1067
+ }
1068
+ terminal.sendText(selectedText);
1069
+ }
1070
+
1071
+ async attach(terminalId: number, taskInfo: TaskInfo): Promise<number | void> {
1072
+ let widgetOpenMode: WidgetOpenMode = 'open';
1073
+ if (taskInfo) {
1074
+ const terminalWidget = this.terminalService.getByTerminalId(terminalId);
1075
+ if (terminalWidget) {
1076
+ this.messageService.error('Task is already running in terminal');
1077
+ return this.terminalService.open(terminalWidget, { mode: 'activate' });
1078
+ }
1079
+ if (TaskOutputPresentation.shouldAlwaysRevealTerminal(taskInfo.config)) {
1080
+ if (TaskOutputPresentation.shouldSetFocusToTerminal(taskInfo.config)) { // assign focus to the terminal if presentation.focus is true
1081
+ widgetOpenMode = 'activate';
1082
+ } else { // show the terminal but not assign focus
1083
+ widgetOpenMode = 'reveal';
1084
+ }
1085
+ }
1086
+ }
1087
+ const { taskId } = taskInfo;
1088
+ // Create / find a terminal widget to display an execution output of a task that was launched as a command inside a shell.
1089
+ const widget = await this.taskTerminalWidgetManager.open({
1090
+ created: new Date().toString(),
1091
+ id: this.getTerminalWidgetId(terminalId),
1092
+ title: taskInfo
1093
+ ? `Task: ${taskInfo.config.label}`
1094
+ : `Task: #${taskId}`,
1095
+ destroyTermOnClose: true,
1096
+ useServerTitle: false
1097
+ }, {
1098
+ widgetOptions: { area: 'bottom' },
1099
+ mode: widgetOpenMode,
1100
+ taskInfo
1101
+ });
1102
+ return widget.start(terminalId);
1103
+ }
1104
+
1105
+ protected getTerminalWidgetId(terminalId: number): string | undefined {
1106
+ const terminalWidget = this.terminalService.getByTerminalId(terminalId);
1107
+ if (terminalWidget) {
1108
+ return terminalWidget.id;
1109
+ }
1110
+ }
1111
+
1112
+ /**
1113
+ * Opens an editor to configure the given task.
1114
+ *
1115
+ * @param token The cache token for the user interaction in progress
1116
+ * @param task The task to configure
1117
+ */
1118
+ async configure(token: number, task: TaskConfiguration): Promise<void> {
1119
+ Object.assign(task, { label: this.taskNameResolver.resolve(task) });
1120
+ await this.taskConfigurations.configure(token, task);
1121
+ }
1122
+
1123
+ protected isEventForThisClient(context: string | undefined): boolean {
1124
+ if (context === this.getContext()) {
1125
+ return true;
1126
+ }
1127
+ return false;
1128
+ }
1129
+
1130
+ taskConfigurationChanged(event: string[]): void {
1131
+ // do nothing for now
1132
+ }
1133
+
1134
+ protected getContext(): string | undefined {
1135
+ return this.workspaceService.workspace?.resource.toString();
1136
+ }
1137
+
1138
+ /** Kill task for a given id if task is found */
1139
+ async kill(id: number): Promise<void> {
1140
+ try {
1141
+ await this.taskServer.kill(id);
1142
+ } catch (error) {
1143
+ this.logger.error(`Error killing task '${id}': ${error}`);
1144
+ this.messageService.error(`Error killing task '${id}': ${error}`);
1145
+ return;
1146
+ }
1147
+ this.logger.debug(`Task killed. Task id: ${id}`);
1148
+ }
1149
+
1150
+ async isBackgroundTaskEnded(id: number): Promise<boolean | undefined> {
1151
+ const completedTask = this.runningTasks.get(id);
1152
+ return completedTask && completedTask.isBackgroundTaskEnded!.promise;
1153
+ }
1154
+
1155
+ async getExitCode(id: number): Promise<number | undefined> {
1156
+ const completedTask = this.runningTasks.get(id);
1157
+ return completedTask && completedTask.exitCode.promise;
1158
+ }
1159
+
1160
+ async getTerminateSignal(id: number): Promise<string | undefined> {
1161
+ const completedTask = this.runningTasks.get(id);
1162
+ return completedTask && completedTask.terminateSignal.promise;
1163
+ }
1164
+ }