task.contribution.ts 60.7 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import 'vs/css!./media/task.contribution';
import 'vs/workbench/parts/tasks/browser/taskQuickOpen';

import * as nls from 'vs/nls';

import { TPromise, Promise } from 'vs/base/common/winjs.base';
import Severity from 'vs/base/common/severity';
import * as Objects from 'vs/base/common/objects';
import { IStringDictionary } from 'vs/base/common/collections';
import { Action } from 'vs/base/common/actions';
import * as Dom from 'vs/base/browser/dom';
J
Joao Moreno 已提交
19
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
20
import { EventEmitter } from 'vs/base/common/eventEmitter';
E
Erich Gamma 已提交
21 22 23 24
import * as Builder from 'vs/base/browser/builder';
import * as Types from 'vs/base/common/types';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { match } from 'vs/base/common/glob';
A
tslint  
Alex Dima 已提交
25
import { setTimeout } from 'vs/base/common/platform';
D
Dirk Baeumer 已提交
26
import { TerminateResponse, TerminateResponseCode } from 'vs/base/common/processes';
27
import * as strings from 'vs/base/common/strings';
E
Erich Gamma 已提交
28 29 30 31 32

import { Registry } from 'vs/platform/platform';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
33
import { IEditor } from 'vs/platform/editor/common/editor';
E
Erich Gamma 已提交
34 35 36
import { IMessageService } from 'vs/platform/message/common/message';
import { IMarkerService, MarkerStatistics } from 'vs/platform/markers/common/markers';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
37
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
38
import { IFileService, FileChangeType } from 'vs/platform/files/common/files';
A
Alex Dima 已提交
39
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
E
Erich Gamma 已提交
40 41 42 43

import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService';

M
Martin Aeschlimann 已提交
44
import jsonContributionRegistry = require('vs/platform/jsonschemas/common/jsonContributionRegistry');
E
Erich Gamma 已提交
45 46
import { IJSONSchema } from 'vs/base/common/jsonSchema';

47
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actionRegistry';
J
Johannes Rieken 已提交
48
import { IStatusbarItem, IStatusbarRegistry, Extensions as StatusbarExtensions, StatusbarItemDescriptor, StatusbarAlignment } from 'vs/workbench/browser/parts/statusbar/statusbar';
49
import { IQuickOpenRegistry, Extensions as QuickOpenExtensions, QuickOpenHandlerDescriptor } from 'vs/workbench/browser/quickopen';
E
Erich Gamma 已提交
50

J
Johannes Rieken 已提交
51
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
52
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
53 54
import Constants from 'vs/workbench/parts/markers/common/constants';
import { IPartService } from 'vs/workbench/services/part/common/partService';
E
Erich Gamma 已提交
55
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
56
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
57
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
E
Erich Gamma 已提交
58

59
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
60
import { IOutputService, IOutputChannelRegistry, Extensions as OutputExt, IOutputChannel } from 'vs/workbench/parts/output/common/output';
E
Erich Gamma 已提交
61

62 63
import { ITerminalService } from 'vs/workbench/parts/terminal/common/terminal';

64
import { ITaskSystem, ITaskSummary, ITaskExecuteResult, TaskExecuteKind, TaskError, TaskErrors, TaskConfiguration, TaskDescription, TaskSystemEvents } from 'vs/workbench/parts/tasks/common/taskSystem';
E
Erich Gamma 已提交
65
import { ITaskService, TaskServiceEvents } from 'vs/workbench/parts/tasks/common/taskService';
D
Dirk Baeumer 已提交
66
import { templates as taskTemplates } from 'vs/workbench/parts/tasks/common/taskTemplates';
E
Erich Gamma 已提交
67

J
Johannes Rieken 已提交
68
import * as FileConfig from 'vs/workbench/parts/tasks/node/processRunnerConfiguration';
69
import { ProcessRunnerSystem } from 'vs/workbench/parts/tasks/node/processRunnerSystem';
70
import { TerminalTaskSystem } from './terminalTaskSystem';
J
Johannes Rieken 已提交
71
import { ProcessRunnerDetector } from 'vs/workbench/parts/tasks/node/processRunnerDetector';
72

J
Johannes Rieken 已提交
73
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
E
Erich Gamma 已提交
74 75 76 77 78 79 80

let $ = Builder.$;

class AbstractTaskAction extends Action {

	protected taskService: ITaskService;
	protected telemetryService: ITelemetryService;
D
Dirk Baeumer 已提交
81 82
	protected messageService: IMessageService;
	protected contextService: IWorkspaceContextService;
E
Erich Gamma 已提交
83

J
Johannes Rieken 已提交
84
	constructor(id: string, label: string, @ITaskService taskService: ITaskService,
85
		@ITelemetryService telemetryService: ITelemetryService,
J
Johannes Rieken 已提交
86
		@IMessageService messageService: IMessageService,
87
		@IWorkspaceContextService contextService: IWorkspaceContextService) {
E
Erich Gamma 已提交
88 89 90 91

		super(id, label);
		this.taskService = taskService;
		this.telemetryService = telemetryService;
92 93 94 95 96
		this.messageService = messageService;
		this.contextService = contextService;
	}

	protected canRun(): boolean {
B
Benjamin Pasero 已提交
97
		if (!this.contextService.hasWorkspace()) {
98 99 100 101
			this.messageService.show(Severity.Info, nls.localize('AbstractTaskAction.noWorkspace', 'Tasks are only available on a workspace folder.'));
			return false;
		}
		return true;
E
Erich Gamma 已提交
102 103 104 105 106
	}
}

class BuildAction extends AbstractTaskAction {
	public static ID = 'workbench.action.tasks.build';
107
	public static TEXT = nls.localize('BuildAction.label', "Run Build Task");
E
Erich Gamma 已提交
108

J
Johannes Rieken 已提交
109 110
	constructor(id: string, label: string, @ITaskService taskService: ITaskService, @ITelemetryService telemetryService: ITelemetryService,
		@IMessageService messageService: IMessageService, @IWorkspaceContextService contextService: IWorkspaceContextService) {
111
		super(id, label, taskService, telemetryService, messageService, contextService);
E
Erich Gamma 已提交
112 113
	}

114 115 116 117
	public run(): TPromise<ITaskSummary> {
		if (!this.canRun()) {
			return TPromise.as(undefined);
		}
E
Erich Gamma 已提交
118 119 120 121 122 123
		return this.taskService.build();
	}
}

class TestAction extends AbstractTaskAction {
	public static ID = 'workbench.action.tasks.test';
124
	public static TEXT = nls.localize('TestAction.label', "Run Test Task");
E
Erich Gamma 已提交
125

J
Johannes Rieken 已提交
126 127
	constructor(id: string, label: string, @ITaskService taskService: ITaskService, @ITelemetryService telemetryService: ITelemetryService,
		@IMessageService messageService: IMessageService, @IWorkspaceContextService contextService: IWorkspaceContextService) {
128
		super(id, label, taskService, telemetryService, messageService, contextService);
E
Erich Gamma 已提交
129 130
	}

131 132 133 134
	public run(): TPromise<ITaskSummary> {
		if (!this.canRun()) {
			return TPromise.as(undefined);
		}
E
Erich Gamma 已提交
135 136 137 138 139 140 141 142
		return this.taskService.runTest();
	}
}

class RebuildAction extends AbstractTaskAction {
	public static ID = 'workbench.action.tasks.rebuild';
	public static TEXT = nls.localize('RebuildAction.label', 'Run Rebuild Task');

J
Johannes Rieken 已提交
143 144
	constructor(id: string, label: string, @ITaskService taskService: ITaskService, @ITelemetryService telemetryService: ITelemetryService,
		@IMessageService messageService: IMessageService, @IWorkspaceContextService contextService: IWorkspaceContextService) {
145
		super(id, label, taskService, telemetryService, messageService, contextService);
E
Erich Gamma 已提交
146 147
	}

148 149 150 151
	public run(): TPromise<ITaskSummary> {
		if (!this.canRun()) {
			return TPromise.as(undefined);
		}
E
Erich Gamma 已提交
152 153 154 155 156 157 158 159
		return this.taskService.rebuild();
	}
}

class CleanAction extends AbstractTaskAction {
	public static ID = 'workbench.action.tasks.clean';
	public static TEXT = nls.localize('CleanAction.label', 'Run Clean Task');

J
Johannes Rieken 已提交
160 161
	constructor(id: string, label: string, @ITaskService taskService: ITaskService, @ITelemetryService telemetryService: ITelemetryService,
		@IMessageService messageService: IMessageService, @IWorkspaceContextService contextService: IWorkspaceContextService) {
162
		super(id, label, taskService, telemetryService, messageService, contextService);
E
Erich Gamma 已提交
163 164
	}

165 166 167 168
	public run(): TPromise<ITaskSummary> {
		if (!this.canRun()) {
			return TPromise.as(undefined);
		}
E
Erich Gamma 已提交
169 170 171 172
		return this.taskService.clean();
	}
}

173
abstract class OpenTaskConfigurationAction extends Action {
E
Erich Gamma 已提交
174 175 176 177 178 179 180 181

	private configurationService: IConfigurationService;
	private fileService: IFileService;

	private editorService: IWorkbenchEditorService;
	private contextService: IWorkspaceContextService;
	private outputService: IOutputService;
	private messageService: IMessageService;
D
Dirk Baeumer 已提交
182
	private quickOpenService: IQuickOpenService;
E
Erich Gamma 已提交
183 184 185 186

	constructor(id: string, label: string, @IConfigurationService configurationService: IConfigurationService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService,
		@IWorkspaceContextService contextService: IWorkspaceContextService, @IOutputService outputService: IOutputService,
187
		@IMessageService messageService: IMessageService, @IQuickOpenService quickOpenService: IQuickOpenService,
188 189
		@IEnvironmentService private environmentService: IEnvironmentService,
		@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService) {
E
Erich Gamma 已提交
190 191 192 193 194 195 196 197

		super(id, label);
		this.configurationService = configurationService;
		this.editorService = editorService;
		this.fileService = fileService;
		this.contextService = contextService;
		this.outputService = outputService;
		this.messageService = messageService;
D
Dirk Baeumer 已提交
198
		this.quickOpenService = quickOpenService;
E
Erich Gamma 已提交
199 200
	}

J
Johannes Rieken 已提交
201
	public run(event?: any): TPromise<IEditor> {
B
Benjamin Pasero 已提交
202
		if (!this.contextService.hasWorkspace()) {
203 204 205
			this.messageService.show(Severity.Info, nls.localize('ConfigureTaskRunnerAction.noWorkspace', 'Tasks are only available on a workspace folder.'));
			return TPromise.as(undefined);
		}
E
Erich Gamma 已提交
206
		let sideBySide = !!(event && (event.ctrlKey || event.metaKey));
207
		let configFileCreated = false;
E
Erich Gamma 已提交
208 209
		return this.fileService.resolveFile(this.contextService.toResource('.vscode/tasks.json')).then((success) => {
			return success;
J
Johannes Rieken 已提交
210
		}, (err: any) => {
211
			;
J
Johannes Rieken 已提交
212
			return this.quickOpenService.pick(taskTemplates, { placeHolder: nls.localize('ConfigureTaskRunnerAction.quickPick.template', 'Select a Task Runner') }).then(selection => {
D
Dirk Baeumer 已提交
213 214
				if (!selection) {
					return undefined;
E
Erich Gamma 已提交
215 216
				}
				let contentPromise: TPromise<string>;
D
Dirk Baeumer 已提交
217
				if (selection.autoDetect) {
I
isidor 已提交
218
					const outputChannel = this.outputService.getChannel(TaskService.OutputChannelId);
219
					outputChannel.show(true);
I
isidor 已提交
220
					outputChannel.append(nls.localize('ConfigureTaskRunnerAction.autoDetecting', 'Auto detecting tasks for {0}', selection.id) + '\n');
221
					let detector = new ProcessRunnerDetector(this.fileService, this.contextService, this.configurationResolverService);
222
					contentPromise = detector.detect(false, selection.id).then((value) => {
D
Dirk Baeumer 已提交
223 224 225
						let config = value.config;
						if (value.stderr && value.stderr.length > 0) {
							value.stderr.forEach((line) => {
I
isidor 已提交
226
								outputChannel.append(line + '\n');
D
Dirk Baeumer 已提交
227
							});
228
							this.messageService.show(Severity.Warning, nls.localize('ConfigureTaskRunnerAction.autoDetect', 'Auto detecting the task system failed. Using default template. Consult the task output for details.'));
D
Dirk Baeumer 已提交
229 230
							return selection.content;
						} else if (config) {
231
							if (value.stdout && value.stdout.length > 0) {
I
isidor 已提交
232
								value.stdout.forEach(line => outputChannel.append(line + '\n'));
233
							}
D
Dirk Baeumer 已提交
234 235 236
							let content = JSON.stringify(config, null, '\t');
							content = [
								'{',
J
Johannes Rieken 已提交
237 238
								'\t// See https://go.microsoft.com/fwlink/?LinkId=733558',
								'\t// for the documentation about the tasks.json format',
D
Dirk Baeumer 已提交
239 240 241 242 243
							].join('\n') + content.substr(1);
							return content;
						} else {
							return selection.content;
						}
E
Erich Gamma 已提交
244
					});
D
Dirk Baeumer 已提交
245 246
				} else {
					contentPromise = TPromise.as(selection.content);
E
Erich Gamma 已提交
247
				}
D
Dirk Baeumer 已提交
248
				return contentPromise.then(content => {
249
					let editorConfig = this.configurationService.getConfiguration<any>();
250 251
					if (editorConfig.editor.insertSpaces) {
						content = content.replace(/(\n)(\t+)/g, (_, s1, s2) => s1 + strings.repeat(' ', s2.length * editorConfig.editor.tabSize));
252
					}
253
					configFileCreated = true;
D
Dirk Baeumer 已提交
254
					return this.fileService.createFile(this.contextService.toResource('.vscode/tasks.json'), content);
E
Erich Gamma 已提交
255 256 257
				});
			});
		}).then((stat) => {
D
Dirk Baeumer 已提交
258 259 260 261
			if (!stat) {
				return undefined;
			}
			// // (2) Open editor with configuration file
E
Erich Gamma 已提交
262 263 264
			return this.editorService.openEditor({
				resource: stat.resource,
				options: {
265 266
					forceOpen: true,
					pinned: configFileCreated // pin only if config file is created #8727
E
Erich Gamma 已提交
267
				}
D
Dirk Baeumer 已提交
268
			}, sideBySide);
E
Erich Gamma 已提交
269 270 271 272 273 274
		}, (error) => {
			throw new Error(nls.localize('ConfigureTaskRunnerAction.failed', "Unable to create the 'tasks.json' file inside the '.vscode' folder. Consult the task output for details."));
		});
	}
}

275 276 277 278 279 280 281 282
class ConfigureTaskRunnerAction extends OpenTaskConfigurationAction {
	public static ID = 'workbench.action.tasks.configureTaskRunner';
	public static TEXT = nls.localize('ConfigureTaskRunnerAction.label', "Configure Task Runner");

	constructor(id: string, label: string, @IConfigurationService configurationService: IConfigurationService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService,
		@IWorkspaceContextService contextService: IWorkspaceContextService, @IOutputService outputService: IOutputService,
		@IMessageService messageService: IMessageService, @IQuickOpenService quickOpenService: IQuickOpenService,
283 284
		@IEnvironmentService environmentService: IEnvironmentService,
		@IConfigurationResolverService configurationResolverService: IConfigurationResolverService) {
J
Johannes Rieken 已提交
285
		super(id, label, configurationService, editorService, fileService, contextService,
286
			outputService, messageService, quickOpenService, environmentService, configurationResolverService);
J
Johannes Rieken 已提交
287
	}
288 289 290 291 292 293 294 295 296 297 298

}

class ConfigureBuildTaskAction extends OpenTaskConfigurationAction {
	public static ID = 'workbench.action.tasks.configureBuildTask';
	public static TEXT = nls.localize('ConfigureBuildTaskAction.label', "Configure Build Task");

	constructor(id: string, label: string, @IConfigurationService configurationService: IConfigurationService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService,
		@IWorkspaceContextService contextService: IWorkspaceContextService, @IOutputService outputService: IOutputService,
		@IMessageService messageService: IMessageService, @IQuickOpenService quickOpenService: IQuickOpenService,
299 300
		@IEnvironmentService environmentService: IEnvironmentService,
		@IConfigurationResolverService configurationResolverService: IConfigurationResolverService) {
J
Johannes Rieken 已提交
301
		super(id, label, configurationService, editorService, fileService, contextService,
302
			outputService, messageService, quickOpenService, environmentService, configurationResolverService);
J
Johannes Rieken 已提交
303
	}
304 305
}

E
Erich Gamma 已提交
306 307 308 309 310 311 312 313 314 315
class CloseMessageAction extends Action {

	public static ID = 'workbench.action.build.closeMessage';
	public static TEXT = nls.localize('CloseMessageAction.label', 'Close');

	public closeFunction: () => void;

	constructor() {
		super(CloseMessageAction.ID, CloseMessageAction.TEXT);
	}
316
	public run(): TPromise<void> {
E
Erich Gamma 已提交
317 318 319
		if (this.closeFunction) {
			this.closeFunction();
		}
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
		return TPromise.as(undefined);
	}
}

class ViewTerminalAction extends Action {

	public static ID = 'workbench.action.build.viewTerminal';
	public static TEXT = nls.localize('ShowTerminalAction.label', 'View Terminal');

	constructor( @ITerminalService private terminalService: ITerminalService) {
		super(ViewTerminalAction.ID, ViewTerminalAction.TEXT);
	}

	public run(): TPromise<void> {
		this.terminalService.showPanel();
		return TPromise.as(undefined);
E
Erich Gamma 已提交
336 337 338 339 340
	}
}

class TerminateAction extends AbstractTaskAction {
	public static ID = 'workbench.action.tasks.terminate';
341
	public static TEXT = nls.localize('TerminateAction.label', "Terminate Running Task");
E
Erich Gamma 已提交
342

J
Johannes Rieken 已提交
343
	constructor(id: string, label: string, @ITaskService taskService: ITaskService, @ITelemetryService telemetryService: ITelemetryService,
344 345 346
		@IMessageService messageService: IMessageService, @IWorkspaceContextService contextService: IWorkspaceContextService,
		@ITerminalService private terminalService: ITerminalService
	) {
347
		super(id, label, taskService, telemetryService, messageService, contextService);
E
Erich Gamma 已提交
348 349
	}

350 351 352 353
	public run(): TPromise<TerminateResponse> {
		if (!this.canRun()) {
			return TPromise.as(undefined);
		}
354
		if (this.taskService.inTerminal()) {
355
			this.messageService.show(Severity.Info, {
R
roblou 已提交
356
				message: nls.localize('TerminateAction.terminalSystem', 'The tasks are executed in the integrated terminal. Use the terminal to manage the tasks.'),
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
				actions: [new ViewTerminalAction(this.terminalService), new CloseMessageAction()]
			});
		} else {
			return this.taskService.isActive().then((active) => {
				if (active) {
					return this.taskService.terminate().then((response) => {
						if (response.success) {
							return;
						} else if (response.code && response.code === TerminateResponseCode.ProcessNotFound) {
							this.messageService.show(Severity.Error, nls.localize('TerminateAction.noProcess', 'The launched process doesn\'t exist anymore. If the task spawned background tasks exiting VS Code might result in orphaned processes.'));
						} else {
							return Promise.wrapError(nls.localize('TerminateAction.failed', 'Failed to terminate running task'));
						}
					});
				}
			});
		}
E
Erich Gamma 已提交
374 375 376 377 378
	}
}

class ShowLogAction extends AbstractTaskAction {
	public static ID = 'workbench.action.tasks.showLog';
379
	public static TEXT = nls.localize('ShowLogAction.label', "Show Task Log");
E
Erich Gamma 已提交
380 381 382

	private outputService: IOutputService;

J
Johannes Rieken 已提交
383 384 385
	constructor(id: string, label: string, @ITaskService taskService: ITaskService, @ITelemetryService telemetryService: ITelemetryService,
		@IMessageService messageService: IMessageService, @IWorkspaceContextService contextService: IWorkspaceContextService,
		@IOutputService outputService: IOutputService) {
E
Erich Gamma 已提交
386

387
		super(id, label, taskService, telemetryService, messageService, contextService);
E
Erich Gamma 已提交
388 389 390
		this.outputService = outputService;
	}

391 392 393 394
	public run(): TPromise<IEditor> {
		if (!this.canRun()) {
			return TPromise.as(undefined);
		}
395
		return this.outputService.getChannel(TaskService.OutputChannelId).show(true);
E
Erich Gamma 已提交
396 397 398
	}
}

399
class RunTaskAction extends AbstractTaskAction {
E
Erich Gamma 已提交
400 401 402 403 404

	public static ID = 'workbench.action.tasks.runTask';
	public static TEXT = nls.localize('RunTaskAction.label', "Run Task");
	private quickOpenService: IQuickOpenService;

J
Johannes Rieken 已提交
405
	constructor(id: string, label: string, @IQuickOpenService quickOpenService: IQuickOpenService,
406
		@ITaskService taskService: ITaskService, @ITelemetryService telemetryService: ITelemetryService,
J
Johannes Rieken 已提交
407
		@IMessageService messageService: IMessageService, @IWorkspaceContextService contextService: IWorkspaceContextService) {
408
		super(id, label, taskService, telemetryService, messageService, contextService);
E
Erich Gamma 已提交
409 410 411
		this.quickOpenService = quickOpenService;
	}

J
Johannes Rieken 已提交
412
	public run(event?: any): Promise {
413 414 415
		if (!this.canRun()) {
			return TPromise.as(undefined);
		}
E
Erich Gamma 已提交
416
		this.quickOpenService.show('task ');
A
Alex Dima 已提交
417
		return TPromise.as(null);
E
Erich Gamma 已提交
418 419 420 421
	}
}


422
class StatusBarItem implements IStatusbarItem {
E
Erich Gamma 已提交
423

424
	private panelService: IPanelService;
E
Erich Gamma 已提交
425
	private markerService: IMarkerService;
J
Johannes Rieken 已提交
426
	private taskService: ITaskService;
E
Erich Gamma 已提交
427 428 429 430
	private outputService: IOutputService;

	private intervalToken: any;
	private activeCount: number;
J
Johannes Rieken 已提交
431
	private static progressChars: string = '|/-\\';
E
Erich Gamma 已提交
432

J
Johannes Rieken 已提交
433 434 435
	constructor( @IPanelService panelService: IPanelService,
		@IMarkerService markerService: IMarkerService, @IOutputService outputService: IOutputService,
		@ITaskService taskService: ITaskService,
436
		@IPartService private partService: IPartService) {
E
Erich Gamma 已提交
437

438
		this.panelService = panelService;
E
Erich Gamma 已提交
439 440 441 442 443 444 445 446
		this.markerService = markerService;
		this.outputService = outputService;
		this.taskService = taskService;
		this.activeCount = 0;
	}

	public render(container: HTMLElement): IDisposable {

447
		let callOnDispose: IDisposable[] = [],
E
Erich Gamma 已提交
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
			element = document.createElement('div'),
			// icon = document.createElement('a'),
			progress = document.createElement('div'),
			label = document.createElement('a'),
			error = document.createElement('div'),
			warning = document.createElement('div'),
			info = document.createElement('div');

		Dom.addClass(element, 'task-statusbar-item');

		// dom.addClass(icon, 'task-statusbar-item-icon');
		// element.appendChild(icon);

		Dom.addClass(progress, 'task-statusbar-item-progress');
		element.appendChild(progress);
		progress.innerHTML = StatusBarItem.progressChars[0];
		$(progress).hide();

		Dom.addClass(label, 'task-statusbar-item-label');
		element.appendChild(label);
S
Sandeep Somavarapu 已提交
468
		element.title = nls.localize('problems', "Problems");
E
Erich Gamma 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481

		Dom.addClass(error, 'task-statusbar-item-label-error');
		error.innerHTML = '0';
		label.appendChild(error);

		Dom.addClass(warning, 'task-statusbar-item-label-warning');
		warning.innerHTML = '0';
		label.appendChild(warning);

		Dom.addClass(info, 'task-statusbar-item-label-info');
		label.appendChild(info);
		$(info).hide();

J
Johannes Rieken 已提交
482 483 484
		//		callOnDispose.push(dom.addListener(icon, 'click', (e:MouseEvent) => {
		//			this.outputService.showOutput(TaskService.OutputChannel, e.ctrlKey || e.metaKey, true);
		//		}));
E
Erich Gamma 已提交
485

J
Johannes Rieken 已提交
486 487
		callOnDispose.push(Dom.addDisposableListener(label, 'click', (e: MouseEvent) => {
			const panel = this.panelService.getActivePanel();
488 489 490 491 492
			if (panel && panel.getId() === Constants.MARKERS_PANEL_ID) {
				this.partService.setPanelHidden(true);
			} else {
				this.panelService.openPanel(Constants.MARKERS_PANEL_ID, true);
			}
J
Johannes Rieken 已提交
493
		}));
E
Erich Gamma 已提交
494

J
Johannes Rieken 已提交
495
		let updateStatus = (element: HTMLDivElement, stats: number): boolean => {
E
Erich Gamma 已提交
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
			if (stats > 0) {
				element.innerHTML = stats.toString();
				$(element).show();
				return true;
			} else {
				$(element).hide();
				return false;
			}
		};


		let manyMarkers = nls.localize('manyMarkers', "99+");
		let updateLabel = (stats: MarkerStatistics) => {
			error.innerHTML = stats.errors < 100 ? stats.errors.toString() : manyMarkers;
			warning.innerHTML = stats.warnings < 100 ? stats.warnings.toString() : manyMarkers;
			updateStatus(info, stats.infos);
		};

		this.markerService.onMarkerChanged((changedResources) => {
			updateLabel(this.markerService.getStatistics());
		});

518
		callOnDispose.push(this.taskService.addListener2(TaskServiceEvents.Active, () => {
E
Erich Gamma 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
			this.activeCount++;
			if (this.activeCount === 1) {
				let index = 1;
				let chars = StatusBarItem.progressChars;
				progress.innerHTML = chars[0];
				this.intervalToken = setInterval(() => {
					progress.innerHTML = chars[index];
					index++;
					if (index >= chars.length) {
						index = 0;
					}
				}, 50);
				$(progress).show();
			}
		}));

J
Johannes Rieken 已提交
535
		callOnDispose.push(this.taskService.addListener2(TaskServiceEvents.Inactive, (data: TaskServiceEventData) => {
536 537 538 539 540 541 542 543 544 545 546
			// 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.activeCount > 0) {
				this.activeCount--;
				if (this.activeCount === 0) {
					$(progress).hide();
					if (this.intervalToken) {
						clearInterval(this.intervalToken);
						this.intervalToken = null;
					}
				}
E
Erich Gamma 已提交
547 548 549
			}
		}));

550
		callOnDispose.push(this.taskService.addListener2(TaskServiceEvents.Terminated, () => {
E
Erich Gamma 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563
			if (this.activeCount !== 0) {
				$(progress).hide();
				if (this.intervalToken) {
					clearInterval(this.intervalToken);
					this.intervalToken = null;
				}
				this.activeCount = 0;
			}
		}));

		container.appendChild(element);

		return {
564
			dispose: () => {
J
Joao Moreno 已提交
565
				callOnDispose = dispose(callOnDispose);
566
			}
E
Erich Gamma 已提交
567 568 569 570 571 572 573 574
		};
	}
}

interface TaskServiceEventData {
	error?: any;
}

575
class NullTaskSystem extends EventEmitter implements ITaskSystem {
576
	public build(): ITaskExecuteResult {
577
		return {
578
			kind: TaskExecuteKind.Started,
579 580 581
			promise: TPromise.as<ITaskSummary>({})
		};
	}
582
	public rebuild(): ITaskExecuteResult {
583
		return {
584
			kind: TaskExecuteKind.Started,
585 586 587
			promise: TPromise.as<ITaskSummary>({})
		};
	}
588
	public clean(): ITaskExecuteResult {
589
		return {
590
			kind: TaskExecuteKind.Started,
591 592 593
			promise: TPromise.as<ITaskSummary>({})
		};
	}
594
	public runTest(): ITaskExecuteResult {
595
		return {
596
			kind: TaskExecuteKind.Started,
597 598 599
			promise: TPromise.as<ITaskSummary>({})
		};
	}
600
	public run(taskIdentifier: string): ITaskExecuteResult {
601
		return {
602
			kind: TaskExecuteKind.Started,
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
			promise: TPromise.as<ITaskSummary>({})
		};
	}
	public isActive(): TPromise<boolean> {
		return TPromise.as(false);
	}
	public isActiveSync(): boolean {
		return false;
	}
	public canAutoTerminate(): boolean {
		return true;
	}
	public terminate(): TPromise<TerminateResponse> {
		return TPromise.as<TerminateResponse>({ success: true });
	}
	public tasks(): TPromise<TaskDescription[]> {
		return TPromise.as<TaskDescription[]>([]);
	}
}

E
Erich Gamma 已提交
623
class TaskService extends EventEmitter implements ITaskService {
624
	public _serviceBrand: any;
E
Erich Gamma 已提交
625
	public static SERVICE_ID: string = 'taskService';
J
Johannes Rieken 已提交
626 627
	public static OutputChannelId: string = 'tasks';
	public static OutputChannelLabel: string = nls.localize('tasks', "Tasks");
E
Erich Gamma 已提交
628 629 630 631 632 633 634 635 636 637 638 639

	private modeService: IModeService;
	private configurationService: IConfigurationService;
	private markerService: IMarkerService;
	private outputService: IOutputService;
	private messageService: IMessageService;
	private fileService: IFileService;
	private telemetryService: ITelemetryService;
	private editorService: IWorkbenchEditorService;
	private contextService: IWorkspaceContextService;
	private textFileService: ITextFileService;
	private modelService: IModelService;
A
Alex Dima 已提交
640
	private extensionService: IExtensionService;
D
Dirk Baeumer 已提交
641
	private quickOpenService: IQuickOpenService;
E
Erich Gamma 已提交
642 643 644

	private _taskSystemPromise: TPromise<ITaskSystem>;
	private _taskSystem: ITaskSystem;
645
	private _inTerminal: boolean;
A
Alex Dima 已提交
646
	private taskSystemListeners: IDisposable[];
D
Dirk Baeumer 已提交
647
	private clearTaskSystemPromise: boolean;
648
	private outputChannel: IOutputChannel;
E
Erich Gamma 已提交
649

A
Alex Dima 已提交
650
	private fileChangesListener: IDisposable;
E
Erich Gamma 已提交
651

J
Johannes Rieken 已提交
652
	constructor( @IModeService modeService: IModeService, @IConfigurationService configurationService: IConfigurationService,
E
Erich Gamma 已提交
653
		@IMarkerService markerService: IMarkerService, @IOutputService outputService: IOutputService,
J
Johannes Rieken 已提交
654 655 656
		@IMessageService messageService: IMessageService, @IWorkbenchEditorService editorService: IWorkbenchEditorService,
		@IFileService fileService: IFileService, @IWorkspaceContextService contextService: IWorkspaceContextService,
		@ITelemetryService telemetryService: ITelemetryService, @ITextFileService textFileService: ITextFileService,
657
		@ILifecycleService lifecycleService: ILifecycleService,
A
Alex Dima 已提交
658
		@IModelService modelService: IModelService, @IExtensionService extensionService: IExtensionService,
659
		@IQuickOpenService quickOpenService: IQuickOpenService,
660
		@IEnvironmentService private environmentService: IEnvironmentService,
661 662 663
		@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService,
		@ITerminalService private terminalService: ITerminalService
	) {
E
Erich Gamma 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676

		super();
		this.modeService = modeService;
		this.configurationService = configurationService;
		this.markerService = markerService;
		this.outputService = outputService;
		this.messageService = messageService;
		this.editorService = editorService;
		this.fileService = fileService;
		this.contextService = contextService;
		this.telemetryService = telemetryService;
		this.textFileService = textFileService;
		this.modelService = modelService;
A
Alex Dima 已提交
677
		this.extensionService = extensionService;
D
Dirk Baeumer 已提交
678
		this.quickOpenService = quickOpenService;
E
Erich Gamma 已提交
679

680
		this._inTerminal = false;
E
Erich Gamma 已提交
681
		this.taskSystemListeners = [];
D
Dirk Baeumer 已提交
682
		this.clearTaskSystemPromise = false;
I
isidor 已提交
683
		this.outputChannel = this.outputService.getChannel(TaskService.OutputChannelId);
J
Johannes Rieken 已提交
684
		this.configurationService.onDidUpdateConfiguration(() => {
E
Erich Gamma 已提交
685
			this.emit(TaskServiceEvents.ConfigChanged);
D
Dirk Baeumer 已提交
686 687 688 689 690 691
			if (this._taskSystem && this._taskSystem.isActiveSync()) {
				this.clearTaskSystemPromise = true;
			} else {
				this._taskSystem = null;
				this._taskSystemPromise = null;
			}
E
Erich Gamma 已提交
692 693 694
			this.disposeTaskSystemListeners();
		});

695
		lifecycleService.onWillShutdown(event => event.veto(this.beforeShutdown()));
E
Erich Gamma 已提交
696 697
	}

698 699 700 701
	public log(value: string): void {
		this.outputChannel.append(value + '\n');
	}

E
Erich Gamma 已提交
702
	private disposeTaskSystemListeners(): void {
A
Alex Dima 已提交
703
		this.taskSystemListeners = dispose(this.taskSystemListeners);
E
Erich Gamma 已提交
704 705
	}

D
Dirk Baeumer 已提交
706
	private disposeFileChangesListener(): void {
E
Erich Gamma 已提交
707
		if (this.fileChangesListener) {
A
Alex Dima 已提交
708
			this.fileChangesListener.dispose();
E
Erich Gamma 已提交
709 710 711 712 713 714
			this.fileChangesListener = null;
		}
	}

	private get taskSystemPromise(): TPromise<ITaskSystem> {
		if (!this._taskSystemPromise) {
B
Benjamin Pasero 已提交
715
			if (!this.contextService.hasWorkspace()) {
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
				this._taskSystem = new NullTaskSystem();
				this._taskSystemPromise = TPromise.as(this._taskSystem);
			} else {
				let clearOutput = true;
				this._taskSystemPromise = TPromise.as(this.configurationService.getConfiguration<TaskConfiguration>('tasks')).then((config: TaskConfiguration) => {
					let parseErrors: string[] = config ? (<any>config).$parseErrors : null;
					if (parseErrors) {
						let isAffected = false;
						for (let i = 0; i < parseErrors.length; i++) {
							if (/tasks\.json$/.test(parseErrors[i])) {
								isAffected = true;
								break;
							}
						}
						if (isAffected) {
							this.outputChannel.append(nls.localize('TaskSystem.invalidTaskJson', 'Error: The content of the tasks.json file has syntax errors. Please correct them before executing a task.\n'));
							this.outputChannel.show(true);
							return TPromise.wrapError({});
E
Erich Gamma 已提交
734 735
						}
					}
736 737 738 739
					let configPromise: TPromise<TaskConfiguration>;
					if (config) {
						if (this.isRunnerConfig(config) && this.hasDetectorSupport(<FileConfig.ExternalTaskRunnerConfiguration>config)) {
							let fileConfig = <FileConfig.ExternalTaskRunnerConfiguration>config;
740
							configPromise = new ProcessRunnerDetector(this.fileService, this.contextService, this.configurationResolverService, fileConfig).detect(true).then((value) => {
741 742 743 744
								clearOutput = this.printStderr(value.stderr);
								let detectedConfig = value.config;
								if (!detectedConfig) {
									return config;
E
Erich Gamma 已提交
745
								}
746 747 748 749 750
								let result: FileConfig.ExternalTaskRunnerConfiguration = Objects.clone(fileConfig);
								let configuredTasks: IStringDictionary<FileConfig.TaskDescription> = Object.create(null);
								if (!result.tasks) {
									if (detectedConfig.tasks) {
										result.tasks = detectedConfig.tasks;
E
Erich Gamma 已提交
751
									}
752 753 754 755 756 757 758 759 760 761 762 763 764
								} else {
									result.tasks.forEach(task => configuredTasks[task.taskName] = task);
									detectedConfig.tasks.forEach((task) => {
										if (!configuredTasks[task.taskName]) {
											result.tasks.push(task);
										}
									});
								}
								return result;
							});
						} else {
							configPromise = TPromise.as<TaskConfiguration>(config);
						}
E
Erich Gamma 已提交
765
					} else {
766
						configPromise = new ProcessRunnerDetector(this.fileService, this.contextService, this.configurationResolverService).detect(true).then((value) => {
767 768 769
							clearOutput = this.printStderr(value.stderr);
							return value.config;
						});
E
Erich Gamma 已提交
770
					}
771 772 773 774 775 776
					return configPromise.then((config) => {
						if (!config) {
							this._taskSystemPromise = null;
							throw new TaskError(Severity.Info, nls.localize('TaskSystem.noConfiguration', 'No task runner configured.'), TaskErrors.NotConfigured);
						}
						let result: ITaskSystem = null;
777
						let parseResult = FileConfig.parse(<FileConfig.ExternalTaskRunnerConfiguration>config, this);
778 779 780
						if (!parseResult.validationStatus.isOK()) {
							this.outputChannel.show(true);
						}
781 782 783
						if (parseResult.validationStatus.isFatal()) {
							throw new TaskError(Severity.Error, nls.localize('TaskSystem.fatalError', 'The provided task configuration has validation errors. See tasks output log for details.'), TaskErrors.ConfigValidationError);
						}
784
						if (this.isRunnerConfig(config)) {
785
							this._inTerminal = false;
786
							result = new ProcessRunnerSystem(parseResult.configuration, this.markerService, this.modelService, this.telemetryService, this.outputService, this.configurationResolverService, TaskService.OutputChannelId, clearOutput);
787
						} else if (this.isTerminalConfig(config)) {
788
							this._inTerminal = true;
789
							result = new TerminalTaskSystem(
790
								parseResult.configuration,
791 792 793 794
								this.terminalService, this.outputService, this.markerService,
								this.modelService, this.configurationResolverService, this.telemetryService,
								TaskService.OutputChannelId
							);
795 796 797 798 799
						}
						if (result === null) {
							this._taskSystemPromise = null;
							throw new TaskError(Severity.Info, nls.localize('TaskSystem.noBuildType', "No valid task runner configured. Supported task runners are 'service' and 'program'."), TaskErrors.NoValidTaskRunner);
						}
A
Alex Dima 已提交
800 801
						this.taskSystemListeners.push(result.addListener2(TaskSystemEvents.Active, (event) => this.emit(TaskServiceEvents.Active, event)));
						this.taskSystemListeners.push(result.addListener2(TaskSystemEvents.Inactive, (event) => this.emit(TaskServiceEvents.Inactive, event)));
802 803 804 805 806
						this._taskSystem = result;
						return result;
					}, (err: any) => {
						this.handleError(err);
						return Promise.wrapError(err);
E
Erich Gamma 已提交
807 808
					});
				});
809
			}
E
Erich Gamma 已提交
810 811 812 813 814 815 816 817 818
		}
		return this._taskSystemPromise;
	}

	private printStderr(stderr: string[]): boolean {
		let result = true;
		if (stderr && stderr.length > 0) {
			stderr.forEach((line) => {
				result = false;
819
				this.outputChannel.append(line + '\n');
E
Erich Gamma 已提交
820
			});
821
			this.outputChannel.show(true);
E
Erich Gamma 已提交
822 823 824 825 826
		}
		return result;
	}

	private isRunnerConfig(config: TaskConfiguration): boolean {
827 828 829 830 831
		return !config._runner || config._runner === 'program';
	}

	private isTerminalConfig(config: TaskConfiguration): boolean {
		return config._runner === 'terminal';
E
Erich Gamma 已提交
832 833
	}

834 835 836 837
	public inTerminal(): boolean {
		return this._inTerminal;
	}

E
Erich Gamma 已提交
838 839 840 841 842 843 844
	private hasDetectorSupport(config: FileConfig.ExternalTaskRunnerConfiguration): boolean {
		if (!config.command) {
			return false;
		}
		return ProcessRunnerDetector.supports(config.command);
	}

845 846 847
	public configureAction(): Action {
		return new ConfigureTaskRunnerAction(ConfigureTaskRunnerAction.ID, ConfigureTaskRunnerAction.TEXT,
			this.configurationService, this.editorService, this.fileService, this.contextService,
848
			this.outputService, this.messageService, this.quickOpenService, this.environmentService, this.configurationResolverService);
849 850
	}

851 852 853
	private configureBuildTask(): Action {
		return new ConfigureBuildTaskAction(ConfigureBuildTaskAction.ID, ConfigureBuildTaskAction.TEXT,
			this.configurationService, this.editorService, this.fileService, this.contextService,
854
			this.outputService, this.messageService, this.quickOpenService, this.environmentService, this.configurationResolverService);
855 856
	}

E
Erich Gamma 已提交
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
	public build(): TPromise<ITaskSummary> {
		return this.executeTarget(taskSystem => taskSystem.build());
	}

	public rebuild(): TPromise<ITaskSummary> {
		return this.executeTarget(taskSystem => taskSystem.rebuild());
	}

	public clean(): TPromise<ITaskSummary> {
		return this.executeTarget(taskSystem => taskSystem.clean());
	}

	public runTest(): TPromise<ITaskSummary> {
		return this.executeTarget(taskSystem => taskSystem.runTest());
	}

873
	public run(taskIdentifier: string): TPromise<ITaskSummary> {
E
Erich Gamma 已提交
874 875 876
		return this.executeTarget(taskSystem => taskSystem.run(taskIdentifier));
	}

877
	private executeTarget(fn: (taskSystem: ITaskSystem) => ITaskExecuteResult): TPromise<ITaskSummary> {
878 879
		return this.textFileService.saveAll().then((value) => { // make sure all dirty files are saved
			return this.configurationService.reloadConfiguration().then(() => { // make sure configuration is up to date
880 881
				return this.taskSystemPromise.
					then((taskSystem) => {
882 883 884
						let executeResult = fn(taskSystem);
						if (executeResult.kind === TaskExecuteKind.Active) {
							let active = executeResult.active;
885
							if (active.same && active.background) {
886
								this.messageService.show(Severity.Info, nls.localize('TaskSystem.activeSame', 'The task is already active and in watch mode. To terminate the task use `F1 > terminate task`'));
887 888
							} else {
								throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is an active running task right now. Terminate it first before executing another task.'), TaskErrors.RunningTask);
E
Erich Gamma 已提交
889
							}
890 891
						}
						return executeResult;
892
					}).
893 894 895 896
					then((executeResult: ITaskExecuteResult) => {
						if (executeResult.kind === TaskExecuteKind.Started) {
							if (executeResult.started.restartOnFileChanges) {
								let pattern = executeResult.started.restartOnFileChanges;
897
								this.fileChangesListener = this.fileService.onFileChanges(event => {
898 899
									let needsRestart = event.changes.some((change) => {
										return (change.type === FileChangeType.ADDED || change.type === FileChangeType.DELETED) && !!match(pattern, change.resource.fsPath);
900
									});
901 902 903 904 905 906 907 908 909 910 911 912 913 914
									if (needsRestart) {
										this.terminate().done(() => {
											// We need to give the child process a change to stop.
											setTimeout(() => {
												this.executeTarget(fn);
											}, 2000);
										});
									}
								});
							}
							return executeResult.promise.then((value) => {
								if (this.clearTaskSystemPromise) {
									this._taskSystemPromise = null;
									this.clearTaskSystemPromise = false;
915
								}
916
								return value;
917
							});
918 919
						} else {
							return executeResult.promise;
D
Dirk Baeumer 已提交
920
						}
921 922
					}, (err: any) => {
						this.handleError(err);
D
Dirk Baeumer 已提交
923
					});
924
			});
E
Erich Gamma 已提交
925 926 927 928 929 930 931 932 933 934 935 936 937
		});
	}

	public isActive(): TPromise<boolean> {
		if (this._taskSystemPromise) {
			return this.taskSystemPromise.then(taskSystem => taskSystem.isActive());
		}
		return TPromise.as(false);
	}

	public terminate(): TPromise<TerminateResponse> {
		if (this._taskSystemPromise) {
			return this.taskSystemPromise.then(taskSystem => {
J
Johannes Rieken 已提交
938 939 940 941 942 943
				return taskSystem.terminate();
			}).then(response => {
				if (response.success) {
					if (this.clearTaskSystemPromise) {
						this._taskSystemPromise = null;
						this.clearTaskSystemPromise = false;
E
Erich Gamma 已提交
944
					}
J
Johannes Rieken 已提交
945 946 947 948 949
					this.emit(TaskServiceEvents.Terminated, {});
					this.disposeFileChangesListener();
				}
				return response;
			});
E
Erich Gamma 已提交
950
		}
J
Johannes Rieken 已提交
951
		return TPromise.as({ success: true });
E
Erich Gamma 已提交
952 953 954 955 956 957 958 959
	}

	public tasks(): TPromise<TaskDescription[]> {
		return this.taskSystemPromise.then(taskSystem => taskSystem.tasks());
	}

	public beforeShutdown(): boolean | TPromise<boolean> {
		if (this._taskSystem && this._taskSystem.isActiveSync()) {
D
Dirk Baeumer 已提交
960
			if (this._taskSystem.canAutoTerminate() || this.messageService.confirm({
E
Erich Gamma 已提交
961
				message: nls.localize('TaskSystem.runningTask', 'There is a task running. Do you want to terminate it?'),
B
Benjamin Pasero 已提交
962
				primaryButton: nls.localize({ key: 'TaskSystem.terminateTask', comment: ['&& denotes a mnemonic'] }, "&&Terminate Task")
E
Erich Gamma 已提交
963 964 965 966 967
			})) {
				return this._taskSystem.terminate().then((response) => {
					if (response.success) {
						this.emit(TaskServiceEvents.Terminated, {});
						this._taskSystem = null;
D
Dirk Baeumer 已提交
968
						this.disposeFileChangesListener();
E
Erich Gamma 已提交
969 970
						this.disposeTaskSystemListeners();
						return false; // no veto
D
Dirk Baeumer 已提交
971 972 973 974 975
					} else if (response.code && response.code === TerminateResponseCode.ProcessNotFound) {
						return !this.messageService.confirm({
							message: nls.localize('TaskSystem.noProcess', 'The launched task doesn\'t exist anymore. If the task spawned background processes exiting VS Code might result in orphaned processes. To avoid this start the last background process with a wait flag.'),
							primaryButton: nls.localize({ key: 'TaskSystem.exitAnyways', comment: ['&& denotes a mnemonic'] }, "&&Exit Anyways")
						});
E
Erich Gamma 已提交
976 977 978 979 980 981 982 983 984 985 986 987
					}
					return true; // veto
				}, (err) => {
					return true; // veto
				});
			} else {
				return true; // veto
			}
		}
		return false; // Nothing to do here
	}

988
	private getConfigureAction(code: TaskErrors): Action {
J
Johannes Rieken 已提交
989
		switch (code) {
990 991 992 993 994 995
			case TaskErrors.NoBuildTask:
				return this.configureBuildTask();
			default:
				return this.configureAction();
		}
	}
J
Johannes Rieken 已提交
996
	private handleError(err: any): void {
E
Erich Gamma 已提交
997 998 999
		let showOutput = true;
		if (err instanceof TaskError) {
			let buildError = <TaskError>err;
1000 1001 1002
			let needsConfig = buildError.code === TaskErrors.NotConfigured || buildError.code === TaskErrors.NoBuildTask || buildError.code === TaskErrors.NoTestTask;
			let needsTerminate = buildError.code === TaskErrors.RunningTask;
			if (needsConfig || needsTerminate) {
E
Erich Gamma 已提交
1003
				let closeAction = new CloseMessageAction();
1004
				let action = needsConfig
1005
					? this.getConfigureAction(buildError.code)
1006
					: new TerminateAction(TerminateAction.ID, TerminateAction.TEXT, this, this.telemetryService, this.messageService, this.contextService, this.terminalService);
E
Erich Gamma 已提交
1007

J
Johannes Rieken 已提交
1008
				closeAction.closeFunction = this.messageService.show(buildError.severity, { message: buildError.message, actions: [action, closeAction] });
E
Erich Gamma 已提交
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
			} else {
				this.messageService.show(buildError.severity, buildError.message);
			}
		} else if (err instanceof Error) {
			let error = <Error>err;
			this.messageService.show(Severity.Error, error.message);
		} else if (Types.isString(err)) {
			this.messageService.show(Severity.Error, <string>err);
		} else {
			this.messageService.show(Severity.Error, nls.localize('TaskSystem.unknownError', 'An error has occurred while running a task. See task log for details.'));
		}
		if (showOutput) {
1021
			this.outputChannel.show(true);
E
Erich Gamma 已提交
1022 1023 1024 1025
		}
	}
}

1026 1027
let tasksCategory = nls.localize('tasksCategory', "Tasks");
let workbenchActionsRegistry = <IWorkbenchActionRegistry>Registry.as(WorkbenchActionExtensions.WorkbenchActions);
1028 1029 1030
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureTaskRunnerAction, ConfigureTaskRunnerAction.ID, ConfigureTaskRunnerAction.TEXT), 'Tasks: Configure Task Runner', tasksCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(BuildAction, BuildAction.ID, BuildAction.TEXT, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_B }), 'Tasks: Run Build Task', tasksCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(TestAction, TestAction.ID, TestAction.TEXT), 'Tasks: Run Test Task', tasksCategory);
1031 1032
// workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(RebuildAction, RebuildAction.ID, RebuildAction.TEXT), tasksCategory);
// workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CleanAction, CleanAction.ID, CleanAction.TEXT), tasksCategory);
1033 1034 1035
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(TerminateAction, TerminateAction.ID, TerminateAction.TEXT), 'Tasks: Terminate Running Task', tasksCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowLogAction, ShowLogAction.ID, ShowLogAction.TEXT), 'Tasks: Show Task Log', tasksCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(RunTaskAction, RunTaskAction.ID, RunTaskAction.TEXT), 'Tasks: Run Task', tasksCategory);
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061

// Task Service
registerSingleton(ITaskService, TaskService);

// Register Quick Open
(<IQuickOpenRegistry>Registry.as(QuickOpenExtensions.Quickopen)).registerQuickOpenHandler(
	new QuickOpenHandlerDescriptor(
		'vs/workbench/parts/tasks/browser/taskQuickOpen',
		'QuickOpenHandler',
		'task ',
		nls.localize('taskCommands', "Run Task")
	)
);

// Status bar
let statusbarRegistry = <IStatusbarRegistry>Registry.as(StatusbarExtensions.Statusbar);
statusbarRegistry.registerStatusbarItem(new StatusbarItemDescriptor(StatusBarItem, StatusbarAlignment.LEFT, 50 /* Medium Priority */));

// Output channel
let outputChannelRegistry = <IOutputChannelRegistry>Registry.as(OutputExt.OutputChannels);
outputChannelRegistry.registerChannel(TaskService.OutputChannelId, TaskService.OutputChannelLabel);

// (<IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench)).registerWorkbenchContribution(TaskServiceParticipant);

// tasks.json validation
let schemaId = 'vscode://schemas/tasks';
J
Johannes Rieken 已提交
1062
let schema: IJSONSchema =
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
	{
		'id': schemaId,
		'description': 'Task definition file',
		'type': 'object',
		'default': {
			'version': '0.1.0',
			'command': 'myCommand',
			'isShellCommand': false,
			'args': [],
			'showOutput': 'always',
			'tasks': [
				{
					'taskName': 'build',
					'showOutput': 'silent',
					'isBuildCommand': true,
					'problemMatcher': ['$tsc', '$lessCompile']
				}
			]
		},
		'definitions': {
			'showOutputType': {
				'type': 'string',
1085
				'enum': ['always', 'silent', 'never']
1086
			},
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
			'options': {
				'type': 'object',
				'description': nls.localize('JsonSchema.options', 'Additional command options'),
				'properties': {
					'cwd': {
						'type': 'string',
						'description': nls.localize('JsonSchema.options.cwd', 'The current working directory of the executed program or script. If omitted Code\'s current workspace root is used.')
					},
					'env': {
						'type': 'object',
						'additionalProperties': {
							'type': 'string'
						},
						'description': nls.localize('JsonSchema.options.env', 'The environment of the executed program or shell. If omitted the parent process\' environment is used.')
					}
				},
				'additionalProperties': {
					'type': ['string', 'array', 'object']
				}
			},
1107 1108
			'patternType': {
				'anyOf': [
E
Erich Gamma 已提交
1109
					{
1110
						'type': 'string',
J
Johannes Rieken 已提交
1111
						'enum': ['$tsc', '$tsc-watch', '$msCompile', '$lessCompile', '$gulp-tsc', '$cpp', '$csc', '$vb', '$jshint', '$jshint-stylish', '$eslint-compact', '$eslint-stylish', '$go']
1112 1113 1114 1115
					},
					{
						'$ref': '#/definitions/pattern'
					},
E
Erich Gamma 已提交
1116
					{
1117 1118 1119 1120
						'type': 'array',
						'items': {
							'$ref': '#/definitions/pattern'
						}
E
Erich Gamma 已提交
1121 1122 1123
					}
				]
			},
1124 1125 1126 1127 1128 1129
			'pattern': {
				'default': {
					'regexp': '^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$',
					'file': 1,
					'location': 2,
					'message': 3
E
Erich Gamma 已提交
1130
				},
1131 1132 1133 1134 1135
				'additionalProperties': false,
				'properties': {
					'regexp': {
						'type': 'string',
						'description': nls.localize('JsonSchema.pattern.regexp', 'The regular expression to find an error, warning or info in the output.')
E
Erich Gamma 已提交
1136
					},
1137 1138 1139 1140 1141 1142
					'file': {
						'type': 'integer',
						'description': nls.localize('JsonSchema.pattern.file', 'The match group index of the filename. If omitted 1 is used.')
					},
					'location': {
						'type': 'integer',
1143
						'description': nls.localize('JsonSchema.pattern.location', 'The match group index of the problem\'s location. Valid location patterns are: (line), (line,column) and (startLine,startColumn,endLine,endColumn). If omitted (line,column) is assumed.')
1144 1145 1146 1147 1148 1149 1150
					},
					'line': {
						'type': 'integer',
						'description': nls.localize('JsonSchema.pattern.line', 'The match group index of the problem\'s line. Defaults to 2')
					},
					'column': {
						'type': 'integer',
1151
						'description': nls.localize('JsonSchema.pattern.column', 'The match group index of the problem\'s line character. Defaults to 3')
1152 1153 1154 1155 1156 1157 1158
					},
					'endLine': {
						'type': 'integer',
						'description': nls.localize('JsonSchema.pattern.endLine', 'The match group index of the problem\'s end line. Defaults to undefined')
					},
					'endColumn': {
						'type': 'integer',
1159
						'description': nls.localize('JsonSchema.pattern.endColumn', 'The match group index of the problem\'s end line character. Defaults to undefined')
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
					},
					'severity': {
						'type': 'integer',
						'description': nls.localize('JsonSchema.pattern.severity', 'The match group index of the problem\'s severity. Defaults to undefined')
					},
					'code': {
						'type': 'integer',
						'description': nls.localize('JsonSchema.pattern.code', 'The match group index of the problem\'s code. Defaults to undefined')
					},
					'message': {
						'type': 'integer',
						'description': nls.localize('JsonSchema.pattern.message', 'The match group index of the message. If omitted it defaults to 4 if location is specified. Otherwise it defaults to 5.')
					},
					'loop': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.pattern.loop', 'In a multi line matcher loop indicated whether this pattern is executed in a loop as long as it matches. Can only specified on a last pattern in a multi line pattern.')
E
Erich Gamma 已提交
1176
					}
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
				}
			},
			'problemMatcherType': {
				'oneOf': [
					{
						'type': 'string',
						'enum': ['$tsc', '$tsc-watch', '$msCompile', '$lessCompile', '$gulp-tsc', '$jshint', '$jshint-stylish', '$eslint-compact', '$eslint-stylish', '$go']
					},
					{
						'$ref': '#/definitions/problemMatcher'
					},
					{
						'type': 'array',
						'items': {
							'anyOf': [
E
Erich Gamma 已提交
1192
								{
1193
									'$ref': '#/definitions/problemMatcher'
E
Erich Gamma 已提交
1194 1195
								},
								{
1196 1197
									'type': 'string',
									'enum': ['$tsc', '$tsc-watch', '$msCompile', '$lessCompile', '$gulp-tsc', '$jshint', '$jshint-stylish', '$eslint-compact', '$eslint-stylish', '$go']
E
Erich Gamma 已提交
1198
								}
1199
							]
E
Erich Gamma 已提交
1200 1201
						}
					}
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
				]
			},
			'watchingPattern': {
				'type': 'object',
				'additionalProperties': false,
				'properties': {
					'regexp': {
						'type': 'string',
						'description': nls.localize('JsonSchema.watchingPattern.regexp', 'The regular expression to detect the begin or end of a watching task.')
					},
					'file': {
						'type': 'integer',
						'description': nls.localize('JsonSchema.watchingPattern.file', 'The match group index of the filename. Can be omitted.')
					},
				}
			},
			'problemMatcher': {
				'type': 'object',
				'additionalProperties': false,
				'properties': {
					'base': {
						'type': 'string',
						'enum': ['$tsc', '$tsc-watch', '$msCompile', '$lessCompile', '$gulp-tsc', '$jshint', '$jshint-stylish', '$eslint-compact', '$eslint-stylish', '$go'],
						'description': nls.localize('JsonSchema.problemMatcher.base', 'The name of a base problem matcher to use.')
					},
					'owner': {
						'type': 'string',
						'description': nls.localize('JsonSchema.problemMatcher.owner', 'The owner of the problem inside Code. Can be omitted if base is specified. Defaults to \'external\' if omitted and base is not specified.')
					},
					'severity': {
						'type': 'string',
						'enum': ['error', 'warning', 'info'],
						'description': nls.localize('JsonSchema.problemMatcher.severity', 'The default severity for captures problems. Is used if the pattern doesn\'t define a match group for severity.')
					},
					'applyTo': {
						'type': 'string',
						'enum': ['allDocuments', 'openDocuments', 'closedDocuments'],
						'description': nls.localize('JsonSchema.problemMatcher.applyTo', 'Controls if a problem reported on a text document is applied only to open, closed or all documents.')
					},
					'pattern': {
						'$ref': '#/definitions/patternType',
						'description': nls.localize('JsonSchema.problemMatcher.pattern', 'A problem pattern or the name of a predefined problem pattern. Can be omitted if base is specified.')
					},
					'fileLocation': {
						'oneOf': [
							{
								'type': 'string',
								'enum': ['absolute', 'relative']
							},
							{
								'type': 'array',
								'items': {
									'type': 'string'
								}
E
Erich Gamma 已提交
1256
							}
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
						],
						'description': nls.localize('JsonSchema.problemMatcher.fileLocation', 'Defines how file names reported in a problem pattern should be interpreted.')
					},
					'watching': {
						'type': 'object',
						'additionalProperties': false,
						'properties': {
							'activeOnStart': {
								'type': 'boolean',
								'description': nls.localize('JsonSchema.problemMatcher.watching.activeOnStart', 'If set to true the watcher is in active mode when the task starts. This is equals of issuing a line that matches the beginPattern')
							},
							'beginsPattern': {
								'oneOf': [
									{
1271 1272
										'type': 'string'
									},
1273 1274 1275 1276 1277
									{
										'type': '#/definitions/watchingPattern'
									}
								],
								'description': nls.localize('JsonSchema.problemMatcher.watching.beginsPattern', 'If matched in the output the start of a watching task is signaled.')
E
Erich Gamma 已提交
1278
							},
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
							'endsPattern': {
								'oneOf': [
									{
										'type': 'string'
									},
									{
										'type': '#/definitions/watchingPattern'
									}
								],
								'description': nls.localize('JsonSchema.problemMatcher.watching.endsPattern', 'If matched in the output the end of a watching task is signaled.')
E
Erich Gamma 已提交
1289 1290
							}
						}
1291 1292 1293 1294 1295 1296 1297 1298
					},
					'watchedTaskBeginsRegExp': {
						'type': 'string',
						'description': nls.localize('JsonSchema.problemMatcher.watchedBegin', 'A regular expression signaling that a watched tasks begins executing triggered through file watching.')
					},
					'watchedTaskEndsRegExp': {
						'type': 'string',
						'description': nls.localize('JsonSchema.problemMatcher.watchedEnd', 'A regular expression signaling that a watched tasks ends executing.')
E
Erich Gamma 已提交
1299
					}
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
				}
			},
			'baseTaskRunnerConfiguration': {
				'type': 'object',
				'properties': {
					'command': {
						'type': 'string',
						'description': nls.localize('JsonSchema.command', 'The command to be executed. Can be an external program or a shell command.')
					},
					'isShellCommand': {
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
						'anyOf': [
							{
								'type': 'boolean',
								'default': true,
								'description': nls.localize('JsonSchema.shell', 'Specifies whether the command is a shell command or an external program. Defaults to false if omitted.')
							},
							{
								'$ref': '#definitions/shellConfiguration'
							}
						]
1320 1321 1322 1323 1324 1325 1326 1327 1328
					},
					'args': {
						'type': 'array',
						'description': nls.localize('JsonSchema.args', 'Additional arguments passed to the command.'),
						'items': {
							'type': 'string'
						}
					},
					'options': {
1329
						'$ref': '#/definitions/options'
D
Dirk Baeumer 已提交
1330
					},
1331 1332 1333 1334 1335 1336
					'showOutput': {
						'$ref': '#/definitions/showOutputType',
						'description': nls.localize('JsonSchema.showOutput', 'Controls whether the output of the running task is shown or not. If omitted \'always\' is used.')
					},
					'isWatching': {
						'type': 'boolean',
1337
						'deprecationMessage': nls.localize('JsonSchema.watching.deprecation', 'Deprecated. Use isBackground instead.'),
1338 1339 1340
						'description': nls.localize('JsonSchema.watching', 'Whether the executed task is kept alive and is watching the file system.'),
						'default': true
					},
1341 1342 1343 1344 1345
					'isBackground': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.background', 'Whether the executed task is kept alive and is running in the background.'),
						'default': true
					},
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
					'promptOnClose': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.promptOnClose', 'Whether the user is prompted when VS Code closes with a running background task.'),
						'default': false
					},
					'echoCommand': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.echoCommand', 'Controls whether the executed command is echoed to the output. Default is false.'),
						'default': true
					},
					'suppressTaskName': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.suppressTaskName', 'Controls whether the task name is added as an argument to the command. Default is false.'),
						'default': true
					},
					'taskSelector': {
						'type': 'string',
						'description': nls.localize('JsonSchema.taskSelector', 'Prefix to indicate that an argument is task.')
					},
					'problemMatcher': {
						'$ref': '#/definitions/problemMatcherType',
						'description': nls.localize('JsonSchema.matchers', 'The problem matcher(s) to use. Can either be a string or a problem matcher definition or an array of strings and problem matchers.')
					},
					'tasks': {
						'type': 'array',
						'description': nls.localize('JsonSchema.tasks', 'The task configurations. Usually these are enrichments of task already defined in the external task runner.'),
						'items': {
							'type': 'object',
							'$ref': '#/definitions/taskDescription'
D
Dirk Baeumer 已提交
1375
						}
1376
					}
E
Erich Gamma 已提交
1377 1378
				}
			},
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
			'shellConfiguration': {
				'type': 'object',
				'additionalProperties': false,
				'properties': {
					'executable': {
						'type': 'string',
						'description': nls.localize('JsonSchema.shell.executable', 'The shell to be used.')
					},
					'args': {
						'type': 'array',
						'description': nls.localize('JsonSchema.shell.args', 'The shell arguments.'),
						'items': {
							'type': 'string'
						}
					}
				}
			},
1396 1397 1398 1399 1400 1401 1402 1403 1404
			'commandConfiguration': {
				'type': 'object',
				'additionalProperties': false,
				'properties': {
					'command': {
						'type': 'string',
						'description': nls.localize('JsonSchema.command', 'The command to be executed. Can be an external program or a shell command.')
					},
					'isShellCommand': {
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
						'anyOf': [
							{
								'type': 'boolean',
								'default': true,
								'description': nls.localize('JsonSchema.shell', 'Specifies whether the command is a shell command or an external program. Defaults to false if omitted.')
							},
							{
								'$ref': '#definitions/shellConfiguration'
							}
						]
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
					},
					'args': {
						'type': 'array',
						'description': nls.localize('JsonSchema.tasks.args', 'Arguments passed to the command when this task is invoked.'),
						'items': {
							'type': 'string'
						}
					},
					'options': {
						'$ref': '#/definitions/options'
					}
				}
			},
1428 1429 1430 1431 1432 1433 1434 1435 1436
			'taskDescription': {
				'type': 'object',
				'required': ['taskName'],
				'additionalProperties': false,
				'properties': {
					'taskName': {
						'type': 'string',
						'description': nls.localize('JsonSchema.tasks.taskName', "The task's name")
					},
1437 1438 1439 1440 1441
					'command': {
						'type': 'string',
						'description': nls.localize('JsonSchema.command', 'The command to be executed. Can be an external program or a shell command.')
					},
					'isShellCommand': {
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451
						'anyOf': [
							{
								'type': 'boolean',
								'default': true,
								'description': nls.localize('JsonSchema.shell', 'Specifies whether the command is a shell command or an external program. Defaults to false if omitted.')
							},
							{
								'$ref': '#definitions/shellConfiguration'
							}
						]
1452
					},
1453 1454
					'args': {
						'type': 'array',
1455
						'description': nls.localize('JsonSchema.tasks.args', 'Arguments passed to the command when this task is invoked.'),
1456 1457
						'items': {
							'type': 'string'
E
Erich Gamma 已提交
1458
						}
1459
					},
1460 1461 1462
					'options': {
						'$ref': '#/definitions/options'
					},
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
					'windows': {
						'$ref': '#/definitions/commandConfiguration',
						'description': nls.localize('JsonSchema.tasks.windows', 'Windows specific command configuration')
					},
					'osx': {
						'$ref': '#/definitions/commandConfiguration',
						'description': nls.localize('JsonSchema.tasks.mac', 'Mac specific command configuration')
					},
					'linux': {
						'$ref': '#/definitions/commandConfiguration',
						'description': nls.localize('JsonSchema.tasks.linux', 'Linux specific command configuration')
					},
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
					'suppressTaskName': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.tasks.suppressTaskName', 'Controls whether the task name is added as an argument to the command. If omitted the globally defined value is used.'),
						'default': true
					},
					'showOutput': {
						'$ref': '#/definitions/showOutputType',
						'description': nls.localize('JsonSchema.tasks.showOutput', 'Controls whether the output of the running task is shown or not. If omitted the globally defined value is used.')
					},
					'echoCommand': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.echoCommand', 'Controls whether the executed command is echoed to the output. Default is false.'),
						'default': true
					},
					'isWatching': {
						'type': 'boolean',
1491 1492
						'deprecationMessage': nls.localize('JsonSchema.tasks.watching.deprecation', 'Deprecated. Use isBackground instead.'),
						'description': nls.localize('JsonSchema.tasks.watching', 'Whether the executed task is kept alive and is watching the file system.'),
1493 1494 1495 1496 1497
						'default': true
					},
					'isBackground': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.tasks.background', 'Whether the executed task is kept alive and is running in the background.'),
1498 1499
						'default': true
					},
1500 1501 1502 1503 1504
					'promptOnClose': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.tasks.promptOnClose', 'Whether the user is prompted when VS Code closes with a running task.'),
						'default': false
					},
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
					'isBuildCommand': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.tasks.build', 'Maps this task to Code\'s default build command.'),
						'default': true
					},
					'isTestCommand': {
						'type': 'boolean',
						'description': nls.localize('JsonSchema.tasks.test', 'Maps this task to Code\'s default test command.'),
						'default': true
					},
					'problemMatcher': {
						'$ref': '#/definitions/problemMatcherType',
						'description': nls.localize('JsonSchema.tasks.matchers', 'The problem matcher(s) to use. Can either be a string or a problem matcher definition or an array of strings and problem matchers.')
E
Erich Gamma 已提交
1518 1519
					}
				},
1520 1521 1522 1523
				'defaultSnippets': [
					{
						'label': 'Empty task',
						'body': {
1524
							'taskName': '${1:taskName}'
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541
						}
					}
				]
			}
		},
		'allOf': [
			{
				'type': 'object',
				'required': ['version'],
				'properties': {
					'version': {
						'type': 'string',
						'enum': ['0.1.0'],
						'description': nls.localize('JsonSchema.version', 'The config\'s version number')
					},
					'windows': {
						'$ref': '#/definitions/baseTaskRunnerConfiguration',
1542
						'description': nls.localize('JsonSchema.windows', 'Windows specific command configuration')
1543 1544 1545
					},
					'osx': {
						'$ref': '#/definitions/baseTaskRunnerConfiguration',
1546
						'description': nls.localize('JsonSchema.mac', 'Mac specific command configuration')
1547 1548 1549
					},
					'linux': {
						'$ref': '#/definitions/baseTaskRunnerConfiguration',
1550
						'description': nls.localize('JsonSchema.linux', 'Linux specific command configuration')
1551
					}
E
Erich Gamma 已提交
1552
				}
1553 1554 1555 1556 1557 1558 1559 1560
			},
			{
				'$ref': '#/definitions/baseTaskRunnerConfiguration'
			}
		]
	};
let jsonRegistry = <jsonContributionRegistry.IJSONContributionRegistry>Registry.as(jsonContributionRegistry.Extensions.JSONContribution);
jsonRegistry.registerSchema(schemaId, schema);