1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Disposable } from 'vs/base/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { MenuRegistry, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { ProblemMatcherRegistry } from 'vs/workbench/contrib/tasks/common/problemMatcher';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import * as jsonContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { StatusbarAlignment, IStatusbarService, IStatusbarEntryAccessor, IStatusbarEntry } from 'vs/workbench/services/statusbar/browser/statusbar';
import { IOutputChannelRegistry, Extensions as OutputExt } from 'vs/workbench/services/output/common/output';
import { ITaskEvent, TaskEventKind, TaskGroup, TaskSettingId, TASKS_CATEGORY, TASK_RUNNING_STATE } from 'vs/workbench/contrib/tasks/common/tasks';
import { ITaskService, ProcessExecutionSupportedContext, ShellExecutionSupportedContext, TaskCommandsRegistered } from 'vs/workbench/contrib/tasks/common/taskService';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { RunAutomaticTasks, ManageAutomaticTaskRunning } from 'vs/workbench/contrib/tasks/browser/runAutomaticTasks';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import schemaVersion1 from '../common/jsonSchema_v1';
import schemaVersion2, { updateProblemMatchers, updateTaskDefinitions } from '../common/jsonSchema_v2';
import { AbstractTaskService, ConfigureTaskAction } from 'vs/workbench/contrib/tasks/browser/abstractTaskService';
import { tasksSchemaId } from 'vs/workbench/services/configuration/common/configuration';
import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { WorkbenchStateContext } from 'vs/workbench/common/contextkeys';
import { IQuickAccessRegistry, Extensions as QuickAccessExtensions } from 'vs/platform/quickinput/common/quickAccess';
import { TasksQuickAccessProvider } from 'vs/workbench/contrib/tasks/browser/tasksQuickAccess';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDefinitionRegistry';
import { TerminalMenuBarGroup } from 'vs/workbench/contrib/terminal/browser/terminalMenus';
import { isString } from 'vs/base/common/types';
const SHOW_TASKS_COMMANDS_CONTEXT = ContextKeyExpr.and(ShellExecutionSupportedContext, ProcessExecutionSupportedContext);
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(RunAutomaticTasks, LifecyclePhase.Eventually);
registerAction2(ManageAutomaticTaskRunning);
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: ManageAutomaticTaskRunning.ID,
title: ManageAutomaticTaskRunning.LABEL,
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
export class TaskStatusBarContributions extends Disposable implements IWorkbenchContribution {
private _runningTasksStatusItem: IStatusbarEntryAccessor | undefined;
private _activeTasksCount: number = 0;
constructor(
@ITaskService private readonly _taskService: ITaskService,
@IStatusbarService private readonly _statusbarService: IStatusbarService,
@IProgressService private readonly _progressService: IProgressService
) {
super();
this._registerListeners();
}
private _registerListeners(): void {
let promise: Promise<void> | undefined = undefined;
let resolver: (value?: void | Thenable<void>) => void;
this._taskService.onDidStateChange(event => {
if (event.kind === TaskEventKind.Changed) {
this._updateRunningTasksStatus();
}
if (!this._ignoreEventForUpdateRunningTasksCount(event)) {
switch (event.kind) {
case TaskEventKind.Active:
this._activeTasksCount++;
if (this._activeTasksCount === 1) {
if (!promise) {
promise = new Promise<void>((resolve) => {
resolver = resolve;
});
}
}
break;
case TaskEventKind.Inactive:
// Since the exiting of the sub process is communicated async we can't order inactive and terminate events.
// So try to treat them accordingly.
if (this._activeTasksCount > 0) {
this._activeTasksCount--;
if (this._activeTasksCount === 0) {
if (promise && resolver!) {
resolver!();
}
}
}
break;
case TaskEventKind.Terminated:
if (this._activeTasksCount !== 0) {
this._activeTasksCount = 0;
if (promise && resolver!) {
resolver!();
}
}
break;
}
}
if (promise && (event.kind === TaskEventKind.Active) && (this._activeTasksCount === 1)) {
this._progressService.withProgress({ location: ProgressLocation.Window, command: 'workbench.action.tasks.showTasks' }, progress => {
progress.report({ message: nls.localize('building', 'Building...') });
return promise!;
}).then(() => {
promise = undefined;
});
}
});
}
private async _updateRunningTasksStatus(): Promise<void> {
const tasks = await this._taskService.getActiveTasks();
if (tasks.length === 0) {
if (this._runningTasksStatusItem) {
this._runningTasksStatusItem.dispose();
this._runningTasksStatusItem = undefined;
}
} else {
const itemProps: IStatusbarEntry = {
name: nls.localize('status.runningTasks', "Running Tasks"),
text: `$(tools) ${tasks.length}`,
ariaLabel: nls.localize('numberOfRunningTasks', "{0} running tasks", tasks.length),
tooltip: nls.localize('runningTasks', "Show Running Tasks"),
command: 'workbench.action.tasks.showTasks',
};
if (!this._runningTasksStatusItem) {
this._runningTasksStatusItem = this._statusbarService.addEntry(itemProps, 'status.runningTasks', StatusbarAlignment.LEFT, 49 /* Medium Priority, next to Markers */);
} else {
this._runningTasksStatusItem.update(itemProps);
}
}
}
private _ignoreEventForUpdateRunningTasksCount(event: ITaskEvent): boolean {
if (!this._taskService.inTerminal()) {
return false;
}
if ((isString(event.group) ? event.group : event.group?._id) !== TaskGroup.Build._id) {
return true;
}
if (!event.__task) {
return false;
}
return event.__task.configurationProperties.problemMatchers === undefined || event.__task.configurationProperties.problemMatchers.length === 0;
}
}
workbenchRegistry.registerWorkbenchContribution(TaskStatusBarContributions, LifecyclePhase.Restored);
MenuRegistry.appendMenuItem(MenuId.MenubarTerminalMenu, {
group: TerminalMenuBarGroup.Run,
command: {
id: 'workbench.action.tasks.runTask',
title: nls.localize({ key: 'miRunTask', comment: ['&& denotes a mnemonic'] }, "&&Run Task...")
},
order: 1,
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.MenubarTerminalMenu, {
group: TerminalMenuBarGroup.Run,
command: {
id: 'workbench.action.tasks.build',
title: nls.localize({ key: 'miBuildTask', comment: ['&& denotes a mnemonic'] }, "Run &&Build Task...")
},
order: 2,
when: SHOW_TASKS_COMMANDS_CONTEXT
});
// Manage Tasks
MenuRegistry.appendMenuItem(MenuId.MenubarTerminalMenu, {
group: TerminalMenuBarGroup.Manage,
command: {
precondition: TASK_RUNNING_STATE,
id: 'workbench.action.tasks.showTasks',
title: nls.localize({ key: 'miRunningTask', comment: ['&& denotes a mnemonic'] }, "Show Runnin&&g Tasks...")
},
order: 1,
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.MenubarTerminalMenu, {
group: TerminalMenuBarGroup.Manage,
command: {
precondition: TASK_RUNNING_STATE,
id: 'workbench.action.tasks.restartTask',
title: nls.localize({ key: 'miRestartTask', comment: ['&& denotes a mnemonic'] }, "R&&estart Running Task...")
},
order: 2,
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.MenubarTerminalMenu, {
group: TerminalMenuBarGroup.Manage,
command: {
precondition: TASK_RUNNING_STATE,
id: 'workbench.action.tasks.terminate',
title: nls.localize({ key: 'miTerminateTask', comment: ['&& denotes a mnemonic'] }, "&&Terminate Task...")
},
order: 3,
when: SHOW_TASKS_COMMANDS_CONTEXT
});
// Configure Tasks
MenuRegistry.appendMenuItem(MenuId.MenubarTerminalMenu, {
group: TerminalMenuBarGroup.Configure,
command: {
id: 'workbench.action.tasks.configureTaskRunner',
title: nls.localize({ key: 'miConfigureTask', comment: ['&& denotes a mnemonic'] }, "&&Configure Tasks...")
},
order: 1,
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.MenubarTerminalMenu, {
group: TerminalMenuBarGroup.Configure,
command: {
id: 'workbench.action.tasks.configureDefaultBuildTask',
title: nls.localize({ key: 'miConfigureBuildTask', comment: ['&& denotes a mnemonic'] }, "Configure De&&fault Build Task...")
},
order: 2,
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.openWorkspaceFileTasks',
title: { value: nls.localize('workbench.action.tasks.openWorkspaceFileTasks', "Open Workspace Tasks"), original: 'Open Workspace Tasks' },
category: TASKS_CATEGORY
},
when: ContextKeyExpr.and(WorkbenchStateContext.isEqualTo('workspace'), SHOW_TASKS_COMMANDS_CONTEXT)
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: ConfigureTaskAction.ID,
title: { value: ConfigureTaskAction.TEXT, original: 'Configure Task' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.showLog',
title: { value: nls.localize('ShowLogAction.label', "Show Task Log"), original: 'Show Task Log' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.runTask',
title: { value: nls.localize('RunTaskAction.label', "Run Task"), original: 'Run Task' },
category: TASKS_CATEGORY
}
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.reRunTask',
title: { value: nls.localize('ReRunTaskAction.label', "Rerun Last Task"), original: 'Rerun Last Task' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.restartTask',
title: { value: nls.localize('RestartTaskAction.label', "Restart Running Task"), original: 'Restart Running Task' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.showTasks',
title: { value: nls.localize('ShowTasksAction.label', "Show Running Tasks"), original: 'Show Running Tasks' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.terminate',
title: { value: nls.localize('TerminateAction.label', "Terminate Task"), original: 'Terminate Task' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.build',
title: { value: nls.localize('BuildAction.label', "Run Build Task"), original: 'Run Build Task' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.test',
title: { value: nls.localize('TestAction.label', "Run Test Task"), original: 'Run Test Task' },
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.configureDefaultBuildTask',
title: {
value: nls.localize('ConfigureDefaultBuildTask.label', "Configure Default Build Task"),
original: 'Configure Default Build Task'
},
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.configureDefaultTestTask',
title: {
value: nls.localize('ConfigureDefaultTestTask.label', "Configure Default Test Task"),
original: 'Configure Default Test Task'
},
category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: 'workbench.action.tasks.openUserTasks',
title: {
value: nls.localize('workbench.action.tasks.openUserTasks', "Open User Tasks"),
original: 'Open User Tasks'
}, category: TASKS_CATEGORY
},
when: SHOW_TASKS_COMMANDS_CONTEXT
});
// MenuRegistry.addCommand( { id: 'workbench.action.tasks.rebuild', title: nls.localize('RebuildAction.label', 'Run Rebuild Task'), category: tasksCategory });
// MenuRegistry.addCommand( { id: 'workbench.action.tasks.clean', title: nls.localize('CleanAction.label', 'Run Clean Task'), category: tasksCategory });
KeybindingsRegistry.registerKeybindingRule({
id: 'workbench.action.tasks.build',
weight: KeybindingWeight.WorkbenchContrib,
when: TaskCommandsRegistered,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyB
});
// Tasks Output channel. Register it before using it in Task Service.
const outputChannelRegistry = Registry.as<IOutputChannelRegistry>(OutputExt.OutputChannels);
outputChannelRegistry.registerChannel({ id: AbstractTaskService.OutputChannelId, label: AbstractTaskService.OutputChannelLabel, log: false });
// Register Quick Access
const quickAccessRegistry = (Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess));
const tasksPickerContextKey = 'inTasksPicker';
quickAccessRegistry.registerQuickAccessProvider({
ctor: TasksQuickAccessProvider,
prefix: TasksQuickAccessProvider.PREFIX,
contextKey: tasksPickerContextKey,
placeholder: nls.localize('tasksQuickAccessPlaceholder', "Type the name of a task to run."),
helpEntries: [{ description: nls.localize('tasksQuickAccessHelp', "Run Task") }]
});
// tasks.json validation
const schema: IJSONSchema = {
id: tasksSchemaId,
description: 'Task definition file',
type: 'object',
allowTrailingCommas: true,
allowComments: true,
default: {
version: '2.0.0',
tasks: [
{
label: 'My Task',
command: 'echo hello',
type: 'shell',
args: [],
problemMatcher: ['$tsc'],
presentation: {
reveal: 'always'
},
group: 'build'
}
]
}
};
schema.definitions = {
...schemaVersion1.definitions,
...schemaVersion2.definitions,
};
schema.oneOf = [...(schemaVersion2.oneOf || []), ...(schemaVersion1.oneOf || [])];
const jsonRegistry = <jsonContributionRegistry.IJSONContributionRegistry>Registry.as(jsonContributionRegistry.Extensions.JSONContribution);
jsonRegistry.registerSchema(tasksSchemaId, schema);
ProblemMatcherRegistry.onMatcherChanged(() => {
updateProblemMatchers();
jsonRegistry.notifySchemaChanged(tasksSchemaId);
});
TaskDefinitionRegistry.onDefinitionsChanged(() => {
updateTaskDefinitions();
jsonRegistry.notifySchemaChanged(tasksSchemaId);
});
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
id: 'task',
order: 100,
title: nls.localize('tasksConfigurationTitle', "Tasks"),
type: 'object',
properties: {
[TaskSettingId.ProblemMatchersNeverPrompt]: {
markdownDescription: nls.localize('task.problemMatchers.neverPrompt', "Configures whether to show the problem matcher prompt when running a task. Set to `true` to never prompt, or use a dictionary of task types to turn off prompting only for specific task types."),
'oneOf': [
{
type: 'boolean',
markdownDescription: nls.localize('task.problemMatchers.neverPrompt.boolean', 'Sets problem matcher prompting behavior for all tasks.')
},
{
type: 'object',
patternProperties: {
'.*': {
type: 'boolean'
}
},
markdownDescription: nls.localize('task.problemMatchers.neverPrompt.array', 'An object containing task type-boolean pairs to never prompt for problem matchers on.'),
default: {
'shell': true
}
}
],
default: false
},
[TaskSettingId.AutoDetect]: {
markdownDescription: nls.localize('task.autoDetect', "Controls enablement of `provideTasks` for all task provider extension. If the Tasks: Run Task command is slow, disabling auto detect for task providers may help. Individual extensions may also provide settings that disable auto detection."),
type: 'string',
enum: ['on', 'off'],
default: 'on'
},
[TaskSettingId.SlowProviderWarning]: {
markdownDescription: nls.localize('task.slowProviderWarning', "Configures whether a warning is shown when a provider is slow"),
'oneOf': [
{
type: 'boolean',
markdownDescription: nls.localize('task.slowProviderWarning.boolean', 'Sets the slow provider warning for all tasks.')
},
{
type: 'array',
items: {
type: 'string',
markdownDescription: nls.localize('task.slowProviderWarning.array', 'An array of task types to never show the slow provider warning.')
}
}
],
default: true
},
[TaskSettingId.QuickOpenHistory]: {
markdownDescription: nls.localize('task.quickOpen.history', "Controls the number of recent items tracked in task quick open dialog."),
type: 'number',
default: 30, minimum: 0, maximum: 30
},
[TaskSettingId.QuickOpenDetail]: {
markdownDescription: nls.localize('task.quickOpen.detail', "Controls whether to show the task detail for tasks that have a detail in task quick picks, such as Run Task."),
type: 'boolean',
default: true
},
[TaskSettingId.QuickOpenSkip]: {
type: 'boolean',
description: nls.localize('task.quickOpen.skip', "Controls whether the task quick pick is skipped when there is only one task to pick from."),
default: false
},
[TaskSettingId.QuickOpenShowAll]: {
type: 'boolean',
description: nls.localize('task.quickOpen.showAll', "Causes the Tasks: Run Task command to use the slower \"show all\" behavior instead of the faster two level picker where tasks are grouped by provider."),
default: false
},
[TaskSettingId.AllowAutomaticTasks]: {
type: 'string',
enum: ['on', 'auto', 'off'],
enumDescriptions: [
nls.localize('ttask.allowAutomaticTasks.on', "Always"),
nls.localize('task.allowAutomaticTasks.auto', "Prompt for permission for each folder"),
nls.localize('task.allowAutomaticTasks.off', "Never"),
],
description: nls.localize('task.allowAutomaticTasks', "Enable automatic tasks in the folder."),
default: 'auto',
restricted: true
},
[TaskSettingId.ShowDecorations]: {
type: 'boolean',
description: nls.localize('task.showDecorations', "Shows decorations at points of interest in the terminal buffer such as the first problem found via a watch task. Note that this will only take effect for future tasks."),
default: true
},
[TaskSettingId.SaveBeforeRun]: {
markdownDescription: nls.localize(
'task.saveBeforeRun',
'Save all dirty editors before running a task.'
),
type: 'string',
enum: ['always', 'never', 'prompt'],
enumDescriptions: [
nls.localize('task.saveBeforeRun.always', 'Always saves all editors before running.'),
nls.localize('task.saveBeforeRun.never', 'Never saves editors before running.'),
nls.localize('task.SaveBeforeRun.prompt', 'Prompts whether to save editors before running.'),
],
default: 'always',
},
}
});
|