@theia/task 1.53.0-next.4 → 1.53.0-next.55

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 (60) hide show
  1. package/README.md +193 -193
  2. package/lib/browser/task-schema-updater.js +1 -1
  3. package/package.json +13 -13
  4. package/src/browser/index.ts +22 -22
  5. package/src/browser/process/process-task-contribution.ts +31 -31
  6. package/src/browser/process/process-task-frontend-module.ts +27 -27
  7. package/src/browser/process/process-task-resolver.ts +89 -89
  8. package/src/browser/provided-task-configurations.spec.ts +46 -46
  9. package/src/browser/provided-task-configurations.ts +213 -213
  10. package/src/browser/quick-open-task.ts +831 -831
  11. package/src/browser/style/index.css +19 -19
  12. package/src/browser/task-configuration-manager.ts +256 -256
  13. package/src/browser/task-configuration-model.ts +101 -101
  14. package/src/browser/task-configurations.ts +508 -508
  15. package/src/browser/task-contribution.ts +266 -266
  16. package/src/browser/task-definition-registry.spec.ts +203 -203
  17. package/src/browser/task-definition-registry.ts +131 -131
  18. package/src/browser/task-frontend-contribution.ts +402 -402
  19. package/src/browser/task-frontend-module.ts +86 -86
  20. package/src/browser/task-name-resolver.ts +55 -55
  21. package/src/browser/task-node.ts +37 -37
  22. package/src/browser/task-preferences.ts +40 -40
  23. package/src/browser/task-problem-matcher-registry.ts +308 -308
  24. package/src/browser/task-problem-pattern-registry.ts +196 -196
  25. package/src/browser/task-schema-updater.ts +701 -701
  26. package/src/browser/task-service.ts +1164 -1164
  27. package/src/browser/task-source-resolver.ts +36 -36
  28. package/src/browser/task-templates.ts +168 -168
  29. package/src/browser/task-terminal-widget-manager.ts +224 -224
  30. package/src/browser/tasks-monaco-contribution.ts +27 -27
  31. package/src/common/index.ts +20 -20
  32. package/src/common/problem-matcher-protocol.ts +234 -234
  33. package/src/common/process/task-protocol.ts +97 -97
  34. package/src/common/task-common-module.ts +34 -34
  35. package/src/common/task-protocol.ts +317 -317
  36. package/src/common/task-util.ts +43 -43
  37. package/src/common/task-watcher.ts +78 -78
  38. package/src/node/custom/custom-task-runner-backend-module.ts +37 -37
  39. package/src/node/custom/custom-task-runner-contribution.ts +30 -30
  40. package/src/node/custom/custom-task-runner.ts +60 -60
  41. package/src/node/custom/custom-task.ts +73 -73
  42. package/src/node/index.ts +19 -19
  43. package/src/node/process/process-task-runner-backend-module.ts +37 -37
  44. package/src/node/process/process-task-runner-contribution.ts +31 -31
  45. package/src/node/process/process-task-runner.ts +371 -371
  46. package/src/node/process/process-task.spec.ts +30 -30
  47. package/src/node/process/process-task.ts +144 -144
  48. package/src/node/task-abstract-line-matcher.ts +312 -312
  49. package/src/node/task-backend-application-contribution.ts +36 -36
  50. package/src/node/task-backend-module.ts +57 -57
  51. package/src/node/task-line-matchers.ts +127 -127
  52. package/src/node/task-manager.ts +129 -129
  53. package/src/node/task-problem-collector.spec.ts +338 -338
  54. package/src/node/task-problem-collector.ts +62 -62
  55. package/src/node/task-runner-protocol.ts +33 -33
  56. package/src/node/task-runner.ts +96 -96
  57. package/src/node/task-server.slow-spec.ts +444 -444
  58. package/src/node/task-server.ts +263 -263
  59. package/src/node/task.ts +103 -103
  60. package/src/node/test/task-test-container.ts +63 -63
@@ -1,402 +1,402 @@
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 { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
18
- import { ILogger, ContributionProvider, CommandContribution, Command, CommandRegistry, MenuContribution, MenuModelRegistry, nls } from '@theia/core/lib/common';
19
- import { QuickOpenTask, TaskTerminateQuickOpen, TaskRunningQuickOpen, TaskRestartRunningQuickOpen } from './quick-open-task';
20
- import {
21
- FrontendApplication, FrontendApplicationContribution, QuickAccessContribution,
22
- KeybindingRegistry, KeybindingContribution, StorageService, StatusBar, StatusBarAlignment, CommonMenus
23
- } from '@theia/core/lib/browser';
24
- import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
25
- import { TaskContribution, TaskResolverRegistry, TaskProviderRegistry } from './task-contribution';
26
- import { TaskService } from './task-service';
27
- import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
28
- import { TaskSchemaUpdater } from './task-schema-updater';
29
- import { TaskConfiguration, TaskWatcher } from '../common';
30
- import { EditorManager } from '@theia/editor/lib/browser';
31
- import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
32
-
33
- export namespace TaskCommands {
34
- const TASK_CATEGORY = 'Task';
35
- const TASK_CATEGORY_KEY = nls.getDefaultKey(TASK_CATEGORY);
36
- export const TASK_RUN = Command.toDefaultLocalizedCommand({
37
- id: 'task:run',
38
- category: TASK_CATEGORY,
39
- label: 'Run Task...'
40
- });
41
-
42
- export const TASK_RUN_BUILD = Command.toDefaultLocalizedCommand({
43
- id: 'task:run:build',
44
- category: TASK_CATEGORY,
45
- label: 'Run Build Task'
46
- });
47
-
48
- export const TASK_RUN_TEST = Command.toDefaultLocalizedCommand({
49
- id: 'task:run:test',
50
- category: TASK_CATEGORY,
51
- label: 'Run Test Task'
52
- });
53
-
54
- export const WORKBENCH_RUN_TASK = Command.toLocalizedCommand({
55
- id: 'workbench.action.tasks.runTask',
56
- category: TASK_CATEGORY
57
- }, '', TASK_CATEGORY_KEY);
58
-
59
- export const TASK_RUN_LAST = Command.toDefaultLocalizedCommand({
60
- id: 'task:run:last',
61
- category: TASK_CATEGORY,
62
- label: 'Rerun Last Task'
63
- });
64
-
65
- export const TASK_ATTACH = Command.toLocalizedCommand({
66
- id: 'task:attach',
67
- category: TASK_CATEGORY,
68
- label: 'Attach Task...'
69
- }, 'theia/task/attachTask', TASK_CATEGORY_KEY);
70
-
71
- export const TASK_RUN_TEXT = Command.toDefaultLocalizedCommand({
72
- id: 'task:run:text',
73
- category: TASK_CATEGORY,
74
- label: 'Run Selected Text'
75
- });
76
-
77
- export const TASK_CONFIGURE = Command.toDefaultLocalizedCommand({
78
- id: 'task:configure',
79
- category: TASK_CATEGORY,
80
- label: 'Configure Tasks...'
81
- });
82
-
83
- export const TASK_OPEN_USER = Command.toLocalizedCommand({
84
- id: 'task:open_user',
85
- category: TASK_CATEGORY,
86
- label: 'Open User Tasks'
87
- }, 'theia/task/openUserTasks', TASK_CATEGORY_KEY);
88
-
89
- export const TASK_CLEAR_HISTORY = Command.toLocalizedCommand({
90
- id: 'task:clear-history',
91
- category: TASK_CATEGORY,
92
- label: 'Clear History'
93
- }, 'theia/task/clearHistory', TASK_CATEGORY_KEY);
94
-
95
- export const TASK_SHOW_RUNNING = Command.toDefaultLocalizedCommand({
96
- id: 'task:show-running',
97
- category: TASK_CATEGORY,
98
- label: 'Show Running Tasks'
99
- });
100
-
101
- export const TASK_TERMINATE = Command.toDefaultLocalizedCommand({
102
- id: 'task:terminate',
103
- category: TASK_CATEGORY,
104
- label: 'Terminate Task'
105
- });
106
-
107
- export const TASK_RESTART_RUNNING = Command.toDefaultLocalizedCommand({
108
- id: 'task:restart-running',
109
- category: TASK_CATEGORY,
110
- label: 'Restart Running Task...'
111
- });
112
- }
113
-
114
- const TASKS_STORAGE_KEY = 'tasks';
115
-
116
- @injectable()
117
- export class TaskFrontendContribution implements CommandContribution, MenuContribution, KeybindingContribution, FrontendApplicationContribution, QuickAccessContribution {
118
- @inject(QuickOpenTask)
119
- protected readonly quickOpenTask: QuickOpenTask;
120
-
121
- @inject(EditorManager)
122
- protected readonly editorManager: EditorManager;
123
-
124
- @inject(FrontendApplication)
125
- protected readonly app: FrontendApplication;
126
-
127
- @inject(ILogger) @named('task')
128
- protected readonly logger: ILogger;
129
-
130
- @inject(WidgetManager)
131
- protected readonly widgetManager: WidgetManager;
132
-
133
- @inject(ContributionProvider) @named(TaskContribution)
134
- protected readonly contributionProvider: ContributionProvider<TaskContribution>;
135
-
136
- @inject(TaskProviderRegistry)
137
- protected readonly taskProviderRegistry: TaskProviderRegistry;
138
-
139
- @inject(TaskResolverRegistry)
140
- protected readonly taskResolverRegistry: TaskResolverRegistry;
141
-
142
- @inject(TaskService)
143
- protected readonly taskService: TaskService;
144
-
145
- @inject(TaskSchemaUpdater)
146
- protected readonly schemaUpdater: TaskSchemaUpdater;
147
-
148
- @inject(StorageService)
149
- protected readonly storageService: StorageService;
150
-
151
- @inject(TaskRunningQuickOpen)
152
- protected readonly taskRunningQuickOpen: TaskRunningQuickOpen;
153
-
154
- @inject(TaskTerminateQuickOpen)
155
- protected readonly taskTerminateQuickOpen: TaskTerminateQuickOpen;
156
-
157
- @inject(TaskRestartRunningQuickOpen)
158
- protected readonly taskRestartRunningQuickOpen: TaskRestartRunningQuickOpen;
159
-
160
- @inject(TaskWatcher)
161
- protected readonly taskWatcher: TaskWatcher;
162
-
163
- @inject(StatusBar)
164
- protected readonly statusBar: StatusBar;
165
-
166
- @inject(WorkspaceService)
167
- protected readonly workspaceService: WorkspaceService;
168
-
169
- @postConstruct()
170
- protected init(): void {
171
- this.taskWatcher.onTaskCreated(() => this.updateRunningTasksItem());
172
- this.taskWatcher.onTaskExit(() => this.updateRunningTasksItem());
173
- }
174
-
175
- onStart(): void {
176
- this.contributionProvider.getContributions().forEach(contrib => {
177
- if (contrib.registerResolvers) {
178
- contrib.registerResolvers(this.taskResolverRegistry);
179
- }
180
- if (contrib.registerProviders) {
181
- contrib.registerProviders(this.taskProviderRegistry);
182
- }
183
- });
184
- this.schemaUpdater.update();
185
-
186
- this.storageService.getData<{ recent: TaskConfiguration[] }>(TASKS_STORAGE_KEY, { recent: [] })
187
- .then(tasks => this.taskService.recentTasks = tasks.recent);
188
- }
189
-
190
- onStop(): void {
191
- const recent = this.taskService.recentTasks;
192
- this.storageService.setData<{ recent: TaskConfiguration[] }>(TASKS_STORAGE_KEY, { recent });
193
- }
194
-
195
- /**
196
- * Contribute a status-bar item to trigger
197
- * the `Show Running Tasks` command.
198
- */
199
- protected async updateRunningTasksItem(): Promise<void> {
200
- const id = 'show-running-tasks';
201
- const items = await this.taskService.getRunningTasks();
202
- if (!!items.length) {
203
- this.statusBar.setElement(id, {
204
- text: `$(tools) ${items.length}`,
205
- tooltip: TaskCommands.TASK_SHOW_RUNNING.label,
206
- alignment: StatusBarAlignment.LEFT,
207
- priority: 2,
208
- command: TaskCommands.TASK_SHOW_RUNNING.id,
209
- });
210
- } else {
211
- this.statusBar.removeElement(id);
212
- }
213
- }
214
-
215
- registerCommands(registry: CommandRegistry): void {
216
- registry.registerCommand(
217
- TaskCommands.WORKBENCH_RUN_TASK,
218
- {
219
- isEnabled: () => true,
220
- execute: async (label: string) => {
221
- const didExecute = await this.taskService.runTaskByLabel(this.taskService.startUserAction(), label);
222
- if (!didExecute) {
223
- this.quickOpenTask.open();
224
- }
225
- }
226
- }
227
- );
228
-
229
- registry.registerCommand(
230
- TaskCommands.TASK_RUN,
231
- {
232
- isEnabled: () => true,
233
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
234
- execute: (...args: any[]) => {
235
- const [source, label, scope] = args;
236
- if (source && label) {
237
- return this.taskService.run(this.taskService.startUserAction(), source, label, scope);
238
- }
239
- return this.quickOpenTask.open();
240
- }
241
- }
242
- );
243
- registry.registerCommand(
244
- TaskCommands.TASK_RUN_BUILD,
245
- {
246
- isEnabled: () => this.workspaceService.opened,
247
- execute: () =>
248
- this.quickOpenTask.runBuildOrTestTask('build')
249
- }
250
- );
251
- registry.registerCommand(
252
- TaskCommands.TASK_RUN_TEST,
253
- {
254
- isEnabled: () => this.workspaceService.opened,
255
- execute: () =>
256
- this.quickOpenTask.runBuildOrTestTask('test')
257
- }
258
- );
259
- registry.registerCommand(
260
- TaskCommands.TASK_ATTACH,
261
- {
262
- isEnabled: () => true,
263
- execute: () => this.quickOpenTask.attach()
264
- }
265
- );
266
- registry.registerCommand(
267
- TaskCommands.TASK_RUN_LAST,
268
- {
269
- execute: async () => {
270
- if (!await this.taskService.runLastTask(this.taskService.startUserAction())) {
271
- await this.quickOpenTask.open();
272
- }
273
- }
274
- }
275
- );
276
- registry.registerCommand(
277
- TaskCommands.TASK_RUN_TEXT,
278
- {
279
- isVisible: () => !!this.editorManager.currentEditor,
280
- isEnabled: () => !!this.editorManager.currentEditor,
281
- execute: () => this.taskService.runSelectedText()
282
- }
283
- );
284
-
285
- registry.registerCommand(
286
- TaskCommands.TASK_CONFIGURE,
287
- {
288
- execute: () => this.quickOpenTask.configure()
289
- }
290
- );
291
-
292
- registry.registerCommand(
293
- TaskCommands.TASK_OPEN_USER,
294
- {
295
- execute: () => {
296
- this.taskService.openUserTasks();
297
- }
298
- }
299
- );
300
-
301
- registry.registerCommand(
302
- TaskCommands.TASK_CLEAR_HISTORY,
303
- {
304
- execute: () => this.taskService.clearRecentTasks()
305
- }
306
- );
307
-
308
- registry.registerCommand(
309
- TaskCommands.TASK_SHOW_RUNNING,
310
- {
311
- execute: () => this.taskRunningQuickOpen.open()
312
- }
313
- );
314
-
315
- registry.registerCommand(
316
- TaskCommands.TASK_TERMINATE,
317
- {
318
- execute: () => this.taskTerminateQuickOpen.open()
319
- }
320
- );
321
-
322
- registry.registerCommand(
323
- TaskCommands.TASK_RESTART_RUNNING,
324
- {
325
- execute: () => this.taskRestartRunningQuickOpen.open()
326
- }
327
- );
328
- }
329
-
330
- registerMenus(menus: MenuModelRegistry): void {
331
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
332
- commandId: TaskCommands.TASK_RUN.id,
333
- order: '0'
334
- });
335
-
336
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
337
- commandId: TaskCommands.TASK_RUN_BUILD.id,
338
- order: '1'
339
- });
340
-
341
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
342
- commandId: TaskCommands.TASK_RUN_TEST.id,
343
- order: '2'
344
- });
345
-
346
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
347
- commandId: TaskCommands.TASK_RUN_LAST.id,
348
- order: '3'
349
- });
350
-
351
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
352
- commandId: TaskCommands.TASK_ATTACH.id,
353
- order: '4'
354
- });
355
-
356
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
357
- commandId: TaskCommands.TASK_RUN_TEXT.id,
358
- order: '5'
359
- });
360
-
361
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_INFO, {
362
- commandId: TaskCommands.TASK_SHOW_RUNNING.id,
363
- label: TaskCommands.TASK_SHOW_RUNNING.label + '...',
364
- order: '0'
365
- });
366
-
367
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_INFO, {
368
- commandId: TaskCommands.TASK_RESTART_RUNNING.id,
369
- label: TaskCommands.TASK_RESTART_RUNNING.label,
370
- order: '1'
371
- });
372
-
373
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_INFO, {
374
- commandId: TaskCommands.TASK_TERMINATE.id,
375
- label: TaskCommands.TASK_TERMINATE.label + '...',
376
- order: '2'
377
- });
378
-
379
- menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_CONFIG, {
380
- commandId: TaskCommands.TASK_CONFIGURE.id,
381
- order: '0'
382
- });
383
-
384
- menus.registerMenuAction(CommonMenus.MANAGE_SETTINGS, {
385
- commandId: TaskCommands.TASK_OPEN_USER.id,
386
- label: nls.localizeByDefault('User Tasks'),
387
- order: 'a40'
388
- });
389
- }
390
-
391
- registerQuickAccessProvider(): void {
392
- this.quickOpenTask.registerQuickAccessProvider();
393
- }
394
-
395
- registerKeybindings(keybindings: KeybindingRegistry): void {
396
- keybindings.registerKeybinding({
397
- command: TaskCommands.TASK_RUN_LAST.id,
398
- keybinding: 'ctrlcmd+shift+k',
399
- when: '!textInputFocus || editorReadonly'
400
- });
401
- }
402
- }
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 { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
18
+ import { ILogger, ContributionProvider, CommandContribution, Command, CommandRegistry, MenuContribution, MenuModelRegistry, nls } from '@theia/core/lib/common';
19
+ import { QuickOpenTask, TaskTerminateQuickOpen, TaskRunningQuickOpen, TaskRestartRunningQuickOpen } from './quick-open-task';
20
+ import {
21
+ FrontendApplication, FrontendApplicationContribution, QuickAccessContribution,
22
+ KeybindingRegistry, KeybindingContribution, StorageService, StatusBar, StatusBarAlignment, CommonMenus
23
+ } from '@theia/core/lib/browser';
24
+ import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
25
+ import { TaskContribution, TaskResolverRegistry, TaskProviderRegistry } from './task-contribution';
26
+ import { TaskService } from './task-service';
27
+ import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
28
+ import { TaskSchemaUpdater } from './task-schema-updater';
29
+ import { TaskConfiguration, TaskWatcher } from '../common';
30
+ import { EditorManager } from '@theia/editor/lib/browser';
31
+ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
32
+
33
+ export namespace TaskCommands {
34
+ const TASK_CATEGORY = 'Task';
35
+ const TASK_CATEGORY_KEY = nls.getDefaultKey(TASK_CATEGORY);
36
+ export const TASK_RUN = Command.toDefaultLocalizedCommand({
37
+ id: 'task:run',
38
+ category: TASK_CATEGORY,
39
+ label: 'Run Task...'
40
+ });
41
+
42
+ export const TASK_RUN_BUILD = Command.toDefaultLocalizedCommand({
43
+ id: 'task:run:build',
44
+ category: TASK_CATEGORY,
45
+ label: 'Run Build Task'
46
+ });
47
+
48
+ export const TASK_RUN_TEST = Command.toDefaultLocalizedCommand({
49
+ id: 'task:run:test',
50
+ category: TASK_CATEGORY,
51
+ label: 'Run Test Task'
52
+ });
53
+
54
+ export const WORKBENCH_RUN_TASK = Command.toLocalizedCommand({
55
+ id: 'workbench.action.tasks.runTask',
56
+ category: TASK_CATEGORY
57
+ }, '', TASK_CATEGORY_KEY);
58
+
59
+ export const TASK_RUN_LAST = Command.toDefaultLocalizedCommand({
60
+ id: 'task:run:last',
61
+ category: TASK_CATEGORY,
62
+ label: 'Rerun Last Task'
63
+ });
64
+
65
+ export const TASK_ATTACH = Command.toLocalizedCommand({
66
+ id: 'task:attach',
67
+ category: TASK_CATEGORY,
68
+ label: 'Attach Task...'
69
+ }, 'theia/task/attachTask', TASK_CATEGORY_KEY);
70
+
71
+ export const TASK_RUN_TEXT = Command.toDefaultLocalizedCommand({
72
+ id: 'task:run:text',
73
+ category: TASK_CATEGORY,
74
+ label: 'Run Selected Text'
75
+ });
76
+
77
+ export const TASK_CONFIGURE = Command.toDefaultLocalizedCommand({
78
+ id: 'task:configure',
79
+ category: TASK_CATEGORY,
80
+ label: 'Configure Tasks...'
81
+ });
82
+
83
+ export const TASK_OPEN_USER = Command.toLocalizedCommand({
84
+ id: 'task:open_user',
85
+ category: TASK_CATEGORY,
86
+ label: 'Open User Tasks'
87
+ }, 'theia/task/openUserTasks', TASK_CATEGORY_KEY);
88
+
89
+ export const TASK_CLEAR_HISTORY = Command.toLocalizedCommand({
90
+ id: 'task:clear-history',
91
+ category: TASK_CATEGORY,
92
+ label: 'Clear History'
93
+ }, 'theia/task/clearHistory', TASK_CATEGORY_KEY);
94
+
95
+ export const TASK_SHOW_RUNNING = Command.toDefaultLocalizedCommand({
96
+ id: 'task:show-running',
97
+ category: TASK_CATEGORY,
98
+ label: 'Show Running Tasks'
99
+ });
100
+
101
+ export const TASK_TERMINATE = Command.toDefaultLocalizedCommand({
102
+ id: 'task:terminate',
103
+ category: TASK_CATEGORY,
104
+ label: 'Terminate Task'
105
+ });
106
+
107
+ export const TASK_RESTART_RUNNING = Command.toDefaultLocalizedCommand({
108
+ id: 'task:restart-running',
109
+ category: TASK_CATEGORY,
110
+ label: 'Restart Running Task...'
111
+ });
112
+ }
113
+
114
+ const TASKS_STORAGE_KEY = 'tasks';
115
+
116
+ @injectable()
117
+ export class TaskFrontendContribution implements CommandContribution, MenuContribution, KeybindingContribution, FrontendApplicationContribution, QuickAccessContribution {
118
+ @inject(QuickOpenTask)
119
+ protected readonly quickOpenTask: QuickOpenTask;
120
+
121
+ @inject(EditorManager)
122
+ protected readonly editorManager: EditorManager;
123
+
124
+ @inject(FrontendApplication)
125
+ protected readonly app: FrontendApplication;
126
+
127
+ @inject(ILogger) @named('task')
128
+ protected readonly logger: ILogger;
129
+
130
+ @inject(WidgetManager)
131
+ protected readonly widgetManager: WidgetManager;
132
+
133
+ @inject(ContributionProvider) @named(TaskContribution)
134
+ protected readonly contributionProvider: ContributionProvider<TaskContribution>;
135
+
136
+ @inject(TaskProviderRegistry)
137
+ protected readonly taskProviderRegistry: TaskProviderRegistry;
138
+
139
+ @inject(TaskResolverRegistry)
140
+ protected readonly taskResolverRegistry: TaskResolverRegistry;
141
+
142
+ @inject(TaskService)
143
+ protected readonly taskService: TaskService;
144
+
145
+ @inject(TaskSchemaUpdater)
146
+ protected readonly schemaUpdater: TaskSchemaUpdater;
147
+
148
+ @inject(StorageService)
149
+ protected readonly storageService: StorageService;
150
+
151
+ @inject(TaskRunningQuickOpen)
152
+ protected readonly taskRunningQuickOpen: TaskRunningQuickOpen;
153
+
154
+ @inject(TaskTerminateQuickOpen)
155
+ protected readonly taskTerminateQuickOpen: TaskTerminateQuickOpen;
156
+
157
+ @inject(TaskRestartRunningQuickOpen)
158
+ protected readonly taskRestartRunningQuickOpen: TaskRestartRunningQuickOpen;
159
+
160
+ @inject(TaskWatcher)
161
+ protected readonly taskWatcher: TaskWatcher;
162
+
163
+ @inject(StatusBar)
164
+ protected readonly statusBar: StatusBar;
165
+
166
+ @inject(WorkspaceService)
167
+ protected readonly workspaceService: WorkspaceService;
168
+
169
+ @postConstruct()
170
+ protected init(): void {
171
+ this.taskWatcher.onTaskCreated(() => this.updateRunningTasksItem());
172
+ this.taskWatcher.onTaskExit(() => this.updateRunningTasksItem());
173
+ }
174
+
175
+ onStart(): void {
176
+ this.contributionProvider.getContributions().forEach(contrib => {
177
+ if (contrib.registerResolvers) {
178
+ contrib.registerResolvers(this.taskResolverRegistry);
179
+ }
180
+ if (contrib.registerProviders) {
181
+ contrib.registerProviders(this.taskProviderRegistry);
182
+ }
183
+ });
184
+ this.schemaUpdater.update();
185
+
186
+ this.storageService.getData<{ recent: TaskConfiguration[] }>(TASKS_STORAGE_KEY, { recent: [] })
187
+ .then(tasks => this.taskService.recentTasks = tasks.recent);
188
+ }
189
+
190
+ onStop(): void {
191
+ const recent = this.taskService.recentTasks;
192
+ this.storageService.setData<{ recent: TaskConfiguration[] }>(TASKS_STORAGE_KEY, { recent });
193
+ }
194
+
195
+ /**
196
+ * Contribute a status-bar item to trigger
197
+ * the `Show Running Tasks` command.
198
+ */
199
+ protected async updateRunningTasksItem(): Promise<void> {
200
+ const id = 'show-running-tasks';
201
+ const items = await this.taskService.getRunningTasks();
202
+ if (!!items.length) {
203
+ this.statusBar.setElement(id, {
204
+ text: `$(tools) ${items.length}`,
205
+ tooltip: TaskCommands.TASK_SHOW_RUNNING.label,
206
+ alignment: StatusBarAlignment.LEFT,
207
+ priority: 2,
208
+ command: TaskCommands.TASK_SHOW_RUNNING.id,
209
+ });
210
+ } else {
211
+ this.statusBar.removeElement(id);
212
+ }
213
+ }
214
+
215
+ registerCommands(registry: CommandRegistry): void {
216
+ registry.registerCommand(
217
+ TaskCommands.WORKBENCH_RUN_TASK,
218
+ {
219
+ isEnabled: () => true,
220
+ execute: async (label: string) => {
221
+ const didExecute = await this.taskService.runTaskByLabel(this.taskService.startUserAction(), label);
222
+ if (!didExecute) {
223
+ this.quickOpenTask.open();
224
+ }
225
+ }
226
+ }
227
+ );
228
+
229
+ registry.registerCommand(
230
+ TaskCommands.TASK_RUN,
231
+ {
232
+ isEnabled: () => true,
233
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
234
+ execute: (...args: any[]) => {
235
+ const [source, label, scope] = args;
236
+ if (source && label) {
237
+ return this.taskService.run(this.taskService.startUserAction(), source, label, scope);
238
+ }
239
+ return this.quickOpenTask.open();
240
+ }
241
+ }
242
+ );
243
+ registry.registerCommand(
244
+ TaskCommands.TASK_RUN_BUILD,
245
+ {
246
+ isEnabled: () => this.workspaceService.opened,
247
+ execute: () =>
248
+ this.quickOpenTask.runBuildOrTestTask('build')
249
+ }
250
+ );
251
+ registry.registerCommand(
252
+ TaskCommands.TASK_RUN_TEST,
253
+ {
254
+ isEnabled: () => this.workspaceService.opened,
255
+ execute: () =>
256
+ this.quickOpenTask.runBuildOrTestTask('test')
257
+ }
258
+ );
259
+ registry.registerCommand(
260
+ TaskCommands.TASK_ATTACH,
261
+ {
262
+ isEnabled: () => true,
263
+ execute: () => this.quickOpenTask.attach()
264
+ }
265
+ );
266
+ registry.registerCommand(
267
+ TaskCommands.TASK_RUN_LAST,
268
+ {
269
+ execute: async () => {
270
+ if (!await this.taskService.runLastTask(this.taskService.startUserAction())) {
271
+ await this.quickOpenTask.open();
272
+ }
273
+ }
274
+ }
275
+ );
276
+ registry.registerCommand(
277
+ TaskCommands.TASK_RUN_TEXT,
278
+ {
279
+ isVisible: () => !!this.editorManager.currentEditor,
280
+ isEnabled: () => !!this.editorManager.currentEditor,
281
+ execute: () => this.taskService.runSelectedText()
282
+ }
283
+ );
284
+
285
+ registry.registerCommand(
286
+ TaskCommands.TASK_CONFIGURE,
287
+ {
288
+ execute: () => this.quickOpenTask.configure()
289
+ }
290
+ );
291
+
292
+ registry.registerCommand(
293
+ TaskCommands.TASK_OPEN_USER,
294
+ {
295
+ execute: () => {
296
+ this.taskService.openUserTasks();
297
+ }
298
+ }
299
+ );
300
+
301
+ registry.registerCommand(
302
+ TaskCommands.TASK_CLEAR_HISTORY,
303
+ {
304
+ execute: () => this.taskService.clearRecentTasks()
305
+ }
306
+ );
307
+
308
+ registry.registerCommand(
309
+ TaskCommands.TASK_SHOW_RUNNING,
310
+ {
311
+ execute: () => this.taskRunningQuickOpen.open()
312
+ }
313
+ );
314
+
315
+ registry.registerCommand(
316
+ TaskCommands.TASK_TERMINATE,
317
+ {
318
+ execute: () => this.taskTerminateQuickOpen.open()
319
+ }
320
+ );
321
+
322
+ registry.registerCommand(
323
+ TaskCommands.TASK_RESTART_RUNNING,
324
+ {
325
+ execute: () => this.taskRestartRunningQuickOpen.open()
326
+ }
327
+ );
328
+ }
329
+
330
+ registerMenus(menus: MenuModelRegistry): void {
331
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
332
+ commandId: TaskCommands.TASK_RUN.id,
333
+ order: '0'
334
+ });
335
+
336
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
337
+ commandId: TaskCommands.TASK_RUN_BUILD.id,
338
+ order: '1'
339
+ });
340
+
341
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
342
+ commandId: TaskCommands.TASK_RUN_TEST.id,
343
+ order: '2'
344
+ });
345
+
346
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
347
+ commandId: TaskCommands.TASK_RUN_LAST.id,
348
+ order: '3'
349
+ });
350
+
351
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
352
+ commandId: TaskCommands.TASK_ATTACH.id,
353
+ order: '4'
354
+ });
355
+
356
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS, {
357
+ commandId: TaskCommands.TASK_RUN_TEXT.id,
358
+ order: '5'
359
+ });
360
+
361
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_INFO, {
362
+ commandId: TaskCommands.TASK_SHOW_RUNNING.id,
363
+ label: TaskCommands.TASK_SHOW_RUNNING.label + '...',
364
+ order: '0'
365
+ });
366
+
367
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_INFO, {
368
+ commandId: TaskCommands.TASK_RESTART_RUNNING.id,
369
+ label: TaskCommands.TASK_RESTART_RUNNING.label,
370
+ order: '1'
371
+ });
372
+
373
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_INFO, {
374
+ commandId: TaskCommands.TASK_TERMINATE.id,
375
+ label: TaskCommands.TASK_TERMINATE.label + '...',
376
+ order: '2'
377
+ });
378
+
379
+ menus.registerMenuAction(TerminalMenus.TERMINAL_TASKS_CONFIG, {
380
+ commandId: TaskCommands.TASK_CONFIGURE.id,
381
+ order: '0'
382
+ });
383
+
384
+ menus.registerMenuAction(CommonMenus.MANAGE_SETTINGS, {
385
+ commandId: TaskCommands.TASK_OPEN_USER.id,
386
+ label: nls.localizeByDefault('User Tasks'),
387
+ order: 'a40'
388
+ });
389
+ }
390
+
391
+ registerQuickAccessProvider(): void {
392
+ this.quickOpenTask.registerQuickAccessProvider();
393
+ }
394
+
395
+ registerKeybindings(keybindings: KeybindingRegistry): void {
396
+ keybindings.registerKeybinding({
397
+ command: TaskCommands.TASK_RUN_LAST.id,
398
+ keybinding: 'ctrlcmd+shift+k',
399
+ when: '!textInputFocus || editorReadonly'
400
+ });
401
+ }
402
+ }