extensionService.ts 40.4 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import * as nls from 'vs/nls';
7
import * as path from 'vs/base/common/path';
A
Alex Dima 已提交
8
import { ipcRenderer as ipc } from 'electron';
9
import { isNonEmptyArray } from 'vs/base/common/arrays';
A
Alex Dima 已提交
10 11
import { Barrier, runWhenIdle } from 'vs/base/common/async';
import { Emitter, Event } from 'vs/base/common/event';
12
import { Disposable } from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
13
import * as perf from 'vs/base/common/performance';
14
import { isEqualOrParent } from 'vs/base/common/resources';
A
Alex Dima 已提交
15
import { URI } from 'vs/base/common/uri';
16
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
17
import { EnablementState, IExtensionEnablementService, IExtensionIdentifier, IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
18
import { BetterMergeId, areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
A
Alex Dima 已提交
19 20 21 22 23 24
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInitDataProvider, RemoteExtensionHostClient } from 'vs/workbench/services/extensions/electron-browser/remoteExtensionHostClient';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { IRemoteAuthorityResolverService, ResolvedAuthority, RemoteAuthorityResolverError } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { isUIExtension } from 'vs/workbench/services/extensions/node/extensionsUtil';
import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
B
Benjamin Pasero 已提交
25
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
26
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
27 28
import pkg from 'vs/platform/product/node/package';
import product from 'vs/platform/product/node/product';
29
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
A
Alex Dima 已提交
30 31
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
32
import { ActivationTimes, ExtensionPointContribution, IExtensionService, IExtensionsStatus, IMessage, IWillActivateEvent, IResponsiveStateChangeEvent, toExtension } from 'vs/workbench/services/extensions/common/extensions';
A
Alex Dima 已提交
33
import { ExtensionMessageCollector, ExtensionPoint, ExtensionsRegistry, IExtensionPoint, IExtensionPointUser, schema } from 'vs/workbench/services/extensions/common/extensionsRegistry';
34
import { ExtensionHostProcessWorker } from 'vs/workbench/services/extensions/electron-browser/extensionHost';
35 36
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
import { ResponsiveState } from 'vs/workbench/services/extensions/common/rpcProtocol';
37
import { CachedExtensionScanner, Logger } from 'vs/workbench/services/extensions/electron-browser/cachedExtensionScanner';
J
Johannes Rieken 已提交
38
import { ExtensionHostProcessManager } from 'vs/workbench/services/extensions/common/extensionHostProcessManager';
39
import { ExtensionIdentifier, IExtension, ExtensionType, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
40
import { Schemas } from 'vs/base/common/network';
41
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
42
import { IFileService } from 'vs/platform/files/common/files';
43
import { parseExtensionDevOptions } from 'vs/workbench/services/extensions/common/extensionDevOptions';
A
Alex Dima 已提交
44
import { PersistenConnectionEventType } from 'vs/platform/remote/common/remoteAgentConnection';
45

46
const hasOwnProperty = Object.hasOwnProperty;
R
Rob Lourens 已提交
47
const NO_OP_VOID_PROMISE = Promise.resolve<void>(undefined);
48

49 50
schema.properties.engines.properties.vscode.default = `^${pkg.version}`;

M
Matt Bierner 已提交
51
let productAllowProposedApi: Set<string> | null = null;
52
function allowProposedApiFromProduct(id: ExtensionIdentifier): boolean {
53
	// create set if needed
M
Matt Bierner 已提交
54
	if (!productAllowProposedApi) {
55 56
		productAllowProposedApi = new Set<string>();
		if (isNonEmptyArray(product.extensionAllowedProposedApi)) {
M
Matt Bierner 已提交
57
			product.extensionAllowedProposedApi.forEach((id) => productAllowProposedApi!.add(ExtensionIdentifier.toKey(id)));
58 59
		}
	}
60
	return productAllowProposedApi.has(ExtensionIdentifier.toKey(id));
61 62
}

63 64 65 66 67 68 69
class DeltaExtensionsQueueItem {
	constructor(
		public readonly toAdd: IExtension[],
		public readonly toRemove: string[]
	) { }
}

A
Alex Dima 已提交
70
export class ExtensionService extends Disposable implements IExtensionService {
71

72
	public _serviceBrand: any;
73

A
Alex Dima 已提交
74 75
	private _remoteExtensionsEnvironmentData: Map<string, IRemoteAgentEnvironment>;

S
Sandeep Somavarapu 已提交
76
	private readonly _extensionHostLogsLocation: URI;
A
Alex Dima 已提交
77
	private readonly _registry: ExtensionDescriptionRegistry;
78
	private readonly _installedExtensionsReady: Barrier;
79
	private readonly _isDev: boolean;
80
	private readonly _extensionsMessages: Map<string, IMessage[]>;
A
Alex Dima 已提交
81
	private _allRequestedActivateEvents: { [activationEvent: string]: boolean; };
82
	private readonly _extensionScanner: CachedExtensionScanner;
83
	private _deltaExtensionsQueue: DeltaExtensionsQueueItem[];
84

85
	private readonly _onDidRegisterExtensions: Emitter<void> = this._register(new Emitter<void>());
86
	public readonly onDidRegisterExtensions = this._onDidRegisterExtensions.event;
A
Alex Dima 已提交
87

88 89
	private readonly _onDidChangeExtensionsStatus: Emitter<ExtensionIdentifier[]> = this._register(new Emitter<ExtensionIdentifier[]>());
	public readonly onDidChangeExtensionsStatus: Event<ExtensionIdentifier[]> = this._onDidChangeExtensionsStatus.event;
A
Alex Dima 已提交
90

91 92 93
	private readonly _onDidChangeExtensions: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidChangeExtensions: Event<void> = this._onDidChangeExtensions.event;

94 95
	private readonly _onWillActivateByEvent = this._register(new Emitter<IWillActivateEvent>());
	public readonly onWillActivateByEvent: Event<IWillActivateEvent> = this._onWillActivateByEvent.event;
96

97 98
	private readonly _onDidChangeResponsiveChange = this._register(new Emitter<IResponsiveStateChangeEvent>());
	public readonly onDidChangeResponsiveChange: Event<IResponsiveStateChangeEvent> = this._onDidChangeResponsiveChange.event;
99

A
Alex Dima 已提交
100
	// --- Members used per extension host process
101
	private _extensionHostProcessManagers: ExtensionHostProcessManager[];
102
	private _extensionHostActiveExtensions: Map<string, ExtensionIdentifier>;
103 104
	private _extensionHostProcessActivationTimes: Map<string, ActivationTimes>;
	private _extensionHostExtensionRuntimeErrors: Map<string, Error[]>;
105

106 107
	constructor(
		@IInstantiationService private readonly _instantiationService: IInstantiationService,
108
		@INotificationService private readonly _notificationService: INotificationService,
109
		@IWorkbenchEnvironmentService private readonly _environmentService: IWorkbenchEnvironmentService,
110
		@ITelemetryService private readonly _telemetryService: ITelemetryService,
111
		@IExtensionEnablementService private readonly _extensionEnablementService: IExtensionEnablementService,
112
		@IExtensionManagementService private readonly _extensionManagementService: IExtensionManagementService,
113
		@IWindowService private readonly _windowService: IWindowService,
A
Alex Dima 已提交
114 115 116
		@IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService,
		@IRemoteAuthorityResolverService private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService,
		@IConfigurationService private readonly _configurationService: IConfigurationService,
117 118
		@ILifecycleService private readonly _lifecycleService: ILifecycleService,
		@IFileService fileService: IFileService
119
	) {
A
Alex Dima 已提交
120
		super();
121 122 123 124 125 126

		// help the file service to activate providers by activating extensions by file system event
		this._register(fileService.onWillActivateFileSystemProvider(e => {
			e.join(this.activateByEvent(`onFileSystem:${e.scheme}`));
		}));

A
Alex Dima 已提交
127 128 129
		this._remoteExtensionsEnvironmentData = new Map<string, IRemoteAgentEnvironment>();

		this._extensionHostLogsLocation = URI.file(path.join(this._environmentService.logsPath, `exthost${_windowService.windowId}`));
A
Alex Dima 已提交
130
		this._registry = new ExtensionDescriptionRegistry([]);
131
		this._installedExtensionsReady = new Barrier();
132
		this._isDev = !this._environmentService.isBuilt || this._environmentService.isExtensionDevelopment;
133
		this._extensionsMessages = new Map<string, IMessage[]>();
A
Alex Dima 已提交
134
		this._allRequestedActivateEvents = Object.create(null);
135
		this._extensionScanner = this._instantiationService.createInstance(CachedExtensionScanner);
136
		this._deltaExtensionsQueue = [];
137

138
		this._extensionHostProcessManagers = [];
139
		this._extensionHostActiveExtensions = new Map<string, ExtensionIdentifier>();
140 141
		this._extensionHostProcessActivationTimes = new Map<string, ActivationTimes>();
		this._extensionHostExtensionRuntimeErrors = new Map<string, Error[]>();
142

143
		this._startDelayed(this._lifecycleService);
144

S
Sandeep Somavarapu 已提交
145 146
		if (this._extensionEnablementService.allUserExtensionsDisabled) {
			this._notificationService.prompt(Severity.Info, nls.localize('extensionsDisabled', "All installed extensions are temporarily disabled. Reload the window to return to the previous state."), [{
147 148 149 150 151
				label: nls.localize('Reload', "Reload"),
				run: () => {
					this._windowService.reloadWindow();
				}
			}]);
152
		}
A
Alex Dima 已提交
153

154
		this._register(this._extensionEnablementService.onEnablementChanged((extensions) => {
155 156
			let toAdd: IExtension[] = [];
			let toRemove: string[] = [];
S
Sandeep Somavarapu 已提交
157 158 159
			for (const extension of extensions) {
				if (this._extensionEnablementService.isEnabled(extension)) {
					// an extension has been enabled
160
					toAdd.push(extension);
S
Sandeep Somavarapu 已提交
161 162
				} else {
					// an extension has been disabled
163
					toRemove.push(extension.identifier.id);
S
Sandeep Somavarapu 已提交
164
				}
165
			}
166
			this._handleDeltaExtensions(new DeltaExtensionsQueueItem(toAdd, toRemove));
167
		}));
A
Alex Dima 已提交
168

169
		this._register(this._extensionManagementService.onDidInstallExtension((event) => {
170
			if (event.local) {
S
Sandeep Somavarapu 已提交
171 172 173 174
				if (this._extensionEnablementService.isEnabled(event.local)) {
					// an extension has been installed
					this._handleDeltaExtensions(new DeltaExtensionsQueueItem([event.local], []));
				}
175
			}
176
		}));
177

178
		this._register(this._extensionManagementService.onDidUninstallExtension((event) => {
179 180
			if (!event.error) {
				// an extension has been uninstalled
181
				this._handleDeltaExtensions(new DeltaExtensionsQueueItem([], [event.identifier.id]));
182
			}
183
		}));
A
Alex Dima 已提交
184 185
	}

186 187 188 189 190
	private _inHandleDeltaExtensions = false;
	private async _handleDeltaExtensions(item: DeltaExtensionsQueueItem): Promise<void> {
		this._deltaExtensionsQueue.push(item);
		if (this._inHandleDeltaExtensions) {
			// Let the current item finish, the new one will be picked up
191
			return;
A
Alex Dima 已提交
192 193
		}

194
		while (this._deltaExtensionsQueue.length > 0) {
M
Matt Bierner 已提交
195
			const item = this._deltaExtensionsQueue.shift()!;
196 197 198 199 200 201 202 203 204 205
			try {
				this._inHandleDeltaExtensions = true;
				await this._deltaExtensions(item.toAdd, item.toRemove);
			} finally {
				this._inHandleDeltaExtensions = false;
			}
		}
	}

	private async _deltaExtensions(_toAdd: IExtension[], _toRemove: string[]): Promise<void> {
206
		if (this._environmentService.configuration.remoteAuthority) {
207 208 209
			return;
		}

210 211 212
		let toAdd: IExtensionDescription[] = [];
		for (let i = 0, len = _toAdd.length; i < len; i++) {
			const extension = _toAdd[i];
A
Alex Dima 已提交
213

214 215 216 217
			if (extension.location.scheme !== Schemas.file) {
				continue;
			}

218 219 220 221 222 223
			const existingExtensionDescription = this._registry.getExtensionDescription(extension.identifier.id);
			if (existingExtensionDescription) {
				// this extension is already running (most likely at a different version)
				continue;
			}

224
			const extensionDescription = await this._extensionScanner.scanSingleExtension(extension.location.fsPath, extension.type === ExtensionType.System, this.createLogger());
225 226
			if (!extensionDescription) {
				// could not scan extension...
227 228
				continue;
			}
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
			toAdd.push(extensionDescription);
		}

		let toRemove: IExtensionDescription[] = [];
		for (let i = 0, len = _toRemove.length; i < len; i++) {
			const extensionId = _toRemove[i];
			const extensionDescription = this._registry.getExtensionDescription(extensionId);
			if (!extensionDescription) {
				// ignore disabling/uninstalling an extension which is not running
				continue;
			}

			if (!this._canRemoveExtension(extensionDescription)) {
				// uses non-dynamic extension point or is activated
				continue;
			}

			toRemove.push(extensionDescription);
		}

		if (toAdd.length === 0 && toRemove.length === 0) {
			return;
		}

		// Update the local registry
255 256 257 258 259
		const result = this._registry.deltaExtensions(toAdd, toRemove.map(e => e.identifier));
		toRemove = toRemove.concat(result.removedDueToLooping);
		if (result.removedDueToLooping.length > 0) {
			this._logOrShowMessage(Severity.Error, nls.localize('looping', "The following extensions contain dependency loops and have been disabled: {0}", result.removedDueToLooping.map(e => `'${e.identifier.value}'`).join(', ')));
		}
260 261 262 263 264

		// Update extension points
		this._rehandleExtensionPoints((<IExtensionDescription[]>[]).concat(toAdd).concat(toRemove));

		// Update the extension host
265
		if (this._extensionHostProcessManagers.length > 0) {
266 267 268
			await this._extensionHostProcessManagers[0].deltaExtensions(toAdd, toRemove.map(e => e.identifier));
		}

269 270
		this._onDidChangeExtensions.fire(undefined);

271 272
		for (let i = 0; i < toAdd.length; i++) {
			this._activateAddedExtensionIfNeeded(toAdd[i]);
273
		}
274 275
	}

276
	private _rehandleExtensionPoints(extensionDescriptions: IExtensionDescription[]): void {
A
Alex Dima 已提交
277
		const affectedExtensionPoints: { [extPointName: string]: boolean; } = Object.create(null);
278 279 280 281 282 283
		for (let extensionDescription of extensionDescriptions) {
			if (extensionDescription.contributes) {
				for (let extPointName in extensionDescription.contributes) {
					if (hasOwnProperty.call(extensionDescription.contributes, extPointName)) {
						affectedExtensionPoints[extPointName] = true;
					}
A
Alex Dima 已提交
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
				}
			}
		}

		const messageHandler = (msg: IMessage) => this._handleExtensionPointMessage(msg);

		const availableExtensions = this._registry.getAllExtensionDescriptions();
		const extensionPoints = ExtensionsRegistry.getExtensionPoints();
		for (let i = 0, len = extensionPoints.length; i < len; i++) {
			if (affectedExtensionPoints[extensionPoints[i].name]) {
				ExtensionService._handleExtensionPoint(extensionPoints[i], availableExtensions, messageHandler);
			}
		}
	}

299
	public canAddExtension(extension: IExtensionDescription): boolean {
300
		if (this._environmentService.configuration.remoteAuthority) {
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
			return false;
		}

		if (extension.extensionLocation.scheme !== Schemas.file) {
			return false;
		}

		const extensionDescription = this._registry.getExtensionDescription(extension.identifier);
		if (extensionDescription) {
			// ignore adding an extension which is already running and cannot be removed
			if (!this._canRemoveExtension(extensionDescription)) {
				return false;
			}
		}

316
		return true;
317 318 319
	}

	public canRemoveExtension(extension: IExtensionDescription): boolean {
320
		if (this._environmentService.configuration.remoteAuthority) {
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
			return false;
		}

		if (extension.extensionLocation.scheme !== Schemas.file) {
			return false;
		}

		const extensionDescription = this._registry.getExtensionDescription(extension.identifier);
		if (!extensionDescription) {
			// ignore removing an extension which is not running
			return false;
		}

		return this._canRemoveExtension(extensionDescription);
	}

337 338 339 340 341 342
	private _canRemoveExtension(extension: IExtensionDescription): boolean {
		if (this._extensionHostActiveExtensions.has(ExtensionIdentifier.toKey(extension.identifier))) {
			// Extension is running, cannot remove it safely
			return false;
		}

343
		return true;
344 345
	}

346
	private async _activateAddedExtensionIfNeeded(extensionDescription: IExtensionDescription): Promise<void> {
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368

		let shouldActivate = false;
		let shouldActivateReason: string | null = null;
		if (Array.isArray(extensionDescription.activationEvents)) {
			for (let activationEvent of extensionDescription.activationEvents) {
				// TODO@joao: there's no easy way to contribute this
				if (activationEvent === 'onUri') {
					activationEvent = `onUri:${ExtensionIdentifier.toKey(extensionDescription.identifier)}`;
				}

				if (this._allRequestedActivateEvents[activationEvent]) {
					// This activation event was fired before the extension was added
					shouldActivate = true;
					shouldActivateReason = activationEvent;
					break;
				}

				if (activationEvent === '*') {
					shouldActivate = true;
					shouldActivateReason = activationEvent;
					break;
				}
369 370 371 372 373 374 375

				if (/^workspaceContains/.test(activationEvent)) {
					// do not trigger a search, just activate in this case...
					shouldActivate = true;
					shouldActivateReason = activationEvent;
					break;
				}
376 377 378 379 380
			}
		}

		if (shouldActivate) {
			await Promise.all(
A
Alex Dima 已提交
381
				this._extensionHostProcessManagers.map(extHostManager => extHostManager.activate(extensionDescription.identifier, shouldActivateReason!))
382 383
			).then(() => { });
		}
384 385
	}

386
	private _startDelayed(lifecycleService: ILifecycleService): void {
B
Benjamin Pasero 已提交
387
		// delay extension host creation and extension scanning
B
Benjamin Pasero 已提交
388 389
		// until the workbench is running. we cannot defer the
		// extension host more (LifecyclePhase.Restored) because
B
Benjamin Pasero 已提交
390 391 392
		// some editors require the extension host to restore
		// and this would result in a deadlock
		// see https://github.com/Microsoft/vscode/issues/41322
B
Benjamin Pasero 已提交
393
		lifecycleService.when(LifecyclePhase.Ready).then(() => {
394 395 396
			// reschedule to ensure this runs after restoring viewlets, panels, and editors
			runWhenIdle(() => {
				perf.mark('willLoadExtensions');
A
Alex Dima 已提交
397
				this._startExtensionHostProcess(true, []);
398 399 400
				this._scanAndHandleExtensions();
				this.whenInstalledExtensionsRegistered().then(() => perf.mark('didLoadExtensions'));
			}, 50 /*max delay*/);
401
		});
A
Alex Dima 已提交
402 403
	}

A
Alex Dima 已提交
404 405
	public dispose(): void {
		super.dispose();
406 407
		this._onWillActivateByEvent.dispose();
		this._onDidChangeResponsiveChange.dispose();
A
Alex Dima 已提交
408 409
	}

410 411
	public restartExtensionHost(): void {
		this._stopExtensionHostProcess();
A
Alex Dima 已提交
412
		this._startExtensionHostProcess(false, Object.keys(this._allRequestedActivateEvents));
413 414
	}

415
	public startExtensionHost(): void {
A
Alex Dima 已提交
416
		this._startExtensionHostProcess(false, Object.keys(this._allRequestedActivateEvents));
417 418 419 420 421 422
	}

	public stopExtensionHost(): void {
		this._stopExtensionHostProcess();
	}

A
Alex Dima 已提交
423
	private _stopExtensionHostProcess(): void {
424
		let previouslyActivatedExtensionIds: ExtensionIdentifier[] = [];
425 426 427
		this._extensionHostActiveExtensions.forEach((value) => {
			previouslyActivatedExtensionIds.push(value);
		});
A
Alex Dima 已提交
428

429 430
		for (const manager of this._extensionHostProcessManagers) {
			manager.dispose();
A
Alex Dima 已提交
431
		}
432
		this._extensionHostProcessManagers = [];
433
		this._extensionHostActiveExtensions = new Map<string, ExtensionIdentifier>();
434 435
		this._extensionHostProcessActivationTimes = new Map<string, ActivationTimes>();
		this._extensionHostExtensionRuntimeErrors = new Map<string, Error[]>();
A
Alex Dima 已提交
436

A
Alex Dima 已提交
437 438 439
		if (previouslyActivatedExtensionIds.length > 0) {
			this._onDidChangeExtensionsStatus.fire(previouslyActivatedExtensionIds);
		}
A
Alex Dima 已提交
440 441
	}

A
Alex Dima 已提交
442 443 444 445 446 447 448 449 450 451 452
	private _createProvider(remoteAuthority: string): IInitDataProvider {
		return {
			remoteAuthority: remoteAuthority,
			getInitData: () => {
				return this._installedExtensionsReady.wait().then(() => {
					return this._remoteExtensionsEnvironmentData.get(remoteAuthority)!;
				});
			}
		};
	}

A
Alex Dima 已提交
453
	private _startExtensionHostProcess(isInitialStart: boolean, initialActivationEvents: string[]): void {
A
Alex Dima 已提交
454 455
		this._stopExtensionHostProcess();

456 457 458 459
		let autoStart: boolean;
		let extensions: Promise<IExtensionDescription[]>;
		if (isInitialStart) {
			autoStart = false;
460
			extensions = this._extensionScanner.scannedExtensions;
461 462 463
		} else {
			// restart case
			autoStart = true;
A
Alex Dima 已提交
464
			extensions = this.getExtensions().then((extensions) => extensions.filter(ext => ext.extensionLocation.scheme === Schemas.file));
465 466 467
		}

		const extHostProcessWorker = this._instantiationService.createInstance(ExtensionHostProcessWorker, autoStart, extensions, this._extensionHostLogsLocation);
A
Alex Dima 已提交
468
		const extHostProcessManager = this._instantiationService.createInstance(ExtensionHostProcessManager, extHostProcessWorker, null, initialActivationEvents);
A
Alex Dima 已提交
469
		extHostProcessManager.onDidCrash(([code, signal]) => this._onExtensionHostCrashed(code, signal, true));
470
		extHostProcessManager.onDidChangeResponsiveState((responsiveState) => { this._onDidChangeResponsiveChange.fire({ isResponsive: responsiveState === ResponsiveState.Responsive }); });
471
		this._extensionHostProcessManagers.push(extHostProcessManager);
A
Alex Dima 已提交
472 473 474 475 476 477 478 479 480

		const remoteAgentConnection = this._remoteAgentService.getConnection();
		if (remoteAgentConnection) {
			const remoteExtHostProcessWorker = this._instantiationService.createInstance(RemoteExtensionHostClient, this.getExtensions(), this._createProvider(remoteAgentConnection.remoteAuthority));
			const remoteExtHostProcessManager = this._instantiationService.createInstance(ExtensionHostProcessManager, remoteExtHostProcessWorker, remoteAgentConnection.remoteAuthority, initialActivationEvents);
			remoteExtHostProcessManager.onDidCrash(([code, signal]) => this._onExtensionHostCrashed(code, signal, false));
			remoteExtHostProcessManager.onDidChangeResponsiveState((responsiveState) => { this._onDidChangeResponsiveChange.fire({ isResponsive: responsiveState === ResponsiveState.Responsive }); });
			this._extensionHostProcessManagers.push(remoteExtHostProcessManager);
		}
A
Alex Dima 已提交
481
	}
482

A
Alex Dima 已提交
483
	private _onExtensionHostCrashed(code: number, signal: string | null, showNotification: boolean): void {
A
Alex Dima 已提交
484 485 486
		console.error('Extension host terminated unexpectedly. Code: ', code, ' Signal: ', signal);
		this._stopExtensionHostProcess();

A
Alex Dima 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
		if (showNotification) {
			if (code === 55) {
				this._notificationService.prompt(
					Severity.Error,
					nls.localize('extensionService.versionMismatchCrash', "Extension host cannot start: version mismatch."),
					[{
						label: nls.localize('relaunch', "Relaunch VS Code"),
						run: () => {
							this._instantiationService.invokeFunction((accessor) => {
								const windowsService = accessor.get(IWindowsService);
								windowsService.relaunch({});
							});
						}
					}]
				);
				return;
			}

			let message = nls.localize('extensionService.crash', "Extension host terminated unexpectedly.");
			if (code === 87) {
				message = nls.localize('extensionService.unresponsiveCrash', "Extension host terminated because it was not responsive.");
			}

			this._notificationService.prompt(Severity.Error, message,
511
				[{
A
Alex Dima 已提交
512 513 514 515 516 517
					label: nls.localize('devTools', "Open Developer Tools"),
					run: () => this._windowService.openDevTools()
				},
				{
					label: nls.localize('restart', "Restart Extension Host"),
					run: () => this._startExtensionHostProcess(false, Object.keys(this._allRequestedActivateEvents))
518 519 520
				}]
			);
		}
521 522
	}

523
	// ---- begin IExtensionService
524

A
Alex Dima 已提交
525
	public activateByEvent(activationEvent: string): Promise<void> {
526
		if (this._installedExtensionsReady.isOpen()) {
A
Alex Dima 已提交
527 528
			// Extensions have been scanned and interpreted

529 530 531
			// Record the fact that this activationEvent was requested (in case of a restart)
			this._allRequestedActivateEvents[activationEvent] = true;

A
Alex Dima 已提交
532 533 534 535 536
			if (!this._registry.containsActivationEvent(activationEvent)) {
				// There is no extension that is interested in this activation event
				return NO_OP_VOID_PROMISE;
			}

537 538
			return this._activateByEvent(activationEvent);
		} else {
A
Alex Dima 已提交
539 540 541 542 543
			// Extensions have not been scanned yet.

			// Record the fact that this activationEvent was requested (in case of a restart)
			this._allRequestedActivateEvents[activationEvent] = true;

544
			return this._installedExtensionsReady.wait().then(() => this._activateByEvent(activationEvent));
545 546
		}
	}
547

A
Alex Dima 已提交
548 549
	private _activateByEvent(activationEvent: string): Promise<void> {
		const result = Promise.all(
550 551
			this._extensionHostProcessManagers.map(extHostManager => extHostManager.activateByEvent(activationEvent))
		).then(() => { });
552 553 554 555 556
		this._onWillActivateByEvent.fire({
			event: activationEvent,
			activation: result
		});
		return result;
557 558
	}

A
Alex Dima 已提交
559
	public whenInstalledExtensionsRegistered(): Promise<boolean> {
560
		return this._installedExtensionsReady.wait();
561
	}
562

A
Alex Dima 已提交
563
	public getExtensions(): Promise<IExtensionDescription[]> {
564
		return this._installedExtensionsReady.wait().then(() => {
A
Alex Dima 已提交
565 566 567 568
			return this._registry.getAllExtensionDescriptions();
		});
	}

569 570 571 572 573 574
	public getExtension(id: string): Promise<IExtensionDescription | undefined> {
		return this._installedExtensionsReady.wait().then(() => {
			return this._registry.getExtensionDescription(id);
		});
	}

A
Alex Dima 已提交
575
	public readExtensionPointContributions<T>(extPoint: IExtensionPoint<T>): Promise<ExtensionPointContribution<T>[]> {
576
		return this._installedExtensionsReady.wait().then(() => {
A
Alex Dima 已提交
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
			let availableExtensions = this._registry.getAllExtensionDescriptions();

			let result: ExtensionPointContribution<T>[] = [], resultLen = 0;
			for (let i = 0, len = availableExtensions.length; i < len; i++) {
				let desc = availableExtensions[i];

				if (desc.contributes && hasOwnProperty.call(desc.contributes, extPoint.name)) {
					result[resultLen++] = new ExtensionPointContribution<T>(desc, desc.contributes[extPoint.name]);
				}
			}

			return result;
		});
	}

592
	public getExtensionsStatus(): { [id: string]: IExtensionsStatus; } {
A
Alex Dima 已提交
593
		let result: { [id: string]: IExtensionsStatus; } = Object.create(null);
A
Alex Dima 已提交
594 595
		if (this._registry) {
			const extensions = this._registry.getAllExtensionDescriptions();
596
			for (const extension of extensions) {
597
				const extensionKey = ExtensionIdentifier.toKey(extension.identifier);
598
				result[extension.identifier.value] = {
A
Alex Dima 已提交
599
					messages: this._extensionsMessages.get(extensionKey) || [],
600
					activationTimes: this._extensionHostProcessActivationTimes.get(extensionKey),
A
Alex Dima 已提交
601
					runtimeErrors: this._extensionHostExtensionRuntimeErrors.get(extensionKey) || [],
A
Alex Dima 已提交
602 603
				};
			}
A
Alex Dima 已提交
604 605
		}
		return result;
606 607
	}

608 609 610 611 612 613 614
	public getInspectPort(): number {
		if (this._extensionHostProcessManagers.length > 0) {
			return this._extensionHostProcessManagers[0].getInspectPort();
		}
		return 0;
	}

615
	// ---- end IExtensionService
616

617 618
	// --- impl

619 620
	private createLogger(): Logger {
		return new Logger((severity, source, message) => {
621 622 623 624 625
			if (this._isDev && source) {
				this._logOrShowMessage(severity, `[${source}]: ${message}`);
			} else {
				this._logOrShowMessage(severity, message);
			}
626 627 628
		});
	}

A
Alex Dima 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
	private async _resolveAuthorityAgain(): Promise<void> {
		const remoteAuthority = this._environmentService.configuration.remoteAuthority;
		if (!remoteAuthority) {
			return;
		}

		const extensionHost = this._extensionHostProcessManagers[0];
		this._remoteAuthorityResolverService.clearResolvedAuthority(remoteAuthority);
		try {
			const resolvedAuthority = await extensionHost.resolveAuthority(remoteAuthority);
			this._remoteAuthorityResolverService.setResolvedAuthority(resolvedAuthority);
		} catch (err) {
			this._remoteAuthorityResolverService.setResolvedAuthorityError(remoteAuthority, err);
		}
	}

645 646
	private async _scanAndHandleExtensions(): Promise<void> {
		this._extensionScanner.startScanningExtensions(this.createLogger());
647

A
Alex Dima 已提交
648
		const remoteAuthority = this._environmentService.configuration.remoteAuthority;
A
Alex Dima 已提交
649
		const extensionHost = this._extensionHostProcessManagers[0];
A
Alex Dima 已提交
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734

		let localExtensions = await this._extensionScanner.scannedExtensions;

		if (remoteAuthority) {
			let resolvedAuthority: ResolvedAuthority;

			try {
				resolvedAuthority = await extensionHost.resolveAuthority(remoteAuthority);
			} catch (err) {
				console.error(err);
				const plusIndex = remoteAuthority.indexOf('+');
				const authorityFriendlyName = plusIndex > 0 ? remoteAuthority.substr(0, plusIndex) : remoteAuthority;
				if (!RemoteAuthorityResolverError.isHandledNotAvailable(err)) {
					this._notificationService.notify({ severity: Severity.Error, message: nls.localize('resolveAuthorityFailure', "Resolving the authority `{0}` failed", authorityFriendlyName) });
				} else {
					console.log(`Not showing a notification for the error`);
				}

				this._remoteAuthorityResolverService.setResolvedAuthorityError(remoteAuthority, err);

				// Proceed with the local extension host
				await this._startLocalExtensionHost(extensionHost, localExtensions);
				return;
			}

			// set the resolved authority
			this._remoteAuthorityResolverService.setResolvedAuthority(resolvedAuthority);

			// monitor for breakage
			const connection = this._remoteAgentService.getConnection();
			if (connection) {
				connection.onDidStateChange(async (e) => {
					const remoteAuthority = this._environmentService.configuration.remoteAuthority;
					if (!remoteAuthority) {
						return;
					}
					if (e.type === PersistenConnectionEventType.ConnectionLost) {
						this._remoteAuthorityResolverService.clearResolvedAuthority(remoteAuthority);
					}
				});
				connection.onReconnecting(() => this._resolveAuthorityAgain());
			}

			// fetch the remote environment
			const remoteEnv = (await this._remoteAgentService.getEnvironment())!;

			// revive URIs
			remoteEnv.extensions.forEach((extension) => {
				(<any>extension).extensionLocation = URI.revive(extension.extensionLocation);
			});

			// remove UI extensions from the remote extensions
			remoteEnv.extensions = remoteEnv.extensions.filter(extension => !isUIExtension(extension, this._configurationService));

			// remove non-UI extensions from the local extensions
			localExtensions = localExtensions.filter(extension => extension.isBuiltin || isUIExtension(extension, this._configurationService));

			// in case of overlap, the remote wins
			const isRemoteExtension = new Set<string>();
			remoteEnv.extensions.forEach(extension => isRemoteExtension.add(ExtensionIdentifier.toKey(extension.identifier)));
			localExtensions = localExtensions.filter(extension => !isRemoteExtension.has(ExtensionIdentifier.toKey(extension.identifier)));

			// compute enabled extensions
			const enabledExtensions = await this._getRuntimeExtensions((<IExtensionDescription[]>[]).concat(remoteEnv.extensions).concat(localExtensions));

			// remove disabled extensions
			const isEnabled = new Set<string>();
			enabledExtensions.forEach(extension => isEnabled.add(ExtensionIdentifier.toKey(extension.identifier)));
			remoteEnv.extensions = remoteEnv.extensions.filter(extension => isEnabled.has(ExtensionIdentifier.toKey(extension.identifier)));
			localExtensions = localExtensions.filter(extension => isEnabled.has(ExtensionIdentifier.toKey(extension.identifier)));

			// save for remote extension's init data
			this._remoteExtensionsEnvironmentData.set(remoteAuthority, remoteEnv);

			this._handleExtensionPoints(enabledExtensions);
			extensionHost.start(localExtensions.map(extension => extension.identifier));
			this._releaseBarrier();

		} else {
			await this._startLocalExtensionHost(extensionHost, localExtensions);
		}
	}

	private async _startLocalExtensionHost(extensionHost: ExtensionHostProcessManager, localExtensions: IExtensionDescription[]): Promise<void> {
		const enabledExtensions = await this._getRuntimeExtensions(localExtensions);
735 736

		this._handleExtensionPoints(enabledExtensions);
737
		extensionHost.start(enabledExtensions.map(extension => extension.identifier).filter(id => this._registry.containsExtension(id)));
738
		this._releaseBarrier();
A
Alex Dima 已提交
739
	}
S
Sandeep Somavarapu 已提交
740

741
	private _handleExtensionPoints(allExtensions: IExtensionDescription[]): void {
742 743 744 745
		const result = this._registry.deltaExtensions(allExtensions, []);
		if (result.removedDueToLooping.length > 0) {
			this._logOrShowMessage(Severity.Error, nls.localize('looping', "The following extensions contain dependency loops and have been disabled: {0}", result.removedDueToLooping.map(e => `'${e.identifier.value}'`).join(', ')));
		}
S
Sandeep Somavarapu 已提交
746

A
Alex Dima 已提交
747 748
		let availableExtensions = this._registry.getAllExtensionDescriptions();
		let extensionPoints = ExtensionsRegistry.getExtensionPoints();
S
Sandeep Somavarapu 已提交
749

A
Alex Dima 已提交
750 751 752 753 754
		let messageHandler = (msg: IMessage) => this._handleExtensionPointMessage(msg);

		for (let i = 0, len = extensionPoints.length; i < len; i++) {
			ExtensionService._handleExtensionPoint(extensionPoints[i], availableExtensions, messageHandler);
		}
755
	}
756

757
	private _releaseBarrier(): void {
A
Alex Dima 已提交
758 759
		perf.mark('extensionHostReady');
		this._installedExtensionsReady.open();
R
Rob Lourens 已提交
760
		this._onDidRegisterExtensions.fire(undefined);
761
		this._onDidChangeExtensionsStatus.fire(this._registry.getAllExtensionDescriptions().map(e => e.identifier));
S
Sandeep Somavarapu 已提交
762
	}
763

764 765
	private isExtensionUnderDevelopment(extension: IExtensionDescription): boolean {
		if (this._environmentService.isExtensionDevelopment) {
766 767 768 769
			const extDevLocs = this._environmentService.extensionDevelopmentLocationURI;
			if (extDevLocs) {
				const extLocation = extension.extensionLocation;
				for (let p of extDevLocs) {
770 771 772 773 774 775 776 777 778
					if (isEqualOrParent(extLocation, p)) {
						return true;
					}
				}
			}
		}
		return false;
	}

S
Sandeep Somavarapu 已提交
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
	private async _getRuntimeExtensions(allExtensions: IExtensionDescription[]): Promise<IExtensionDescription[]> {

		const runtimeExtensions: IExtensionDescription[] = [];
		const extensionsToDisable: IExtensionDescription[] = [];
		const userMigratedSystemExtensions: IExtensionIdentifier[] = [{ id: BetterMergeId }];

		let enableProposedApiFor: string | string[] = this._environmentService.args['enable-proposed-api'] || [];

		const notFound = (id: string) => nls.localize('notFound', "Extension \`{0}\` cannot use PROPOSED API as it cannot be found", id);

		if (enableProposedApiFor.length) {
			let allProposed = (enableProposedApiFor instanceof Array ? enableProposedApiFor : [enableProposedApiFor]);
			allProposed.forEach(id => {
				if (!allExtensions.some(description => ExtensionIdentifier.equals(description.identifier, id))) {
					console.error(notFound(id));
794
				}
S
Sandeep Somavarapu 已提交
795 796 797 798 799 800 801 802
			});
			// Make enabled proposed API be lowercase for case insensitive comparison
			if (Array.isArray(enableProposedApiFor)) {
				enableProposedApiFor = enableProposedApiFor.map(id => id.toLowerCase());
			} else {
				enableProposedApiFor = enableProposedApiFor.toLowerCase();
			}
		}
803

S
Sandeep Somavarapu 已提交
804 805 806
		const enableProposedApiForAll = !this._environmentService.isBuilt ||
			(!!this._environmentService.extensionDevelopmentLocationURI && product.nameLong !== 'Visual Studio Code') ||
			(enableProposedApiFor.length === 0 && 'enable-proposed-api' in this._environmentService.args);
807

808

S
Sandeep Somavarapu 已提交
809
		for (const extension of allExtensions) {
810

S
Sandeep Somavarapu 已提交
811 812 813 814 815 816
			// Do not disable extensions under development
			if (!this.isExtensionUnderDevelopment(extension)) {
				if (!this._extensionEnablementService.isEnabled(toExtension(extension))) {
					continue;
				}
			}
817

S
Sandeep Somavarapu 已提交
818 819 820 821 822 823
			if (!extension.isBuiltin) {
				// Check if the extension is changed to system extension
				const userMigratedSystemExtension = userMigratedSystemExtensions.filter(userMigratedSystemExtension => areSameExtensions(userMigratedSystemExtension, { id: extension.identifier.value }))[0];
				if (userMigratedSystemExtension) {
					extensionsToDisable.push(extension);
					continue;
824
				}
S
Sandeep Somavarapu 已提交
825 826 827
			}
			runtimeExtensions.push(this._updateEnableProposedApi(extension, enableProposedApiForAll, enableProposedApiFor));
		}
828

S
Sandeep Somavarapu 已提交
829 830 831 832
		this._telemetryService.publicLog('extensionsScanned', {
			totalCount: runtimeExtensions.length,
			disabledCount: allExtensions.length - runtimeExtensions.length
		});
833

S
Sandeep Somavarapu 已提交
834 835 836 837 838 839
		if (extensionsToDisable.length) {
			return this._extensionEnablementService.setEnablement(extensionsToDisable.map(e => toExtension(e)), EnablementState.Disabled)
				.then(() => runtimeExtensions);
		} else {
			return runtimeExtensions;
		}
840 841
	}

842
	private _updateEnableProposedApi(extension: IExtensionDescription, enableProposedApiForAll: boolean, enableProposedApiFor: string | string[]): IExtensionDescription {
843
		if (allowProposedApiFromProduct(extension.identifier)) {
844 845 846 847 848 849 850
			// fast lane -> proposed api is available to all extensions
			// that are listed in product.json-files
			extension.enableProposedApi = true;

		} else if (extension.enableProposedApi && !extension.isBuiltin) {
			if (
				!enableProposedApiForAll &&
851
				enableProposedApiFor.indexOf(extension.identifier.value.toLowerCase()) < 0
852
			) {
853
				extension.enableProposedApi = false;
854
				console.error(`Extension '${extension.identifier.value} cannot use PROPOSED API (must started out of dev or enabled via --enable-proposed-api)`);
855

856 857 858
			} else {
				// proposed api is available when developing or when an extension was explicitly
				// spelled out via a command line argument
859
				console.warn(`Extension '${extension.identifier.value}' uses PROPOSED API which is subject to change and removal without notice.`);
860 861
			}
		}
862
		return extension;
863 864
	}

865
	private _handleExtensionPointMessage(msg: IMessage) {
866
		const extensionKey = ExtensionIdentifier.toKey(msg.extensionId);
867

868 869
		if (!this._extensionsMessages.has(extensionKey)) {
			this._extensionsMessages.set(extensionKey, []);
870
		}
A
Alex Dima 已提交
871
		this._extensionsMessages.get(extensionKey)!.push(msg);
872

A
Alex Dima 已提交
873
		const extension = this._registry.getExtensionDescription(msg.extensionId);
874
		const strMsg = `[${msg.extensionId.value}]: ${msg.message}`;
A
Alex Dima 已提交
875
		if (extension && extension.isUnderDevelopment) {
876
			// This message is about the extension currently being developed
A
Alex Dima 已提交
877
			this._showMessageToUser(msg.type, strMsg);
878
		} else {
A
Alex Dima 已提交
879
			this._logMessageInConsole(msg.type, strMsg);
880 881 882 883
		}

		if (!this._isDev && msg.extensionId) {
			const { type, extensionId, extensionPointId, message } = msg;
K
kieferrm 已提交
884
			/* __GDPR__
K
kieferrm 已提交
885
				"extensionsMessage" : {
R
Ramya Achutha Rao 已提交
886
					"type" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true },
K
kieferrm 已提交
887 888 889 890 891
					"extensionId": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
					"extensionPointId": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
					"message": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
				}
			*/
892
			this._telemetryService.publicLog('extensionsMessage', {
893
				type, extensionId: extensionId.value, extensionPointId, message
894 895 896 897 898
			});
		}
	}

	private static _handleExtensionPoint<T>(extensionPoint: ExtensionPoint<T>, availableExtensions: IExtensionDescription[], messageHandler: (msg: IMessage) => void): void {
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
		let users: IExtensionPointUser<T>[] = [], usersLen = 0;
		for (let i = 0, len = availableExtensions.length; i < len; i++) {
			let desc = availableExtensions[i];

			if (desc.contributes && hasOwnProperty.call(desc.contributes, extensionPoint.name)) {
				users[usersLen++] = {
					description: desc,
					value: desc.contributes[extensionPoint.name],
					collector: new ExtensionMessageCollector(messageHandler, desc, extensionPoint.name)
				};
			}
		}

		extensionPoint.acceptUsers(users);
	}

915 916
	private _showMessageToUser(severity: Severity, msg: string): void {
		if (severity === Severity.Error || severity === Severity.Warning) {
917
			this._notificationService.notify({ severity, message: msg });
918 919 920 921 922 923 924
		} else {
			this._logMessageInConsole(severity, msg);
		}
	}

	private _logMessageInConsole(severity: Severity, msg: string): void {
		if (severity === Severity.Error) {
925 926 927 928 929 930
			console.error(msg);
		} else if (severity === Severity.Warning) {
			console.warn(msg);
		} else {
			console.log(msg);
		}
931
	}
932 933 934 935 936 937 938 939 940 941

	// -- called by extension host

	public _logOrShowMessage(severity: Severity, msg: string): void {
		if (this._isDev) {
			this._showMessageToUser(severity, msg);
		} else {
			this._logMessageInConsole(severity, msg);
		}
	}
942

943 944 945 946 947 948 949 950 951 952
	public async _activateById(extensionId: ExtensionIdentifier, activationEvent: string): Promise<void> {
		const results = await Promise.all(
			this._extensionHostProcessManagers.map(manager => manager.activate(extensionId, activationEvent))
		);
		const activated = results.some(e => e);
		if (!activated) {
			throw new Error(`Unknown extension ${extensionId.value}`);
		}
	}

953 954
	public _onWillActivateExtension(extensionId: ExtensionIdentifier): void {
		this._extensionHostActiveExtensions.set(ExtensionIdentifier.toKey(extensionId), extensionId);
A
Alex Dima 已提交
955 956
	}

957 958
	public _onDidActivateExtension(extensionId: ExtensionIdentifier, startup: boolean, codeLoadingTime: number, activateCallTime: number, activateResolvedTime: number, activationEvent: string): void {
		this._extensionHostProcessActivationTimes.set(ExtensionIdentifier.toKey(extensionId), new ActivationTimes(startup, codeLoadingTime, activateCallTime, activateResolvedTime, activationEvent));
A
Alex Dima 已提交
959
		this._onDidChangeExtensionsStatus.fire([extensionId]);
960
	}
A
Alex Dima 已提交
961

962 963
	public _onExtensionRuntimeError(extensionId: ExtensionIdentifier, err: Error): void {
		const extensionKey = ExtensionIdentifier.toKey(extensionId);
964 965
		if (!this._extensionHostExtensionRuntimeErrors.has(extensionKey)) {
			this._extensionHostExtensionRuntimeErrors.set(extensionKey, []);
966
		}
A
Alex Dima 已提交
967
		this._extensionHostExtensionRuntimeErrors.get(extensionKey)!.push(err);
A
Alex Dima 已提交
968 969
		this._onDidChangeExtensionsStatus.fire([extensionId]);
	}
A
Alex Dima 已提交
970 971

	public _onExtensionHostExit(code: number): void {
972 973 974 975 976 977 978 979 980 981
		// Expected development extension termination: When the extension host goes down we also shutdown the window
		const devOpts = parseExtensionDevOptions(this._environmentService);
		if (!devOpts.isExtensionDevTestFromCli) {
			this._windowService.closeWindow();
		}

		// When CLI testing make sure to exit with proper exit code
		else {
			ipc.send('vscode:exit', code);
		}
A
Alex Dima 已提交
982
	}
983
}
984

985
registerSingleton(IExtensionService, ExtensionService);