@theia/task 1.34.2 → 1.34.3

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 (169) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +193 -193
  3. package/lib/browser/index.d.ts +6 -6
  4. package/lib/browser/index.js +33 -33
  5. package/lib/browser/process/process-task-contribution.d.ts +6 -6
  6. package/lib/browser/process/process-task-contribution.js +43 -43
  7. package/lib/browser/process/process-task-frontend-module.d.ts +2 -2
  8. package/lib/browser/process/process-task-frontend-module.js +27 -27
  9. package/lib/browser/process/process-task-resolver.d.ts +17 -17
  10. package/lib/browser/process/process-task-resolver.js +93 -93
  11. package/lib/browser/provided-task-configurations.d.ts +32 -32
  12. package/lib/browser/provided-task-configurations.js +171 -171
  13. package/lib/browser/provided-task-configurations.spec.d.ts +1 -1
  14. package/lib/browser/provided-task-configurations.spec.js +43 -43
  15. package/lib/browser/quick-open-task.d.ts +129 -129
  16. package/lib/browser/quick-open-task.js +636 -636
  17. package/lib/browser/task-configuration-manager.d.ts +64 -64
  18. package/lib/browser/task-configuration-manager.js +261 -261
  19. package/lib/browser/task-configuration-model.d.ts +32 -32
  20. package/lib/browser/task-configuration-model.js +79 -79
  21. package/lib/browser/task-configurations.d.ts +127 -127
  22. package/lib/browser/task-configurations.js +479 -479
  23. package/lib/browser/task-contribution.d.ts +173 -173
  24. package/lib/browser/task-contribution.js +199 -199
  25. package/lib/browser/task-definition-registry.d.ts +38 -38
  26. package/lib/browser/task-definition-registry.js +131 -131
  27. package/lib/browser/task-definition-registry.spec.d.ts +1 -1
  28. package/lib/browser/task-definition-registry.spec.js +170 -170
  29. package/lib/browser/task-frontend-contribution.d.ts +56 -56
  30. package/lib/browser/task-frontend-contribution.js +353 -353
  31. package/lib/browser/task-frontend-module.d.ts +5 -5
  32. package/lib/browser/task-frontend-module.js +79 -79
  33. package/lib/browser/task-name-resolver.d.ts +13 -13
  34. package/lib/browser/task-name-resolver.js +65 -65
  35. package/lib/browser/task-node.d.ts +9 -9
  36. package/lib/browser/task-node.js +17 -17
  37. package/lib/browser/task-preferences.d.ts +4 -4
  38. package/lib/browser/task-preferences.js +40 -40
  39. package/lib/browser/task-problem-matcher-registry.d.ts +40 -40
  40. package/lib/browser/task-problem-matcher-registry.js +310 -310
  41. package/lib/browser/task-problem-pattern-registry.d.ts +23 -23
  42. package/lib/browser/task-problem-pattern-registry.js +208 -208
  43. package/lib/browser/task-schema-updater.d.ts +58 -58
  44. package/lib/browser/task-schema-updater.js +672 -672
  45. package/lib/browser/task-service.d.ts +276 -276
  46. package/lib/browser/task-service.js +1119 -1119
  47. package/lib/browser/task-source-resolver.d.ts +9 -9
  48. package/lib/browser/task-source-resolver.js +51 -51
  49. package/lib/browser/task-templates.d.ts +13 -13
  50. package/lib/browser/task-templates.js +161 -161
  51. package/lib/browser/task-terminal-widget-manager.d.ts +44 -44
  52. package/lib/browser/task-terminal-widget-manager.js +224 -224
  53. package/lib/browser/tasks-monaco-contribution.d.ts +1 -1
  54. package/lib/browser/tasks-monaco-contribution.js +27 -27
  55. package/lib/common/index.d.ts +3 -3
  56. package/lib/common/index.js +30 -30
  57. package/lib/common/problem-matcher-protocol.d.ts +124 -124
  58. package/lib/common/problem-matcher-protocol.js +132 -132
  59. package/lib/common/process/task-protocol.d.ts +68 -68
  60. package/lib/common/process/task-protocol.js +33 -33
  61. package/lib/common/task-common-module.d.ts +7 -7
  62. package/lib/common/task-common-module.js +33 -33
  63. package/lib/common/task-protocol.d.ts +190 -190
  64. package/lib/common/task-protocol.js +125 -125
  65. package/lib/common/task-watcher.d.ts +17 -17
  66. package/lib/common/task-watcher.js +86 -86
  67. package/lib/node/custom/custom-task-runner-backend-module.d.ts +2 -2
  68. package/lib/node/custom/custom-task-runner-backend-module.js +36 -36
  69. package/lib/node/custom/custom-task-runner-contribution.d.ts +6 -6
  70. package/lib/node/custom/custom-task-runner-contribution.js +42 -42
  71. package/lib/node/custom/custom-task-runner.d.ts +15 -15
  72. package/lib/node/custom/custom-task-runner.js +69 -69
  73. package/lib/node/custom/custom-task.d.ts +20 -20
  74. package/lib/node/custom/custom-task.js +78 -78
  75. package/lib/node/index.d.ts +3 -3
  76. package/lib/node/index.js +30 -30
  77. package/lib/node/process/process-task-runner-backend-module.d.ts +2 -2
  78. package/lib/node/process/process-task-runner-backend-module.js +36 -36
  79. package/lib/node/process/process-task-runner-contribution.d.ts +6 -6
  80. package/lib/node/process/process-task-runner-contribution.js +43 -43
  81. package/lib/node/process/process-task-runner.d.ts +60 -60
  82. package/lib/node/process/process-task-runner.js +352 -352
  83. package/lib/node/process/process-task.d.ts +26 -26
  84. package/lib/node/process/process-task.js +139 -139
  85. package/lib/node/process/process-task.spec.d.ts +1 -1
  86. package/lib/node/process/process-task.spec.js +29 -29
  87. package/lib/node/task-abstract-line-matcher.d.ts +49 -49
  88. package/lib/node/task-abstract-line-matcher.js +278 -278
  89. package/lib/node/task-backend-application-contribution.d.ts +8 -8
  90. package/lib/node/task-backend-application-contribution.js +48 -48
  91. package/lib/node/task-backend-module.d.ts +3 -3
  92. package/lib/node/task-backend-module.js +50 -50
  93. package/lib/node/task-line-matchers.d.ts +27 -27
  94. package/lib/node/task-line-matchers.js +121 -121
  95. package/lib/node/task-manager.d.ts +55 -55
  96. package/lib/node/task-manager.js +135 -135
  97. package/lib/node/task-problem-collector.d.ts +10 -10
  98. package/lib/node/task-problem-collector.js +57 -57
  99. package/lib/node/task-problem-collector.spec.d.ts +1 -1
  100. package/lib/node/task-problem-collector.spec.js +310 -310
  101. package/lib/node/task-runner-protocol.d.ts +16 -16
  102. package/lib/node/task-runner-protocol.js +19 -19
  103. package/lib/node/task-runner.d.ts +50 -50
  104. package/lib/node/task-runner.js +97 -97
  105. package/lib/node/task-server.d.ts +39 -39
  106. package/lib/node/task-server.js +237 -237
  107. package/lib/node/task-server.slow-spec.d.ts +1 -1
  108. package/lib/node/task-server.slow-spec.js +395 -395
  109. package/lib/node/task.d.ts +50 -50
  110. package/lib/node/task.js +77 -77
  111. package/lib/node/test/task-test-container.d.ts +2 -2
  112. package/lib/node/test/task-test-container.js +58 -58
  113. package/package.json +13 -13
  114. package/src/browser/index.ts +22 -22
  115. package/src/browser/process/process-task-contribution.ts +31 -31
  116. package/src/browser/process/process-task-frontend-module.ts +27 -27
  117. package/src/browser/process/process-task-resolver.ts +89 -89
  118. package/src/browser/provided-task-configurations.spec.ts +46 -46
  119. package/src/browser/provided-task-configurations.ts +170 -170
  120. package/src/browser/quick-open-task.ts +701 -701
  121. package/src/browser/style/index.css +19 -19
  122. package/src/browser/task-configuration-manager.ts +256 -256
  123. package/src/browser/task-configuration-model.ts +101 -101
  124. package/src/browser/task-configurations.ts +507 -507
  125. package/src/browser/task-contribution.ts +254 -254
  126. package/src/browser/task-definition-registry.spec.ts +203 -203
  127. package/src/browser/task-definition-registry.ts +128 -128
  128. package/src/browser/task-frontend-contribution.ts +396 -396
  129. package/src/browser/task-frontend-module.ts +86 -86
  130. package/src/browser/task-name-resolver.ts +55 -55
  131. package/src/browser/task-node.ts +37 -37
  132. package/src/browser/task-preferences.ts +40 -40
  133. package/src/browser/task-problem-matcher-registry.ts +308 -308
  134. package/src/browser/task-problem-pattern-registry.ts +195 -195
  135. package/src/browser/task-schema-updater.ts +703 -703
  136. package/src/browser/task-service.ts +1163 -1163
  137. package/src/browser/task-source-resolver.ts +36 -36
  138. package/src/browser/task-templates.ts +168 -168
  139. package/src/browser/task-terminal-widget-manager.ts +221 -221
  140. package/src/browser/tasks-monaco-contribution.ts +27 -27
  141. package/src/common/index.ts +19 -19
  142. package/src/common/problem-matcher-protocol.ts +235 -235
  143. package/src/common/process/task-protocol.ts +97 -97
  144. package/src/common/task-common-module.ts +34 -34
  145. package/src/common/task-protocol.ts +310 -310
  146. package/src/common/task-watcher.ts +78 -78
  147. package/src/node/custom/custom-task-runner-backend-module.ts +37 -37
  148. package/src/node/custom/custom-task-runner-contribution.ts +30 -30
  149. package/src/node/custom/custom-task-runner.ts +60 -60
  150. package/src/node/custom/custom-task.ts +73 -73
  151. package/src/node/index.ts +19 -19
  152. package/src/node/process/process-task-runner-backend-module.ts +37 -37
  153. package/src/node/process/process-task-runner-contribution.ts +31 -31
  154. package/src/node/process/process-task-runner.ts +371 -371
  155. package/src/node/process/process-task.spec.ts +30 -30
  156. package/src/node/process/process-task.ts +147 -147
  157. package/src/node/task-abstract-line-matcher.ts +317 -317
  158. package/src/node/task-backend-application-contribution.ts +36 -36
  159. package/src/node/task-backend-module.ts +57 -57
  160. package/src/node/task-line-matchers.ts +127 -127
  161. package/src/node/task-manager.ts +129 -129
  162. package/src/node/task-problem-collector.spec.ts +338 -338
  163. package/src/node/task-problem-collector.ts +62 -62
  164. package/src/node/task-runner-protocol.ts +33 -33
  165. package/src/node/task-runner.ts +96 -96
  166. package/src/node/task-server.slow-spec.ts +444 -444
  167. package/src/node/task-server.ts +263 -263
  168. package/src/node/task.ts +103 -103
  169. package/src/node/test/task-test-container.ts +63 -63
@@ -1,701 +1,701 @@
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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { inject, injectable, optional } from '@theia/core/shared/inversify';
18
- import { TaskService } from './task-service';
19
- import { TaskInfo, TaskConfiguration, TaskCustomization, TaskScope, TaskConfigurationScope } from '../common/task-protocol';
20
- import { TaskDefinitionRegistry } from './task-definition-registry';
21
- import URI from '@theia/core/lib/common/uri';
22
- import { LabelProvider, QuickAccessProvider, QuickAccessRegistry, QuickInputService, PreferenceService } from '@theia/core/lib/browser';
23
- import { WorkspaceService } from '@theia/workspace/lib/browser';
24
- import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
25
- import { TaskNameResolver } from './task-name-resolver';
26
- import { TaskSourceResolver } from './task-source-resolver';
27
- import { TaskConfigurationManager } from './task-configuration-manager';
28
- import { filterItems, QuickInputButton, QuickPickItem, QuickPickItemOrSeparator, QuickPicks } from '@theia/core/lib/browser/quick-input/quick-input-service';
29
- import { CancellationToken } from '@theia/core/lib/common';
30
- import { TriggerAction } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/browser/pickerQuickAccess';
31
-
32
- export namespace ConfigureTaskAction {
33
- export const ID = 'workbench.action.tasks.configureTaskRunner';
34
- export const TEXT = 'Configure Task';
35
- }
36
-
37
- @injectable()
38
- export class QuickOpenTask implements QuickAccessProvider {
39
- static readonly PREFIX = 'task ';
40
- readonly description: string = 'Run Task';
41
- protected items: Array<QuickPickItemOrSeparator> = [];
42
-
43
- @inject(TaskService)
44
- protected readonly taskService: TaskService;
45
-
46
- @inject(QuickInputService) @optional()
47
- protected readonly quickInputService: QuickInputService;
48
-
49
- @inject(QuickAccessRegistry)
50
- protected readonly quickAccessRegistry: QuickAccessRegistry;
51
-
52
- @inject(WorkspaceService)
53
- protected readonly workspaceService: WorkspaceService;
54
-
55
- @inject(TaskDefinitionRegistry)
56
- protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
57
-
58
- @inject(TaskNameResolver)
59
- protected readonly taskNameResolver: TaskNameResolver;
60
-
61
- @inject(TaskSourceResolver)
62
- protected readonly taskSourceResolver: TaskSourceResolver;
63
-
64
- @inject(TaskConfigurationManager)
65
- protected readonly taskConfigurationManager: TaskConfigurationManager;
66
-
67
- @inject(PreferenceService)
68
- protected readonly preferences: PreferenceService;
69
-
70
- @inject(LabelProvider)
71
- protected readonly labelProvider: LabelProvider;
72
-
73
- init(): Promise<void> {
74
- return this.doInit(this.taskService.startUserAction());
75
- }
76
-
77
- protected async doInit(token: number): Promise<void> {
78
- const recentTasks = this.taskService.recentTasks;
79
- const configuredTasks = await this.taskService.getConfiguredTasks(token);
80
- const providedTasks = await this.taskService.getProvidedTasks(token);
81
-
82
- const { filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, providedTasks);
83
- const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
84
- this.items = [];
85
-
86
- const filteredRecentTasksItems = this.getItems(filteredRecentTasks, 'recently used tasks', token, isMulti);
87
- const filteredConfiguredTasksItems = this.getItems(filteredConfiguredTasks, 'configured tasks', token, isMulti);
88
- const filteredProvidedTasksItems = this.getItems(filteredProvidedTasks, 'detected tasks', token, isMulti);
89
-
90
- this.items.push(
91
- ...filteredRecentTasksItems,
92
- ...filteredConfiguredTasksItems,
93
- ...filteredProvidedTasksItems
94
- );
95
- }
96
-
97
- protected onDidTriggerGearIcon(item: QuickPickItem): void {
98
- if (item instanceof TaskRunQuickOpenItem) {
99
- this.taskService.configure(item.token, item.task);
100
- this.quickInputService.hide();
101
- }
102
- }
103
-
104
- async open(): Promise<void> {
105
- await this.init();
106
- if (!this.items.length) {
107
- this.items.push(({
108
- label: 'No task to run found. Configure Tasks...',
109
- execute: () => this.configure()
110
- }));
111
- }
112
- this.quickInputService?.showQuickPick(this.items, {
113
- placeholder: 'Select the task to run',
114
- onDidTriggerItemButton: ({ item }) => this.onDidTriggerGearIcon(item)
115
- });
116
- }
117
-
118
- attach(): void {
119
- this.items = [];
120
- const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
121
- this.taskService.getRunningTasks().then(tasks => {
122
- if (!tasks.length) {
123
- this.items.push({
124
- label: 'No tasks found',
125
- });
126
- } else {
127
- tasks.forEach((task: TaskInfo) => {
128
- // can only attach to terminal processes, so only list those
129
- if (task.terminalId) {
130
- this.items.push(new RunningTaskQuickOpenItem(
131
- task,
132
- this.taskService,
133
- this.taskNameResolver,
134
- this.taskSourceResolver,
135
- this.taskDefinitionRegistry,
136
- this.labelProvider,
137
- isMulti,
138
- () => this.taskService.attach(task.terminalId!, task)
139
- ));
140
- }
141
- });
142
- }
143
- if (this.items.length === 0) {
144
- this.items.push(({
145
- label: 'No tasks found'
146
- }));
147
- }
148
- this.quickInputService?.showQuickPick(this.items, { placeholder: 'Choose task to open' });
149
- });
150
- }
151
-
152
- async configure(): Promise<void> {
153
- this.items = [];
154
- const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
155
- const token: number = this.taskService.startUserAction();
156
-
157
- const configuredTasks = await this.taskService.getConfiguredTasks(token);
158
- const providedTasks = await this.taskService.getProvidedTasks(token);
159
-
160
- // check if tasks.json exists. If not, display "Create tasks.json file from template"
161
- // If tasks.json exists and empty, display 'Open tasks.json file'
162
- const { filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks([], configuredTasks, providedTasks);
163
- const groupedTasks = this.getGroupedTasksByWorkspaceFolder([...filteredConfiguredTasks, ...filteredProvidedTasks]);
164
- if (groupedTasks.has(TaskScope.Global.toString())) {
165
- const configs = groupedTasks.get(TaskScope.Global.toString())!;
166
- this.items.push(
167
- ...configs.map(taskConfig => {
168
- const item = new TaskConfigureQuickOpenItem(
169
- token,
170
- taskConfig,
171
- this.taskService,
172
- this.taskNameResolver,
173
- this.workspaceService,
174
- isMulti
175
- );
176
- item['taskDefinitionRegistry'] = this.taskDefinitionRegistry;
177
- return item;
178
- })
179
- );
180
- }
181
-
182
- const rootUris = (await this.workspaceService.roots).map(rootStat => rootStat.resource.toString());
183
- for (const rootFolder of rootUris) {
184
- const folderName = new URI(rootFolder).displayName;
185
- if (groupedTasks.has(rootFolder)) {
186
- const configs = groupedTasks.get(rootFolder.toString())!;
187
- this.items.push(
188
- ...configs.map((taskConfig, index) => {
189
- const item = new TaskConfigureQuickOpenItem(
190
- token,
191
- taskConfig,
192
- this.taskService,
193
- this.taskNameResolver,
194
- this.workspaceService,
195
- isMulti,
196
-
197
- );
198
- item['taskDefinitionRegistry'] = this.taskDefinitionRegistry;
199
- return item;
200
- })
201
- );
202
- } else {
203
- const { configUri } = this.preferences.resolve('tasks', [], rootFolder);
204
- const existTaskConfigFile = !!configUri;
205
- this.items.push(({
206
- label: existTaskConfigFile ? 'Open tasks.json file' : 'Create tasks.json file from template',
207
- execute: () => {
208
- setTimeout(() => this.taskConfigurationManager.openConfiguration(rootFolder));
209
- }
210
- }));
211
- }
212
- if (this.items.length > 0) {
213
- this.items.unshift({
214
- type: 'separator',
215
- label: isMulti ? folderName : ''
216
- });
217
- }
218
- }
219
-
220
- if (this.items.length === 0) {
221
- this.items.push(({
222
- label: 'No tasks found'
223
- }));
224
- }
225
-
226
- this.quickInputService?.showQuickPick(this.items, { placeholder: 'Select a task to configure' });
227
- }
228
-
229
- protected getTaskItems(): QuickPickItem[] {
230
- return this.items.filter((item): item is QuickPickItem => item.type !== 'separator' && (item as TaskRunQuickOpenItem).task !== undefined);
231
- }
232
-
233
- async runBuildOrTestTask(buildOrTestType: 'build' | 'test'): Promise<void> {
234
- const shouldRunBuildTask = buildOrTestType === 'build';
235
- const token: number = this.taskService.startUserAction();
236
-
237
- await this.doInit(token);
238
-
239
- const taskItems = this.getTaskItems();
240
-
241
- if (taskItems.length > 0) { // the item in `this.items` is not 'No tasks found'
242
- const buildOrTestTasks = taskItems.filter((t: TaskRunQuickOpenItem) =>
243
- shouldRunBuildTask ? TaskCustomization.isBuildTask(t.task) : TaskCustomization.isTestTask(t.task)
244
- );
245
- if (buildOrTestTasks.length > 0) { // build / test tasks are defined in the workspace
246
- const defaultBuildOrTestTasks = buildOrTestTasks.filter((t: TaskRunQuickOpenItem) =>
247
- shouldRunBuildTask ? TaskCustomization.isDefaultBuildTask(t.task) : TaskCustomization.isDefaultTestTask(t.task)
248
- );
249
- if (defaultBuildOrTestTasks.length === 1) { // run the default build / test task
250
- const defaultBuildOrTestTask = defaultBuildOrTestTasks[0];
251
- const taskToRun = (defaultBuildOrTestTask as TaskRunQuickOpenItem).task;
252
- const scope = taskToRun._scope;
253
-
254
- if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(taskToRun)) {
255
- this.taskService.run(token, taskToRun.source, taskToRun.label, scope);
256
- } else {
257
- this.taskService.run(token, taskToRun._source, taskToRun.label, scope);
258
- }
259
- return;
260
- }
261
- // if default build / test task is not found, or there are more than one default,
262
- // display the list of build /test tasks to let the user decide which to run
263
- this.items = buildOrTestTasks;
264
- } else { // no build / test tasks, display an action item to configure the build / test task
265
- this.items = [({
266
- label: `No ${buildOrTestType} task to run found. Configure ${buildOrTestType.charAt(0).toUpperCase() + buildOrTestType.slice(1)} Task...`,
267
- execute: () => {
268
- this.doInit(token).then(() => {
269
- // update the `tasks.json` file, instead of running the task itself
270
- this.items = this.getTaskItems().map((item: TaskRunQuickOpenItem) => new ConfigureBuildOrTestTaskQuickOpenItem(
271
- token,
272
- item.task,
273
- this.taskService,
274
- this.workspaceService.isMultiRootWorkspaceOpened,
275
- this.taskNameResolver,
276
- shouldRunBuildTask,
277
- this.taskConfigurationManager,
278
- this.taskDefinitionRegistry,
279
- this.taskSourceResolver
280
- ));
281
- this.quickInputService?.showQuickPick(this.items, { placeholder: `Select the task to be used as the default ${buildOrTestType} task` });
282
- });
283
- }
284
- })];
285
- }
286
- } else { // no tasks are currently present, prompt users if they'd like to configure a task.
287
- this.items = [{
288
- label: `No ${buildOrTestType} task to run found. Configure ${buildOrTestType.charAt(0).toUpperCase() + buildOrTestType.slice(1)} Task...`,
289
- execute: () => this.configure()
290
- }];
291
- }
292
-
293
- this.quickInputService?.showQuickPick(this.items, {
294
- placeholder: `Select the ${buildOrTestType} task to run`,
295
- onDidTriggerItemButton: ({ item }) => this.onDidTriggerGearIcon(item)
296
- });
297
- }
298
-
299
- async getPicks(filter: string, token: CancellationToken): Promise<QuickPicks> {
300
- if (this.items.length === 0) {
301
- await this.init();
302
- }
303
- return filterItems(this.items, filter);
304
- }
305
-
306
- registerQuickAccessProvider(): void {
307
- this.quickAccessRegistry.registerQuickAccessProvider({
308
- getInstance: () => this,
309
- prefix: QuickOpenTask.PREFIX,
310
- placeholder: 'Select the task to run',
311
- helpEntries: [{ description: 'Run Task', needsEditor: false }]
312
- });
313
- }
314
-
315
- protected getRunningTaskLabel(task: TaskInfo): string {
316
- return `Task id: ${task.taskId}, label: ${task.config.label}`;
317
- }
318
-
319
- private getItems(tasks: TaskConfiguration[], groupLabel: string, token: number, isMulti: boolean):
320
- QuickPickItemOrSeparator[] {
321
- const items: QuickPickItemOrSeparator[] = tasks.map(task =>
322
- new TaskRunQuickOpenItem(token, task, this.taskService, isMulti, this.taskDefinitionRegistry, this.taskNameResolver,
323
- this.taskSourceResolver, this.taskConfigurationManager, [{
324
- iconClass: 'codicon-gear',
325
- tooltip: 'Configure Task',
326
- }])
327
- );
328
-
329
- if (items.length > 0) {
330
- items.unshift({ type: 'separator', label: groupLabel });
331
- }
332
- return items;
333
- }
334
-
335
- private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], providedTasks: TaskConfiguration[]): {
336
- filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredProvidedTasks: TaskConfiguration[]
337
- } {
338
-
339
- const filteredRecentTasks: TaskConfiguration[] = [];
340
- recentTasks.forEach(recent => {
341
- const originalTaskConfig = [...configuredTasks, ...providedTasks].find(t => this.taskDefinitionRegistry.compareTasks(recent, t));
342
- if (originalTaskConfig) {
343
- filteredRecentTasks.push(originalTaskConfig);
344
- }
345
- });
346
-
347
- const filteredProvidedTasks: TaskConfiguration[] = [];
348
- providedTasks.forEach(provided => {
349
- const exist = [...filteredRecentTasks, ...configuredTasks].some(t => this.taskDefinitionRegistry.compareTasks(provided, t));
350
- if (!exist) {
351
- filteredProvidedTasks.push(provided);
352
- }
353
- });
354
-
355
- const filteredConfiguredTasks: TaskConfiguration[] = [];
356
- configuredTasks.forEach(configured => {
357
- const exist = filteredRecentTasks.some(t => this.taskDefinitionRegistry.compareTasks(configured, t));
358
- if (!exist) {
359
- filteredConfiguredTasks.push(configured);
360
- }
361
- });
362
-
363
- return {
364
- filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks
365
- };
366
- }
367
-
368
- private getGroupedTasksByWorkspaceFolder(tasks: TaskConfiguration[]): Map<string, TaskConfiguration[]> {
369
- const grouped = new Map<string, TaskConfiguration[]>();
370
- for (const task of tasks) {
371
- const scope = task._scope;
372
- if (grouped.has(scope.toString())) {
373
- grouped.get(scope.toString())!.push(task);
374
- } else {
375
- grouped.set(scope.toString(), [task]);
376
- }
377
- }
378
- for (const taskConfigs of grouped.values()) {
379
- taskConfigs.sort((t1, t2) => t1.label.localeCompare(t2.label));
380
- }
381
- return grouped;
382
- }
383
- }
384
-
385
- export class TaskRunQuickOpenItem implements QuickPickItem {
386
- constructor(
387
- readonly token: number,
388
- readonly task: TaskConfiguration,
389
- protected taskService: TaskService,
390
- protected isMulti: boolean,
391
- protected readonly taskDefinitionRegistry: TaskDefinitionRegistry,
392
- protected readonly taskNameResolver: TaskNameResolver,
393
- protected readonly taskSourceResolver: TaskSourceResolver,
394
- protected taskConfigurationManager: TaskConfigurationManager,
395
- readonly buttons?: Array<QuickInputButton>
396
- ) { }
397
-
398
- get label(): string {
399
- return this.taskNameResolver.resolve(this.task);
400
- }
401
-
402
- get description(): string {
403
- return renderScope(this.task._scope, this.isMulti);
404
- }
405
-
406
- get detail(): string | undefined {
407
- return this.task.detail;
408
- }
409
-
410
- execute(): void {
411
- const scope = this.task._scope;
412
- if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(this.task)) {
413
- this.taskService.run(this.token, this.task.source || this.task._source, this.task.label, scope);
414
- } else {
415
- this.taskService.run(this.token, this.task._source, this.task.label, scope);
416
- }
417
- }
418
-
419
- trigger(): TriggerAction {
420
- this.taskService.configure(this.token, this.task);
421
- return TriggerAction.CLOSE_PICKER;
422
- }
423
- }
424
-
425
- export class ConfigureBuildOrTestTaskQuickOpenItem extends TaskRunQuickOpenItem {
426
- constructor(
427
- token: number,
428
- task: TaskConfiguration,
429
- taskService: TaskService,
430
- isMulti: boolean,
431
- taskNameResolver: TaskNameResolver,
432
- protected readonly isBuildTask: boolean,
433
- taskConfigurationManager: TaskConfigurationManager,
434
- taskDefinitionRegistry: TaskDefinitionRegistry,
435
- taskSourceResolver: TaskSourceResolver
436
- ) {
437
- super(token, task, taskService, isMulti, taskDefinitionRegistry, taskNameResolver, taskSourceResolver, taskConfigurationManager);
438
- }
439
-
440
- override execute(): void {
441
- this.taskService.updateTaskConfiguration(this.token, this.task, { group: { kind: this.isBuildTask ? 'build' : 'test', isDefault: true } })
442
- .then(() => {
443
- if (this.task._scope) {
444
- this.taskConfigurationManager.openConfiguration(this.task._scope);
445
- }
446
- });
447
- }
448
- }
449
-
450
- function renderScope(scope: TaskConfigurationScope, isMulti: boolean): string {
451
- if (typeof scope === 'string') {
452
- if (isMulti) {
453
- return new URI(scope).displayName;
454
- } else {
455
- return '';
456
- }
457
- } else {
458
- return TaskScope[scope];
459
- }
460
- }
461
-
462
- export class TaskConfigureQuickOpenItem implements QuickPickItem {
463
-
464
- protected taskDefinitionRegistry: TaskDefinitionRegistry;
465
-
466
- constructor(
467
- protected readonly token: number,
468
- protected readonly task: TaskConfiguration,
469
- protected readonly taskService: TaskService,
470
- protected readonly taskNameResolver: TaskNameResolver,
471
- protected readonly workspaceService: WorkspaceService,
472
- protected readonly isMulti: boolean
473
- ) {
474
- const stat = this.workspaceService.workspace;
475
- this.isMulti = stat ? !stat.isDirectory : false;
476
- }
477
-
478
- get label(): string {
479
- return this.taskNameResolver.resolve(this.task);
480
- }
481
-
482
- get description(): string {
483
- return renderScope(this.task._scope, this.isMulti);
484
- }
485
-
486
- accept(): void {
487
- this.execute();
488
- }
489
-
490
- execute(): void {
491
- this.taskService.configure(this.token, this.task);
492
- }
493
- }
494
-
495
- @injectable()
496
- export class TaskTerminateQuickOpen {
497
-
498
- @inject(LabelProvider)
499
- protected readonly labelProvider: LabelProvider;
500
-
501
- @inject(QuickInputService) @optional()
502
- protected readonly quickInputService: QuickInputService;
503
-
504
- @inject(TaskDefinitionRegistry)
505
- protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
506
-
507
- @inject(TaskNameResolver)
508
- protected readonly taskNameResolver: TaskNameResolver;
509
-
510
- @inject(TaskSourceResolver)
511
- protected readonly taskSourceResolver: TaskSourceResolver;
512
-
513
- @inject(TaskService)
514
- protected readonly taskService: TaskService;
515
-
516
- @inject(WorkspaceService)
517
- protected readonly workspaceService: WorkspaceService;
518
-
519
- async getItems(): Promise<Array<QuickPickItem>> {
520
- const items: Array<QuickPickItem> = [];
521
- const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks();
522
- const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
523
- if (runningTasks.length <= 0) {
524
- items.push(({
525
- label: 'No task is currently running',
526
- }));
527
- } else {
528
- runningTasks.forEach((task: TaskInfo) => {
529
- items.push(new RunningTaskQuickOpenItem(
530
- task,
531
- this.taskService,
532
- this.taskNameResolver,
533
- this.taskSourceResolver,
534
- this.taskDefinitionRegistry,
535
- this.labelProvider,
536
- isMulti,
537
- () => this.taskService.kill(task.taskId)
538
- ));
539
- });
540
- if (runningTasks.length > 1) {
541
- items.push(({
542
- label: 'All running tasks',
543
- execute: () => {
544
- runningTasks.forEach((t: TaskInfo) => {
545
- this.taskService.kill(t.taskId);
546
- });
547
- }
548
- }));
549
- }
550
- }
551
- return items;
552
- }
553
-
554
- async open(): Promise<void> {
555
- const items = await this.getItems();
556
- this.quickInputService?.showQuickPick(items, { placeholder: 'Select task to terminate' });
557
- }
558
- }
559
-
560
- @injectable()
561
- export class TaskRunningQuickOpen {
562
- @inject(LabelProvider)
563
- protected readonly labelProvider: LabelProvider;
564
-
565
- @inject(QuickInputService) @optional()
566
- protected readonly quickInputService: QuickInputService;
567
-
568
- @inject(TaskDefinitionRegistry)
569
- protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
570
-
571
- @inject(TaskNameResolver)
572
- protected readonly taskNameResolver: TaskNameResolver;
573
-
574
- @inject(TaskSourceResolver)
575
- protected readonly taskSourceResolver: TaskSourceResolver;
576
-
577
- @inject(TaskService)
578
- protected readonly taskService: TaskService;
579
-
580
- @inject(WorkspaceService)
581
- protected readonly workspaceService: WorkspaceService;
582
-
583
- @inject(TerminalService)
584
- protected readonly terminalService: TerminalService;
585
-
586
- async getItems(): Promise<Array<QuickPickItem>> {
587
- const items: Array<QuickPickItem> = [];
588
- const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks();
589
- const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
590
- if (runningTasks.length <= 0) {
591
- items.push(({
592
- label: 'No task is currently running',
593
- }));
594
- } else {
595
- runningTasks.forEach((task: TaskInfo) => {
596
- items.push(new RunningTaskQuickOpenItem(
597
- task,
598
- this.taskService,
599
- this.taskNameResolver,
600
- this.taskSourceResolver,
601
- this.taskDefinitionRegistry,
602
- this.labelProvider,
603
- isMulti,
604
- () => {
605
- if (task.terminalId) {
606
- const terminal = this.terminalService.getByTerminalId(task.terminalId);
607
- if (terminal) {
608
- this.terminalService.open(terminal);
609
- }
610
- }
611
- }
612
- ));
613
- });
614
- }
615
- return items;
616
- }
617
-
618
- async open(): Promise<void> {
619
- const items = await this.getItems();
620
- this.quickInputService?.showQuickPick(items, { placeholder: 'Select the task to show its output' });
621
- }
622
- }
623
-
624
- export class RunningTaskQuickOpenItem implements QuickPickItem {
625
- constructor(
626
- protected readonly taskInfo: TaskInfo,
627
- protected readonly taskService: TaskService,
628
- protected readonly taskNameResolver: TaskNameResolver,
629
- protected readonly taskSourceResolver: TaskSourceResolver,
630
- protected readonly taskDefinitionRegistry: TaskDefinitionRegistry,
631
- protected readonly labelProvider: LabelProvider,
632
- protected readonly isMulti: boolean,
633
- public readonly execute: () => void,
634
- ) { }
635
-
636
- get label(): string {
637
- return this.taskNameResolver.resolve(this.taskInfo.config);
638
- }
639
-
640
- get description(): string {
641
- return renderScope(this.taskInfo.config._scope, this.isMulti);
642
- }
643
-
644
- get detail(): string | undefined {
645
- return this.taskInfo.config.detail;
646
- }
647
- }
648
-
649
- @injectable()
650
- export class TaskRestartRunningQuickOpen {
651
- @inject(LabelProvider)
652
- protected readonly labelProvider: LabelProvider;
653
-
654
- @inject(QuickInputService) @optional()
655
- protected readonly quickInputService: QuickInputService;
656
-
657
- @inject(TaskDefinitionRegistry)
658
- protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
659
-
660
- @inject(TaskNameResolver)
661
- protected readonly taskNameResolver: TaskNameResolver;
662
-
663
- @inject(TaskSourceResolver)
664
- protected readonly taskSourceResolver: TaskSourceResolver;
665
-
666
- @inject(TaskService)
667
- protected readonly taskService: TaskService;
668
-
669
- @inject(WorkspaceService)
670
- protected readonly workspaceService: WorkspaceService;
671
-
672
- async getItems(): Promise<Array<QuickPickItem>> {
673
- const items: Array<QuickPickItem> = [];
674
- const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks();
675
- const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
676
- if (runningTasks.length <= 0) {
677
- items.push({
678
- label: 'No task to restart'
679
- });
680
- } else {
681
- runningTasks.forEach((task: TaskInfo) => {
682
- items.push(new RunningTaskQuickOpenItem(
683
- task,
684
- this.taskService,
685
- this.taskNameResolver,
686
- this.taskSourceResolver,
687
- this.taskDefinitionRegistry,
688
- this.labelProvider,
689
- isMulti,
690
- () => this.taskService.restartTask(task)
691
- ));
692
- });
693
- }
694
- return items;
695
- }
696
-
697
- async open(): Promise<void> {
698
- const items = await this.getItems();
699
- this.quickInputService?.showQuickPick(items, { placeholder: 'Select task to restart' });
700
- }
701
- }
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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable, optional } from '@theia/core/shared/inversify';
18
+ import { TaskService } from './task-service';
19
+ import { TaskInfo, TaskConfiguration, TaskCustomization, TaskScope, TaskConfigurationScope } from '../common/task-protocol';
20
+ import { TaskDefinitionRegistry } from './task-definition-registry';
21
+ import URI from '@theia/core/lib/common/uri';
22
+ import { LabelProvider, QuickAccessProvider, QuickAccessRegistry, QuickInputService, PreferenceService } from '@theia/core/lib/browser';
23
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
24
+ import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
25
+ import { TaskNameResolver } from './task-name-resolver';
26
+ import { TaskSourceResolver } from './task-source-resolver';
27
+ import { TaskConfigurationManager } from './task-configuration-manager';
28
+ import { filterItems, QuickInputButton, QuickPickItem, QuickPickItemOrSeparator, QuickPicks } from '@theia/core/lib/browser/quick-input/quick-input-service';
29
+ import { CancellationToken } from '@theia/core/lib/common';
30
+ import { TriggerAction } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/browser/pickerQuickAccess';
31
+
32
+ export namespace ConfigureTaskAction {
33
+ export const ID = 'workbench.action.tasks.configureTaskRunner';
34
+ export const TEXT = 'Configure Task';
35
+ }
36
+
37
+ @injectable()
38
+ export class QuickOpenTask implements QuickAccessProvider {
39
+ static readonly PREFIX = 'task ';
40
+ readonly description: string = 'Run Task';
41
+ protected items: Array<QuickPickItemOrSeparator> = [];
42
+
43
+ @inject(TaskService)
44
+ protected readonly taskService: TaskService;
45
+
46
+ @inject(QuickInputService) @optional()
47
+ protected readonly quickInputService: QuickInputService;
48
+
49
+ @inject(QuickAccessRegistry)
50
+ protected readonly quickAccessRegistry: QuickAccessRegistry;
51
+
52
+ @inject(WorkspaceService)
53
+ protected readonly workspaceService: WorkspaceService;
54
+
55
+ @inject(TaskDefinitionRegistry)
56
+ protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
57
+
58
+ @inject(TaskNameResolver)
59
+ protected readonly taskNameResolver: TaskNameResolver;
60
+
61
+ @inject(TaskSourceResolver)
62
+ protected readonly taskSourceResolver: TaskSourceResolver;
63
+
64
+ @inject(TaskConfigurationManager)
65
+ protected readonly taskConfigurationManager: TaskConfigurationManager;
66
+
67
+ @inject(PreferenceService)
68
+ protected readonly preferences: PreferenceService;
69
+
70
+ @inject(LabelProvider)
71
+ protected readonly labelProvider: LabelProvider;
72
+
73
+ init(): Promise<void> {
74
+ return this.doInit(this.taskService.startUserAction());
75
+ }
76
+
77
+ protected async doInit(token: number): Promise<void> {
78
+ const recentTasks = this.taskService.recentTasks;
79
+ const configuredTasks = await this.taskService.getConfiguredTasks(token);
80
+ const providedTasks = await this.taskService.getProvidedTasks(token);
81
+
82
+ const { filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, providedTasks);
83
+ const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
84
+ this.items = [];
85
+
86
+ const filteredRecentTasksItems = this.getItems(filteredRecentTasks, 'recently used tasks', token, isMulti);
87
+ const filteredConfiguredTasksItems = this.getItems(filteredConfiguredTasks, 'configured tasks', token, isMulti);
88
+ const filteredProvidedTasksItems = this.getItems(filteredProvidedTasks, 'detected tasks', token, isMulti);
89
+
90
+ this.items.push(
91
+ ...filteredRecentTasksItems,
92
+ ...filteredConfiguredTasksItems,
93
+ ...filteredProvidedTasksItems
94
+ );
95
+ }
96
+
97
+ protected onDidTriggerGearIcon(item: QuickPickItem): void {
98
+ if (item instanceof TaskRunQuickOpenItem) {
99
+ this.taskService.configure(item.token, item.task);
100
+ this.quickInputService.hide();
101
+ }
102
+ }
103
+
104
+ async open(): Promise<void> {
105
+ await this.init();
106
+ if (!this.items.length) {
107
+ this.items.push(({
108
+ label: 'No task to run found. Configure Tasks...',
109
+ execute: () => this.configure()
110
+ }));
111
+ }
112
+ this.quickInputService?.showQuickPick(this.items, {
113
+ placeholder: 'Select the task to run',
114
+ onDidTriggerItemButton: ({ item }) => this.onDidTriggerGearIcon(item)
115
+ });
116
+ }
117
+
118
+ attach(): void {
119
+ this.items = [];
120
+ const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
121
+ this.taskService.getRunningTasks().then(tasks => {
122
+ if (!tasks.length) {
123
+ this.items.push({
124
+ label: 'No tasks found',
125
+ });
126
+ } else {
127
+ tasks.forEach((task: TaskInfo) => {
128
+ // can only attach to terminal processes, so only list those
129
+ if (task.terminalId) {
130
+ this.items.push(new RunningTaskQuickOpenItem(
131
+ task,
132
+ this.taskService,
133
+ this.taskNameResolver,
134
+ this.taskSourceResolver,
135
+ this.taskDefinitionRegistry,
136
+ this.labelProvider,
137
+ isMulti,
138
+ () => this.taskService.attach(task.terminalId!, task)
139
+ ));
140
+ }
141
+ });
142
+ }
143
+ if (this.items.length === 0) {
144
+ this.items.push(({
145
+ label: 'No tasks found'
146
+ }));
147
+ }
148
+ this.quickInputService?.showQuickPick(this.items, { placeholder: 'Choose task to open' });
149
+ });
150
+ }
151
+
152
+ async configure(): Promise<void> {
153
+ this.items = [];
154
+ const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
155
+ const token: number = this.taskService.startUserAction();
156
+
157
+ const configuredTasks = await this.taskService.getConfiguredTasks(token);
158
+ const providedTasks = await this.taskService.getProvidedTasks(token);
159
+
160
+ // check if tasks.json exists. If not, display "Create tasks.json file from template"
161
+ // If tasks.json exists and empty, display 'Open tasks.json file'
162
+ const { filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks([], configuredTasks, providedTasks);
163
+ const groupedTasks = this.getGroupedTasksByWorkspaceFolder([...filteredConfiguredTasks, ...filteredProvidedTasks]);
164
+ if (groupedTasks.has(TaskScope.Global.toString())) {
165
+ const configs = groupedTasks.get(TaskScope.Global.toString())!;
166
+ this.items.push(
167
+ ...configs.map(taskConfig => {
168
+ const item = new TaskConfigureQuickOpenItem(
169
+ token,
170
+ taskConfig,
171
+ this.taskService,
172
+ this.taskNameResolver,
173
+ this.workspaceService,
174
+ isMulti
175
+ );
176
+ item['taskDefinitionRegistry'] = this.taskDefinitionRegistry;
177
+ return item;
178
+ })
179
+ );
180
+ }
181
+
182
+ const rootUris = (await this.workspaceService.roots).map(rootStat => rootStat.resource.toString());
183
+ for (const rootFolder of rootUris) {
184
+ const folderName = new URI(rootFolder).displayName;
185
+ if (groupedTasks.has(rootFolder)) {
186
+ const configs = groupedTasks.get(rootFolder.toString())!;
187
+ this.items.push(
188
+ ...configs.map((taskConfig, index) => {
189
+ const item = new TaskConfigureQuickOpenItem(
190
+ token,
191
+ taskConfig,
192
+ this.taskService,
193
+ this.taskNameResolver,
194
+ this.workspaceService,
195
+ isMulti,
196
+
197
+ );
198
+ item['taskDefinitionRegistry'] = this.taskDefinitionRegistry;
199
+ return item;
200
+ })
201
+ );
202
+ } else {
203
+ const { configUri } = this.preferences.resolve('tasks', [], rootFolder);
204
+ const existTaskConfigFile = !!configUri;
205
+ this.items.push(({
206
+ label: existTaskConfigFile ? 'Open tasks.json file' : 'Create tasks.json file from template',
207
+ execute: () => {
208
+ setTimeout(() => this.taskConfigurationManager.openConfiguration(rootFolder));
209
+ }
210
+ }));
211
+ }
212
+ if (this.items.length > 0) {
213
+ this.items.unshift({
214
+ type: 'separator',
215
+ label: isMulti ? folderName : ''
216
+ });
217
+ }
218
+ }
219
+
220
+ if (this.items.length === 0) {
221
+ this.items.push(({
222
+ label: 'No tasks found'
223
+ }));
224
+ }
225
+
226
+ this.quickInputService?.showQuickPick(this.items, { placeholder: 'Select a task to configure' });
227
+ }
228
+
229
+ protected getTaskItems(): QuickPickItem[] {
230
+ return this.items.filter((item): item is QuickPickItem => item.type !== 'separator' && (item as TaskRunQuickOpenItem).task !== undefined);
231
+ }
232
+
233
+ async runBuildOrTestTask(buildOrTestType: 'build' | 'test'): Promise<void> {
234
+ const shouldRunBuildTask = buildOrTestType === 'build';
235
+ const token: number = this.taskService.startUserAction();
236
+
237
+ await this.doInit(token);
238
+
239
+ const taskItems = this.getTaskItems();
240
+
241
+ if (taskItems.length > 0) { // the item in `this.items` is not 'No tasks found'
242
+ const buildOrTestTasks = taskItems.filter((t: TaskRunQuickOpenItem) =>
243
+ shouldRunBuildTask ? TaskCustomization.isBuildTask(t.task) : TaskCustomization.isTestTask(t.task)
244
+ );
245
+ if (buildOrTestTasks.length > 0) { // build / test tasks are defined in the workspace
246
+ const defaultBuildOrTestTasks = buildOrTestTasks.filter((t: TaskRunQuickOpenItem) =>
247
+ shouldRunBuildTask ? TaskCustomization.isDefaultBuildTask(t.task) : TaskCustomization.isDefaultTestTask(t.task)
248
+ );
249
+ if (defaultBuildOrTestTasks.length === 1) { // run the default build / test task
250
+ const defaultBuildOrTestTask = defaultBuildOrTestTasks[0];
251
+ const taskToRun = (defaultBuildOrTestTask as TaskRunQuickOpenItem).task;
252
+ const scope = taskToRun._scope;
253
+
254
+ if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(taskToRun)) {
255
+ this.taskService.run(token, taskToRun.source, taskToRun.label, scope);
256
+ } else {
257
+ this.taskService.run(token, taskToRun._source, taskToRun.label, scope);
258
+ }
259
+ return;
260
+ }
261
+ // if default build / test task is not found, or there are more than one default,
262
+ // display the list of build /test tasks to let the user decide which to run
263
+ this.items = buildOrTestTasks;
264
+ } else { // no build / test tasks, display an action item to configure the build / test task
265
+ this.items = [({
266
+ label: `No ${buildOrTestType} task to run found. Configure ${buildOrTestType.charAt(0).toUpperCase() + buildOrTestType.slice(1)} Task...`,
267
+ execute: () => {
268
+ this.doInit(token).then(() => {
269
+ // update the `tasks.json` file, instead of running the task itself
270
+ this.items = this.getTaskItems().map((item: TaskRunQuickOpenItem) => new ConfigureBuildOrTestTaskQuickOpenItem(
271
+ token,
272
+ item.task,
273
+ this.taskService,
274
+ this.workspaceService.isMultiRootWorkspaceOpened,
275
+ this.taskNameResolver,
276
+ shouldRunBuildTask,
277
+ this.taskConfigurationManager,
278
+ this.taskDefinitionRegistry,
279
+ this.taskSourceResolver
280
+ ));
281
+ this.quickInputService?.showQuickPick(this.items, { placeholder: `Select the task to be used as the default ${buildOrTestType} task` });
282
+ });
283
+ }
284
+ })];
285
+ }
286
+ } else { // no tasks are currently present, prompt users if they'd like to configure a task.
287
+ this.items = [{
288
+ label: `No ${buildOrTestType} task to run found. Configure ${buildOrTestType.charAt(0).toUpperCase() + buildOrTestType.slice(1)} Task...`,
289
+ execute: () => this.configure()
290
+ }];
291
+ }
292
+
293
+ this.quickInputService?.showQuickPick(this.items, {
294
+ placeholder: `Select the ${buildOrTestType} task to run`,
295
+ onDidTriggerItemButton: ({ item }) => this.onDidTriggerGearIcon(item)
296
+ });
297
+ }
298
+
299
+ async getPicks(filter: string, token: CancellationToken): Promise<QuickPicks> {
300
+ if (this.items.length === 0) {
301
+ await this.init();
302
+ }
303
+ return filterItems(this.items, filter);
304
+ }
305
+
306
+ registerQuickAccessProvider(): void {
307
+ this.quickAccessRegistry.registerQuickAccessProvider({
308
+ getInstance: () => this,
309
+ prefix: QuickOpenTask.PREFIX,
310
+ placeholder: 'Select the task to run',
311
+ helpEntries: [{ description: 'Run Task', needsEditor: false }]
312
+ });
313
+ }
314
+
315
+ protected getRunningTaskLabel(task: TaskInfo): string {
316
+ return `Task id: ${task.taskId}, label: ${task.config.label}`;
317
+ }
318
+
319
+ private getItems(tasks: TaskConfiguration[], groupLabel: string, token: number, isMulti: boolean):
320
+ QuickPickItemOrSeparator[] {
321
+ const items: QuickPickItemOrSeparator[] = tasks.map(task =>
322
+ new TaskRunQuickOpenItem(token, task, this.taskService, isMulti, this.taskDefinitionRegistry, this.taskNameResolver,
323
+ this.taskSourceResolver, this.taskConfigurationManager, [{
324
+ iconClass: 'codicon-gear',
325
+ tooltip: 'Configure Task',
326
+ }])
327
+ );
328
+
329
+ if (items.length > 0) {
330
+ items.unshift({ type: 'separator', label: groupLabel });
331
+ }
332
+ return items;
333
+ }
334
+
335
+ private getFilteredTasks(recentTasks: TaskConfiguration[], configuredTasks: TaskConfiguration[], providedTasks: TaskConfiguration[]): {
336
+ filteredRecentTasks: TaskConfiguration[], filteredConfiguredTasks: TaskConfiguration[], filteredProvidedTasks: TaskConfiguration[]
337
+ } {
338
+
339
+ const filteredRecentTasks: TaskConfiguration[] = [];
340
+ recentTasks.forEach(recent => {
341
+ const originalTaskConfig = [...configuredTasks, ...providedTasks].find(t => this.taskDefinitionRegistry.compareTasks(recent, t));
342
+ if (originalTaskConfig) {
343
+ filteredRecentTasks.push(originalTaskConfig);
344
+ }
345
+ });
346
+
347
+ const filteredProvidedTasks: TaskConfiguration[] = [];
348
+ providedTasks.forEach(provided => {
349
+ const exist = [...filteredRecentTasks, ...configuredTasks].some(t => this.taskDefinitionRegistry.compareTasks(provided, t));
350
+ if (!exist) {
351
+ filteredProvidedTasks.push(provided);
352
+ }
353
+ });
354
+
355
+ const filteredConfiguredTasks: TaskConfiguration[] = [];
356
+ configuredTasks.forEach(configured => {
357
+ const exist = filteredRecentTasks.some(t => this.taskDefinitionRegistry.compareTasks(configured, t));
358
+ if (!exist) {
359
+ filteredConfiguredTasks.push(configured);
360
+ }
361
+ });
362
+
363
+ return {
364
+ filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks
365
+ };
366
+ }
367
+
368
+ private getGroupedTasksByWorkspaceFolder(tasks: TaskConfiguration[]): Map<string, TaskConfiguration[]> {
369
+ const grouped = new Map<string, TaskConfiguration[]>();
370
+ for (const task of tasks) {
371
+ const scope = task._scope;
372
+ if (grouped.has(scope.toString())) {
373
+ grouped.get(scope.toString())!.push(task);
374
+ } else {
375
+ grouped.set(scope.toString(), [task]);
376
+ }
377
+ }
378
+ for (const taskConfigs of grouped.values()) {
379
+ taskConfigs.sort((t1, t2) => t1.label.localeCompare(t2.label));
380
+ }
381
+ return grouped;
382
+ }
383
+ }
384
+
385
+ export class TaskRunQuickOpenItem implements QuickPickItem {
386
+ constructor(
387
+ readonly token: number,
388
+ readonly task: TaskConfiguration,
389
+ protected taskService: TaskService,
390
+ protected isMulti: boolean,
391
+ protected readonly taskDefinitionRegistry: TaskDefinitionRegistry,
392
+ protected readonly taskNameResolver: TaskNameResolver,
393
+ protected readonly taskSourceResolver: TaskSourceResolver,
394
+ protected taskConfigurationManager: TaskConfigurationManager,
395
+ readonly buttons?: Array<QuickInputButton>
396
+ ) { }
397
+
398
+ get label(): string {
399
+ return this.taskNameResolver.resolve(this.task);
400
+ }
401
+
402
+ get description(): string {
403
+ return renderScope(this.task._scope, this.isMulti);
404
+ }
405
+
406
+ get detail(): string | undefined {
407
+ return this.task.detail;
408
+ }
409
+
410
+ execute(): void {
411
+ const scope = this.task._scope;
412
+ if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(this.task)) {
413
+ this.taskService.run(this.token, this.task.source || this.task._source, this.task.label, scope);
414
+ } else {
415
+ this.taskService.run(this.token, this.task._source, this.task.label, scope);
416
+ }
417
+ }
418
+
419
+ trigger(): TriggerAction {
420
+ this.taskService.configure(this.token, this.task);
421
+ return TriggerAction.CLOSE_PICKER;
422
+ }
423
+ }
424
+
425
+ export class ConfigureBuildOrTestTaskQuickOpenItem extends TaskRunQuickOpenItem {
426
+ constructor(
427
+ token: number,
428
+ task: TaskConfiguration,
429
+ taskService: TaskService,
430
+ isMulti: boolean,
431
+ taskNameResolver: TaskNameResolver,
432
+ protected readonly isBuildTask: boolean,
433
+ taskConfigurationManager: TaskConfigurationManager,
434
+ taskDefinitionRegistry: TaskDefinitionRegistry,
435
+ taskSourceResolver: TaskSourceResolver
436
+ ) {
437
+ super(token, task, taskService, isMulti, taskDefinitionRegistry, taskNameResolver, taskSourceResolver, taskConfigurationManager);
438
+ }
439
+
440
+ override execute(): void {
441
+ this.taskService.updateTaskConfiguration(this.token, this.task, { group: { kind: this.isBuildTask ? 'build' : 'test', isDefault: true } })
442
+ .then(() => {
443
+ if (this.task._scope) {
444
+ this.taskConfigurationManager.openConfiguration(this.task._scope);
445
+ }
446
+ });
447
+ }
448
+ }
449
+
450
+ function renderScope(scope: TaskConfigurationScope, isMulti: boolean): string {
451
+ if (typeof scope === 'string') {
452
+ if (isMulti) {
453
+ return new URI(scope).displayName;
454
+ } else {
455
+ return '';
456
+ }
457
+ } else {
458
+ return TaskScope[scope];
459
+ }
460
+ }
461
+
462
+ export class TaskConfigureQuickOpenItem implements QuickPickItem {
463
+
464
+ protected taskDefinitionRegistry: TaskDefinitionRegistry;
465
+
466
+ constructor(
467
+ protected readonly token: number,
468
+ protected readonly task: TaskConfiguration,
469
+ protected readonly taskService: TaskService,
470
+ protected readonly taskNameResolver: TaskNameResolver,
471
+ protected readonly workspaceService: WorkspaceService,
472
+ protected readonly isMulti: boolean
473
+ ) {
474
+ const stat = this.workspaceService.workspace;
475
+ this.isMulti = stat ? !stat.isDirectory : false;
476
+ }
477
+
478
+ get label(): string {
479
+ return this.taskNameResolver.resolve(this.task);
480
+ }
481
+
482
+ get description(): string {
483
+ return renderScope(this.task._scope, this.isMulti);
484
+ }
485
+
486
+ accept(): void {
487
+ this.execute();
488
+ }
489
+
490
+ execute(): void {
491
+ this.taskService.configure(this.token, this.task);
492
+ }
493
+ }
494
+
495
+ @injectable()
496
+ export class TaskTerminateQuickOpen {
497
+
498
+ @inject(LabelProvider)
499
+ protected readonly labelProvider: LabelProvider;
500
+
501
+ @inject(QuickInputService) @optional()
502
+ protected readonly quickInputService: QuickInputService;
503
+
504
+ @inject(TaskDefinitionRegistry)
505
+ protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
506
+
507
+ @inject(TaskNameResolver)
508
+ protected readonly taskNameResolver: TaskNameResolver;
509
+
510
+ @inject(TaskSourceResolver)
511
+ protected readonly taskSourceResolver: TaskSourceResolver;
512
+
513
+ @inject(TaskService)
514
+ protected readonly taskService: TaskService;
515
+
516
+ @inject(WorkspaceService)
517
+ protected readonly workspaceService: WorkspaceService;
518
+
519
+ async getItems(): Promise<Array<QuickPickItem>> {
520
+ const items: Array<QuickPickItem> = [];
521
+ const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks();
522
+ const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
523
+ if (runningTasks.length <= 0) {
524
+ items.push(({
525
+ label: 'No task is currently running',
526
+ }));
527
+ } else {
528
+ runningTasks.forEach((task: TaskInfo) => {
529
+ items.push(new RunningTaskQuickOpenItem(
530
+ task,
531
+ this.taskService,
532
+ this.taskNameResolver,
533
+ this.taskSourceResolver,
534
+ this.taskDefinitionRegistry,
535
+ this.labelProvider,
536
+ isMulti,
537
+ () => this.taskService.kill(task.taskId)
538
+ ));
539
+ });
540
+ if (runningTasks.length > 1) {
541
+ items.push(({
542
+ label: 'All running tasks',
543
+ execute: () => {
544
+ runningTasks.forEach((t: TaskInfo) => {
545
+ this.taskService.kill(t.taskId);
546
+ });
547
+ }
548
+ }));
549
+ }
550
+ }
551
+ return items;
552
+ }
553
+
554
+ async open(): Promise<void> {
555
+ const items = await this.getItems();
556
+ this.quickInputService?.showQuickPick(items, { placeholder: 'Select task to terminate' });
557
+ }
558
+ }
559
+
560
+ @injectable()
561
+ export class TaskRunningQuickOpen {
562
+ @inject(LabelProvider)
563
+ protected readonly labelProvider: LabelProvider;
564
+
565
+ @inject(QuickInputService) @optional()
566
+ protected readonly quickInputService: QuickInputService;
567
+
568
+ @inject(TaskDefinitionRegistry)
569
+ protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
570
+
571
+ @inject(TaskNameResolver)
572
+ protected readonly taskNameResolver: TaskNameResolver;
573
+
574
+ @inject(TaskSourceResolver)
575
+ protected readonly taskSourceResolver: TaskSourceResolver;
576
+
577
+ @inject(TaskService)
578
+ protected readonly taskService: TaskService;
579
+
580
+ @inject(WorkspaceService)
581
+ protected readonly workspaceService: WorkspaceService;
582
+
583
+ @inject(TerminalService)
584
+ protected readonly terminalService: TerminalService;
585
+
586
+ async getItems(): Promise<Array<QuickPickItem>> {
587
+ const items: Array<QuickPickItem> = [];
588
+ const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks();
589
+ const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
590
+ if (runningTasks.length <= 0) {
591
+ items.push(({
592
+ label: 'No task is currently running',
593
+ }));
594
+ } else {
595
+ runningTasks.forEach((task: TaskInfo) => {
596
+ items.push(new RunningTaskQuickOpenItem(
597
+ task,
598
+ this.taskService,
599
+ this.taskNameResolver,
600
+ this.taskSourceResolver,
601
+ this.taskDefinitionRegistry,
602
+ this.labelProvider,
603
+ isMulti,
604
+ () => {
605
+ if (task.terminalId) {
606
+ const terminal = this.terminalService.getByTerminalId(task.terminalId);
607
+ if (terminal) {
608
+ this.terminalService.open(terminal);
609
+ }
610
+ }
611
+ }
612
+ ));
613
+ });
614
+ }
615
+ return items;
616
+ }
617
+
618
+ async open(): Promise<void> {
619
+ const items = await this.getItems();
620
+ this.quickInputService?.showQuickPick(items, { placeholder: 'Select the task to show its output' });
621
+ }
622
+ }
623
+
624
+ export class RunningTaskQuickOpenItem implements QuickPickItem {
625
+ constructor(
626
+ protected readonly taskInfo: TaskInfo,
627
+ protected readonly taskService: TaskService,
628
+ protected readonly taskNameResolver: TaskNameResolver,
629
+ protected readonly taskSourceResolver: TaskSourceResolver,
630
+ protected readonly taskDefinitionRegistry: TaskDefinitionRegistry,
631
+ protected readonly labelProvider: LabelProvider,
632
+ protected readonly isMulti: boolean,
633
+ public readonly execute: () => void,
634
+ ) { }
635
+
636
+ get label(): string {
637
+ return this.taskNameResolver.resolve(this.taskInfo.config);
638
+ }
639
+
640
+ get description(): string {
641
+ return renderScope(this.taskInfo.config._scope, this.isMulti);
642
+ }
643
+
644
+ get detail(): string | undefined {
645
+ return this.taskInfo.config.detail;
646
+ }
647
+ }
648
+
649
+ @injectable()
650
+ export class TaskRestartRunningQuickOpen {
651
+ @inject(LabelProvider)
652
+ protected readonly labelProvider: LabelProvider;
653
+
654
+ @inject(QuickInputService) @optional()
655
+ protected readonly quickInputService: QuickInputService;
656
+
657
+ @inject(TaskDefinitionRegistry)
658
+ protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;
659
+
660
+ @inject(TaskNameResolver)
661
+ protected readonly taskNameResolver: TaskNameResolver;
662
+
663
+ @inject(TaskSourceResolver)
664
+ protected readonly taskSourceResolver: TaskSourceResolver;
665
+
666
+ @inject(TaskService)
667
+ protected readonly taskService: TaskService;
668
+
669
+ @inject(WorkspaceService)
670
+ protected readonly workspaceService: WorkspaceService;
671
+
672
+ async getItems(): Promise<Array<QuickPickItem>> {
673
+ const items: Array<QuickPickItem> = [];
674
+ const runningTasks: TaskInfo[] = await this.taskService.getRunningTasks();
675
+ const isMulti: boolean = this.workspaceService.isMultiRootWorkspaceOpened;
676
+ if (runningTasks.length <= 0) {
677
+ items.push({
678
+ label: 'No task to restart'
679
+ });
680
+ } else {
681
+ runningTasks.forEach((task: TaskInfo) => {
682
+ items.push(new RunningTaskQuickOpenItem(
683
+ task,
684
+ this.taskService,
685
+ this.taskNameResolver,
686
+ this.taskSourceResolver,
687
+ this.taskDefinitionRegistry,
688
+ this.labelProvider,
689
+ isMulti,
690
+ () => this.taskService.restartTask(task)
691
+ ));
692
+ });
693
+ }
694
+ return items;
695
+ }
696
+
697
+ async open(): Promise<void> {
698
+ const items = await this.getItems();
699
+ this.quickInputService?.showQuickPick(items, { placeholder: 'Select task to restart' });
700
+ }
701
+ }