extHost.api.impl.ts 39.4 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

7
import { Emitter } from 'vs/base/common/event';
8
import { TernarySearchTree } from 'vs/base/common/map';
J
Johannes Rieken 已提交
9
import { score } from 'vs/editor/common/modes/languageSelector';
10
import * as Platform from 'vs/base/common/platform';
E
Erich Gamma 已提交
11
import * as errors from 'vs/base/common/errors';
12 13
import product from 'vs/platform/node/product';
import pkg from 'vs/platform/node/package';
J
Johannes Rieken 已提交
14
import { ExtHostFileSystemEventService } from 'vs/workbench/api/node/extHostFileSystemEventService';
J
Johannes Rieken 已提交
15
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
J
Johannes Rieken 已提交
16
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
17
import { ExtHostDocumentContentProvider } from 'vs/workbench/api/node/extHostDocumentContentProviders';
J
Johannes Rieken 已提交
18 19 20
import { ExtHostDocumentSaveParticipant } from 'vs/workbench/api/node/extHostDocumentSaveParticipant';
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
S
Sandeep Somavarapu 已提交
21
import { ExtHostTreeViews } from 'vs/workbench/api/node/extHostTreeViews';
J
Johannes Rieken 已提交
22 23
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostQuickOpen } from 'vs/workbench/api/node/extHostQuickOpen';
24
import { ExtHostProgress } from 'vs/workbench/api/node/extHostProgress';
J
Joao Moreno 已提交
25
import { ExtHostSCM } from 'vs/workbench/api/node/extHostSCM';
J
Johannes Rieken 已提交
26 27 28 29 30 31
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
import { ExtHostStatusBar } from 'vs/workbench/api/node/extHostStatusBar';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
import { ExtHostOutputService } from 'vs/workbench/api/node/extHostOutputService';
import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalService';
import { ExtHostMessageService } from 'vs/workbench/api/node/extHostMessageService';
J
Johannes Rieken 已提交
32
import { ExtHostEditors } from 'vs/workbench/api/node/extHostTextEditors';
J
Johannes Rieken 已提交
33 34
import { ExtHostLanguages } from 'vs/workbench/api/node/extHostLanguages';
import { ExtHostLanguageFeatures } from 'vs/workbench/api/node/extHostLanguageFeatures';
35
import { ExtHostApiCommands } from 'vs/workbench/api/node/extHostApiCommands';
36
import { ExtHostTask } from 'vs/workbench/api/node/extHostTask';
37
import { ExtHostDebugService } from 'vs/workbench/api/node/extHostDebugService';
38
import { ExtHostWindow } from 'vs/workbench/api/node/extHostWindow';
J
Johannes Rieken 已提交
39
import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
E
Erich Gamma 已提交
40 41
import URI from 'vs/base/common/uri';
import Severity from 'vs/base/common/severity';
42
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
J
Johannes Rieken 已提交
43 44 45
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
import { TPromise } from 'vs/base/common/winjs.base';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
46
import * as vscode from 'vscode';
E
Erich Gamma 已提交
47
import * as paths from 'vs/base/common/paths';
48
import { MainContext, ExtHostContext, IInitData, IExtHostContext } from './extHost.protocol';
49
import * as languageConfiguration from 'vs/editor/common/modes/languageConfiguration';
50
import { TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions';
A
Alex Dima 已提交
51
import { ProxyIdentifier } from 'vs/workbench/services/extensions/node/proxyIdentifier';
B
Benjamin Pasero 已提交
52
import { ExtHostDialogs } from 'vs/workbench/api/node/extHostDialogs';
53
import { ExtHostFileSystem } from 'vs/workbench/api/node/extHostFileSystem';
54
import { ExtHostDecorations } from 'vs/workbench/api/node/extHostDecorations';
55
import { toGlobPattern, toLanguageSelector } from 'vs/workbench/api/node/extHostTypeConverters';
A
Alex Dima 已提交
56
import { ExtensionActivatedByAPI } from 'vs/workbench/api/node/extHostExtensionActivator';
57
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
A
Alex Dima 已提交
58
import { OverviewRulerLane } from 'vs/editor/common/model';
59
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
M
Matt Bierner 已提交
60
import { ExtHostWebviews } from 'vs/workbench/api/node/extHostWebview';
E
Erich Gamma 已提交
61

62
export interface IExtensionApiFactory {
63
	(extension: IExtensionDescription): typeof vscode;
64 65
}

66 67 68 69 70 71 72 73 74 75
export function checkProposedApiEnabled(extension: IExtensionDescription): void {
	if (!extension.enableProposedApi) {
		throwProposedApiError(extension);
	}
}

function throwProposedApiError(extension: IExtensionDescription): never {
	throw new Error(`[${extension.id}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${extension.id}`);
}

76
function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
77
	if (extension.enableProposedApi) {
78 79
		return fn;
	} else {
80
		return <any>throwProposedApiError;
81 82 83
	}
}

E
Erich Gamma 已提交
84
/**
85
 * This method instantiates and returns the extension API surface
E
Erich Gamma 已提交
86
 */
87 88
export function createApiFactory(
	initData: IInitData,
A
Alex Dima 已提交
89
	rpcProtocol: IExtHostContext,
90 91
	extHostWorkspace: ExtHostWorkspace,
	extHostConfiguration: ExtHostConfiguration,
J
Joao Moreno 已提交
92
	extensionService: ExtHostExtensionService,
93
	extHostLogService: ExtHostLogService
94
): IExtensionApiFactory {
95

96
	// Addressable instances
97
	rpcProtocol.set(ExtHostContext.ExtHostLogService, extHostLogService);
A
Alex Dima 已提交
98 99
	const extHostHeapService = rpcProtocol.set(ExtHostContext.ExtHostHeapService, new ExtHostHeapService());
	const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, new ExtHostDecorations(rpcProtocol));
M
Matt Bierner 已提交
100
	const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol));
101
	const extHostDocumentsAndEditors = rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, new ExtHostDocumentsAndEditors(rpcProtocol));
A
Alex Dima 已提交
102
	const extHostDocuments = rpcProtocol.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors));
103
	const extHostDocumentContentProviders = rpcProtocol.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(rpcProtocol, extHostDocumentsAndEditors, extHostLogService));
104
	const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostLogService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadTextEditors)));
A
Alex Dima 已提交
105
	const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(rpcProtocol, extHostDocumentsAndEditors));
106
	const extHostCommands = rpcProtocol.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(rpcProtocol, extHostHeapService, extHostLogService));
A
Alex Dima 已提交
107 108
	const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands));
	rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
109
	const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(rpcProtocol, extHostWorkspace, extensionService));
A
Alex Dima 已提交
110 111
	rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
	const extHostDiagnostics = rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(rpcProtocol));
112 113
	const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, extHostDocuments, extHostCommands, extHostHeapService, extHostDiagnostics));
	const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
A
Alex Dima 已提交
114 115 116
	const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService());
	const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands));
	const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(rpcProtocol));
117
	const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));
A
Alex Dima 已提交
118 119 120
	const extHostTask = rpcProtocol.set(ExtHostContext.ExtHostTask, new ExtHostTask(rpcProtocol, extHostWorkspace));
	const extHostWindow = rpcProtocol.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(rpcProtocol));
	rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
121
	const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
122 123 124

	// Check that no named customers are missing
	const expected: ProxyIdentifier<any>[] = Object.keys(ExtHostContext).map((key) => ExtHostContext[key]);
A
Alex Dima 已提交
125
	rpcProtocol.assertRegistered(expected);
126

127
	// Other instances
A
Alex Dima 已提交
128 129 130 131 132
	const extHostMessageService = new ExtHostMessageService(rpcProtocol);
	const extHostDialogs = new ExtHostDialogs(rpcProtocol);
	const extHostStatusBar = new ExtHostStatusBar(rpcProtocol);
	const extHostOutputService = new ExtHostOutputService(rpcProtocol);
	const extHostLanguages = new ExtHostLanguages(rpcProtocol);
133

134
	// Register API-ish commands
135
	ExtHostApiCommands.register(extHostCommands, extHostTask);
136

137
	return function (extension: IExtensionDescription): typeof vscode {
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
		// Check document selectors for being overly generic. Technically this isn't a problem but
		// in practice many extensions say they support `fooLang` but need fs-access to do so. Those
		// extension should specify then the `file`-scheme, e.g `{ scheme: 'fooLang', language: 'fooLang' }`
		// We only inform once, it is not a warning because we just want to raise awareness and because
		// we cannot say if the extension is doing it right or wrong...
		let checkSelector = (function () {
			let done = initData.environment.extensionDevelopmentPath !== extension.extensionFolderPath;
			function inform(selector: vscode.DocumentSelector) {
				console.info(`Extension '${extension.id}' uses a document selector that applies to all schemes.}`);
				done = true;
			}
			return function perform(selector: vscode.DocumentSelector): vscode.DocumentSelector {
				if (!done) {
					if (Array.isArray(selector)) {
						selector.forEach(perform);
					} else if (typeof selector === 'string') {
						inform(selector);
					} else if (typeof selector.scheme === 'undefined') {
						inform(selector);
					}
				}
				return selector;
			};
		})();

164 165 166 167 168 169
		if (!isFalsyOrEmpty(product.extensionAllowedProposedApi)
			&& product.extensionAllowedProposedApi.indexOf(extension.id) >= 0
		) {
			// fast lane -> proposed api is available to all extensions
			// that are listed in product.json-files
			extension.enableProposedApi = true;
170

171
		} else if (extension.enableProposedApi && !extension.isBuiltin) {
172 173 174 175
			if (
				!initData.environment.enableProposedApiForAll &&
				initData.environment.enableProposedApiFor.indexOf(extension.id) < 0
			) {
176
				extension.enableProposedApi = false;
177
				console.error(`Extension '${extension.id} cannot use PROPOSED API (must started out of dev or enabled via --enable-proposed-api)`);
178 179

			} else {
180 181 182
				// proposed api is available when developing or when an extension was explicitly
				// spelled out via a command line argument
				console.warn(`Extension '${extension.id}' uses PROPOSED API which is subject to change and removal without notice.`);
183
			}
184 185
		}

186 187
		// namespace: commands
		const commands: typeof vscode.commands = {
M
Matt Bierner 已提交
188
			registerCommand(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable {
189
				return extHostCommands.registerCommand(true, id, command, thisArgs);
190
			},
191
			registerTextEditorCommand(id: string, callback: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => void, thisArg?: any): vscode.Disposable {
192
				return extHostCommands.registerCommand(true, id, (...args: any[]): any => {
193 194 195
					let activeTextEditor = extHostEditors.getActiveTextEditor();
					if (!activeTextEditor) {
						console.warn('Cannot execute ' + id + ' because there is no active text editor.');
196
						return undefined;
197
					}
198 199 200 201 202 203 204 205 206 207

					return activeTextEditor.edit((edit: vscode.TextEditorEdit) => {
						args.unshift(activeTextEditor, edit);
						callback.apply(thisArg, args);

					}).then((result) => {
						if (!result) {
							console.warn('Edits from command ' + id + ' were not applied.');
						}
					}, (err) => {
208
						console.warn('An error occurred while running command ' + id, err);
209
					});
210
				});
211 212
			},
			registerDiffInformationCommand: proposedApiFunction(extension, (id: string, callback: (diff: vscode.LineChange[], ...args: any[]) => any, thisArg?: any): vscode.Disposable => {
213
				return extHostCommands.registerCommand(true, id, async (...args: any[]) => {
214 215 216 217 218 219 220 221 222
					let activeTextEditor = extHostEditors.getActiveTextEditor();
					if (!activeTextEditor) {
						console.warn('Cannot execute ' + id + ' because there is no active text editor.');
						return undefined;
					}

					const diff = await extHostEditors.getDiffInformation(activeTextEditor.id);
					callback.apply(thisArg, [diff, ...args]);
				});
223
			}),
224
			executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
225
				return extHostCommands.executeCommand<T>(id, ...args);
226
			},
227 228 229
			getCommands(filterInternal: boolean = false): Thenable<string[]> {
				return extHostCommands.getCommands(filterInternal);
			}
230
		};
231

232 233
		// namespace: env
		const env: typeof vscode.env = Object.freeze({
234 235
			get machineId() { return initData.telemetryInfo.machineId; },
			get sessionId() { return initData.telemetryInfo.sessionId; },
236
			get language() { return Platform.language; },
J
Johannes Rieken 已提交
237 238
			get appName() { return product.nameLong; },
			get appRoot() { return initData.environment.appRoot; },
M
Matt Bierner 已提交
239
			get logLevel() { return extHostLogService.getLevel(); }
240
		});
E
Erich Gamma 已提交
241

242 243 244
		// namespace: extensions
		const extensions: typeof vscode.extensions = {
			getExtension(extensionId: string): Extension<any> {
245
				let desc = extensionService.getExtensionDescription(extensionId);
246 247 248
				if (desc) {
					return new Extension(extensionService, desc);
				}
249
				return undefined;
250 251
			},
			get all(): Extension<any>[] {
252
				return extensionService.getAllExtensionDescriptions().map((desc) => new Extension(extensionService, desc));
E
Erich Gamma 已提交
253
			}
254
		};
E
Erich Gamma 已提交
255

256 257 258 259 260
		// namespace: languages
		const languages: typeof vscode.languages = {
			createDiagnosticCollection(name?: string): vscode.DiagnosticCollection {
				return extHostDiagnostics.createDiagnosticCollection(name);
			},
261 262 263 264
			get onDidChangeDiagnostics() {
				checkProposedApiEnabled(extension);
				return extHostDiagnostics.onDidChangeDiagnostics;
			},
265 266 267
			getDiagnostics: (resource?) => {
				return <any>extHostDiagnostics.getDiagnostics(resource);
			},
268 269 270 271
			getLanguages(): TPromise<string[]> {
				return extHostLanguages.getLanguages();
			},
			match(selector: vscode.DocumentSelector, document: vscode.TextDocument): number {
272
				return score(toLanguageSelector(selector), document.uri, document.languageId, true);
273
			},
274 275
			registerCodeActionsProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider, metadata?: vscode.CodeActionProviderMetadata): vscode.Disposable {
				return extHostLanguageFeatures.registerCodeActionProvider(checkSelector(selector), provider, metadata);
276 277
			},
			registerCodeLensProvider(selector: vscode.DocumentSelector, provider: vscode.CodeLensProvider): vscode.Disposable {
278
				return extHostLanguageFeatures.registerCodeLensProvider(checkSelector(selector), provider);
279 280
			},
			registerDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.DefinitionProvider): vscode.Disposable {
281
				return extHostLanguageFeatures.registerDefinitionProvider(checkSelector(selector), provider);
282
			},
M
Matt Bierner 已提交
283
			registerImplementationProvider(selector: vscode.DocumentSelector, provider: vscode.ImplementationProvider): vscode.Disposable {
284
				return extHostLanguageFeatures.registerImplementationProvider(checkSelector(selector), provider);
285
			},
286
			registerTypeDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.TypeDefinitionProvider): vscode.Disposable {
287
				return extHostLanguageFeatures.registerTypeDefinitionProvider(checkSelector(selector), provider);
288
			},
289
			registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider): vscode.Disposable {
290
				return extHostLanguageFeatures.registerHoverProvider(checkSelector(selector), provider, extension.id);
291 292
			},
			registerDocumentHighlightProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentHighlightProvider): vscode.Disposable {
293
				return extHostLanguageFeatures.registerDocumentHighlightProvider(checkSelector(selector), provider);
294 295
			},
			registerReferenceProvider(selector: vscode.DocumentSelector, provider: vscode.ReferenceProvider): vscode.Disposable {
296
				return extHostLanguageFeatures.registerReferenceProvider(checkSelector(selector), provider);
297 298
			},
			registerRenameProvider(selector: vscode.DocumentSelector, provider: vscode.RenameProvider): vscode.Disposable {
299
				return extHostLanguageFeatures.registerRenameProvider(checkSelector(selector), provider, extension.enableProposedApi);
300 301
			},
			registerDocumentSymbolProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentSymbolProvider): vscode.Disposable {
302
				return extHostLanguageFeatures.registerDocumentSymbolProvider(checkSelector(selector), provider);
303 304
			},
			registerWorkspaceSymbolProvider(provider: vscode.WorkspaceSymbolProvider): vscode.Disposable {
305
				return extHostLanguageFeatures.registerWorkspaceSymbolProvider(provider);
306 307
			},
			registerDocumentFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
308
				return extHostLanguageFeatures.registerDocumentFormattingEditProvider(checkSelector(selector), provider);
309 310
			},
			registerDocumentRangeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider): vscode.Disposable {
311
				return extHostLanguageFeatures.registerDocumentRangeFormattingEditProvider(checkSelector(selector), provider);
312 313
			},
			registerOnTypeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, firstTriggerCharacter: string, ...moreTriggerCharacters: string[]): vscode.Disposable {
314
				return extHostLanguageFeatures.registerOnTypeFormattingEditProvider(checkSelector(selector), provider, [firstTriggerCharacter].concat(moreTriggerCharacters));
315 316
			},
			registerSignatureHelpProvider(selector: vscode.DocumentSelector, provider: vscode.SignatureHelpProvider, ...triggerCharacters: string[]): vscode.Disposable {
317
				return extHostLanguageFeatures.registerSignatureHelpProvider(checkSelector(selector), provider, triggerCharacters);
318 319
			},
			registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, ...triggerCharacters: string[]): vscode.Disposable {
320
				return extHostLanguageFeatures.registerCompletionItemProvider(checkSelector(selector), provider, triggerCharacters);
321 322
			},
			registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
323
				return extHostLanguageFeatures.registerDocumentLinkProvider(checkSelector(selector), provider);
324
			},
325
			registerColorProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentColorProvider): vscode.Disposable {
326
				return extHostLanguageFeatures.registerColorProvider(checkSelector(selector), provider);
327
			},
328
			registerFoldingProvider: proposedApiFunction(extension, (selector: vscode.DocumentSelector, provider: vscode.FoldingProvider): vscode.Disposable => {
329
				return extHostLanguageFeatures.registerFoldingProvider(checkSelector(selector), provider);
330
			}),
331
			setLanguageConfiguration: (language: string, configuration: vscode.LanguageConfiguration): vscode.Disposable => {
332
				return extHostLanguageFeatures.setLanguageConfiguration(language, configuration);
333
			}
334
		};
E
Erich Gamma 已提交
335

336 337 338 339 340 341 342 343
		// namespace: window
		const window: typeof vscode.window = {
			get activeTextEditor() {
				return extHostEditors.getActiveTextEditor();
			},
			get visibleTextEditors() {
				return extHostEditors.getVisibleTextEditors();
			},
D
Daniel Imms 已提交
344 345 346
			get terminals() {
				return extHostTerminalService.terminals;
			},
J
Johannes Rieken 已提交
347
			showTextDocument(documentOrUri: vscode.TextDocument | vscode.Uri, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, preserveFocus?: boolean): TPromise<vscode.TextEditor> {
B
Benjamin Pasero 已提交
348
				let documentPromise: TPromise<vscode.TextDocument>;
J
Johannes Rieken 已提交
349 350
				if (URI.isUri(documentOrUri)) {
					documentPromise = TPromise.wrap(workspace.openTextDocument(documentOrUri));
B
Benjamin Pasero 已提交
351
				} else {
J
Johannes Rieken 已提交
352
					documentPromise = TPromise.wrap(<vscode.TextDocument>documentOrUri);
B
Benjamin Pasero 已提交
353 354 355 356
				}
				return documentPromise.then(document => {
					return extHostEditors.showTextDocument(document, columnOrOptions, preserveFocus);
				});
357 358 359 360
			},
			createTextEditorDecorationType(options: vscode.DecorationRenderOptions): vscode.TextEditorDecorationType {
				return extHostEditors.createTextEditorDecorationType(options);
			},
361 362 363
			onDidChangeActiveTextEditor(listener, thisArg?, disposables?) {
				return extHostEditors.onDidChangeActiveTextEditor(listener, thisArg, disposables);
			},
364 365 366
			onDidChangeVisibleTextEditors(listener, thisArg, disposables) {
				return extHostEditors.onDidChangeVisibleTextEditors(listener, thisArg, disposables);
			},
367
			onDidChangeTextEditorSelection(listener: (e: vscode.TextEditorSelectionChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
368 369
				return extHostEditors.onDidChangeTextEditorSelection(listener, thisArgs, disposables);
			},
370
			onDidChangeTextEditorOptions(listener: (e: vscode.TextEditorOptionsChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
371 372
				return extHostEditors.onDidChangeTextEditorOptions(listener, thisArgs, disposables);
			},
373
			onDidChangeTextEditorVisibleRanges(listener: (e: vscode.TextEditorVisibleRangesChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
374
				return extHostEditors.onDidChangeTextEditorVisibleRanges(listener, thisArgs, disposables);
375
			},
376 377 378
			onDidChangeTextEditorViewColumn(listener, thisArg?, disposables?) {
				return extHostEditors.onDidChangeTextEditorViewColumn(listener, thisArg, disposables);
			},
379 380 381
			onDidCloseTerminal(listener, thisArg?, disposables?) {
				return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables);
			},
382 383 384
			onDidOpenTerminal(listener, thisArg?, disposables?) {
				return extHostTerminalService.onDidOpenTerminal(listener, thisArg, disposables);
			},
J
Joao Moreno 已提交
385 386
			get state() {
				return extHostWindow.state;
387
			},
J
Joao Moreno 已提交
388
			onDidChangeWindowState(listener, thisArg?, disposables?) {
J
Joao Moreno 已提交
389
				return extHostWindow.onDidChangeWindowState(listener, thisArg, disposables);
J
Joao Moreno 已提交
390
			},
J
Joao Moreno 已提交
391
			showInformationMessage(message, first, ...rest) {
392
				return extHostMessageService.showMessage(extension, Severity.Info, message, first, rest);
393
			},
J
Joao Moreno 已提交
394
			showWarningMessage(message, first, ...rest) {
395
				return extHostMessageService.showMessage(extension, Severity.Warning, message, first, rest);
396
			},
J
Joao Moreno 已提交
397
			showErrorMessage(message, first, ...rest) {
398
				return extHostMessageService.showMessage(extension, Severity.Error, message, first, rest);
399
			},
C
Christof Marti 已提交
400
			showQuickPick(items: any, options: vscode.QuickPickOptions, token?: vscode.CancellationToken): any {
401 402
				return extHostQuickOpen.showQuickPick(items, options, token);
			},
403
			showWorkspaceFolderPick(options: vscode.WorkspaceFolderPickOptions) {
404
				return extHostQuickOpen.showWorkspaceFolderPick(options);
405
			},
406 407 408
			showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken) {
				return extHostQuickOpen.showInput(options, token);
			},
409 410 411 412 413 414
			showOpenDialog(options) {
				return extHostDialogs.showOpenDialog(options);
			},
			showSaveDialog(options) {
				return extHostDialogs.showSaveDialog(options);
			},
415
			createStatusBarItem(position?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem {
416
				return extHostStatusBar.createStatusBarEntry(extension.id, <number>position, priority);
417 418 419 420
			},
			setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): vscode.Disposable {
				return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable);
			},
421
			withScmProgress<R>(task: (progress: vscode.Progress<number>) => Thenable<R>) {
422
				console.warn(`[Deprecation Warning] function 'withScmProgress' is deprecated and should no longer be used. Use 'withProgress' instead.`);
423
				return extHostProgress.withProgress(extension, { location: extHostTypes.ProgressLocation.SourceControl }, (progress, token) => task({ report(n: number) { /*noop*/ } }));
J
Johannes Rieken 已提交
424
			},
425
			withProgress<R>(options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string; worked?: number }>, token: vscode.CancellationToken) => Thenable<R>) {
J
Johannes Rieken 已提交
426
				return extHostProgress.withProgress(extension, options, task);
427
			},
428 429 430
			createOutputChannel(name: string): vscode.OutputChannel {
				return extHostOutputService.createOutputChannel(name);
			},
431 432 433 434
			createTerminal(nameOrOptions: vscode.TerminalOptions | string, shellPath?: string, shellArgs?: string[]): vscode.Terminal {
				if (typeof nameOrOptions === 'object') {
					return extHostTerminalService.createTerminalFromOptions(<vscode.TerminalOptions>nameOrOptions);
				}
D
Daniel Imms 已提交
435
				return extHostTerminalService.createTerminal(<string>nameOrOptions, shellPath, shellArgs);
436
			},
437 438 439 440 441
			registerTreeDataProvider(viewId: string, treeDataProvider: vscode.TreeDataProvider<any>): vscode.Disposable {
				return extHostTreeViews.registerTreeDataProvider(viewId, treeDataProvider);
			},
			createTreeView(viewId: string, options: { treeDataProvider: vscode.TreeDataProvider<any> }): vscode.TreeView<any> {
				return extHostTreeViews.createTreeView(viewId, options);
S
Sandeep Somavarapu 已提交
442
			},
443 444
			// proposed API
			sampleFunction: proposedApiFunction(extension, () => {
445
				return extHostMessageService.showMessage(extension, Severity.Info, 'Hello Proposed Api!', {}, []);
446
			}),
447 448
			registerDecorationProvider: proposedApiFunction(extension, (provider: vscode.DecorationProvider) => {
				return extHostDecorations.registerDecorationProvider(provider, extension.id);
M
Matt Bierner 已提交
449
			}),
450
			createWebviewEditor: proposedApiFunction(extension, (viewType: string, title: string, column: vscode.ViewColumn, options: vscode.WebviewEditorOptions & vscode.WebviewOptions) => {
451
				return extHostWebviews.createWebview(viewType, title, column, options, extension.extensionFolderPath);
452
			}),
453 454
			registerWebviewEditorSerializer: proposedApiFunction(extension, (viewType: string, serializer: vscode.WebviewEditorSerializer) => {
				return extHostWebviews.registerWebviewEditorSerializer(viewType, serializer);
455
			})
456
		};
E
Erich Gamma 已提交
457

458 459 460 461 462 463 464 465
		// namespace: workspace
		const workspace: typeof vscode.workspace = {
			get rootPath() {
				return extHostWorkspace.getPath();
			},
			set rootPath(value) {
				throw errors.readonly();
			},
466 467
			getWorkspaceFolder(resource) {
				return extHostWorkspace.getWorkspaceFolder(resource);
468
			},
469
			get workspaceFolders() {
470
				return extHostWorkspace.getWorkspaceFolders();
471
			},
472 473 474 475 476 477
			get name() {
				return extHostWorkspace.workspace ? extHostWorkspace.workspace.name : undefined;
			},
			set name(value) {
				throw errors.readonly();
			},
478 479 480
			updateWorkspaceFolders: (index, deleteCount, ...workspaceFoldersToAdd) => {
				return extHostWorkspace.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
			},
481
			onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
482
				return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
483
			},
J
Johannes Rieken 已提交
484 485
			asRelativePath: (pathOrUri, includeWorkspace) => {
				return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
486 487
			},
			findFiles: (include, exclude, maxResults?, token?) => {
488
				return extHostWorkspace.findFiles(toGlobPattern(include), toGlobPattern(exclude), maxResults, extension.id, token);
489 490 491 492 493
			},
			saveAll: (includeUntitled?) => {
				return extHostWorkspace.saveAll(includeUntitled);
			},
			applyEdit(edit: vscode.WorkspaceEdit): TPromise<boolean> {
494
				return extHostEditors.applyWorkspaceEdit(edit);
495 496
			},
			createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
497
				return extHostFileSystemEvent.createFileSystemWatcher(toGlobPattern(pattern), ignoreCreate, ignoreChange, ignoreDelete);
498 499 500 501 502 503 504
			},
			get textDocuments() {
				return extHostDocuments.getAllDocumentData().map(data => data.document);
			},
			set textDocuments(value) {
				throw errors.readonly();
			},
505
			openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) {
B
Benjamin Pasero 已提交
506 507
				let uriPromise: TPromise<URI>;

508
				let options = uriOrFileNameOrOptions as { language?: string; content?: string; };
B
Benjamin Pasero 已提交
509
				if (typeof uriOrFileNameOrOptions === 'string') {
B
Benjamin Pasero 已提交
510 511
					uriPromise = TPromise.as(URI.file(uriOrFileNameOrOptions));
				} else if (uriOrFileNameOrOptions instanceof URI) {
J
Johannes Rieken 已提交
512
					uriPromise = TPromise.as(uriOrFileNameOrOptions);
B
Benjamin Pasero 已提交
513 514
				} else if (!options || typeof options === 'object') {
					uriPromise = extHostDocuments.createDocumentData(options);
515
				} else {
B
Benjamin Pasero 已提交
516
					throw new Error('illegal argument - uriOrFileNameOrOptions');
517
				}
B
Benjamin Pasero 已提交
518 519 520 521 522 523

				return uriPromise.then(uri => {
					return extHostDocuments.ensureDocumentData(uri).then(() => {
						const data = extHostDocuments.getDocumentData(uri);
						return data && data.document;
					});
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
				});
			},
			onDidOpenTextDocument: (listener, thisArgs?, disposables?) => {
				return extHostDocuments.onDidAddDocument(listener, thisArgs, disposables);
			},
			onDidCloseTextDocument: (listener, thisArgs?, disposables?) => {
				return extHostDocuments.onDidRemoveDocument(listener, thisArgs, disposables);
			},
			onDidChangeTextDocument: (listener, thisArgs?, disposables?) => {
				return extHostDocuments.onDidChangeDocument(listener, thisArgs, disposables);
			},
			onDidSaveTextDocument: (listener, thisArgs?, disposables?) => {
				return extHostDocuments.onDidSaveDocument(listener, thisArgs, disposables);
			},
			onWillSaveTextDocument: (listener, thisArgs?, disposables?) => {
539
				return extHostDocumentSaveParticipant.getOnWillSaveTextDocumentEvent(extension)(listener, thisArgs, disposables);
540
			},
541
			onDidChangeConfiguration: (listener: (_: any) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
542 543
				return extHostConfiguration.onDidChangeConfiguration(listener, thisArgs, disposables);
			},
544 545
			getConfiguration(section?: string, resource?: vscode.Uri): vscode.WorkspaceConfiguration {
				resource = arguments.length === 1 ? void 0 : resource;
S
Sandeep Somavarapu 已提交
546
				return extHostConfiguration.getConfiguration(section, resource, extension.id);
547
			},
548 549
			registerTextDocumentContentProvider(scheme: string, provider: vscode.TextDocumentContentProvider) {
				return extHostDocumentContentProviders.registerTextDocumentContentProvider(scheme, provider);
550
			},
551
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
552
				return extHostTask.registerTaskProvider(extension, provider);
J
Johannes Rieken 已提交
553
			},
554
			fetchTasks: proposedApiFunction(extension, (): Thenable<vscode.Task[]> => {
555
				return extHostTask.executeTaskProvider();
556 557
			}),
			executeTask: proposedApiFunction(extension, (task: vscode.Task): Thenable<vscode.TaskExecution> => {
558
				return extHostTask.executeTask(extension, task);
559
			}),
560 561 562 563 564 565
			onDidStartTask: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidStartTask(listeners, thisArgs, disposables);
			},
			onDidEndTask: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidEndTask(listeners, thisArgs, disposables);
			},
566 567
			registerFileSystemProvider: proposedApiFunction(extension, (scheme, provider, newProvider?) => {
				return extHostFileSystem.registerFileSystemProvider(scheme, provider, newProvider);
568 569 570
			}),
			registerSearchProvider: proposedApiFunction(extension, (scheme, provider) => {
				return extHostFileSystem.registerSearchProvider(scheme, provider);
J
Johannes Rieken 已提交
571
			})
572
		};
573

574 575
		// namespace: scm
		const scm: typeof vscode.scm = {
576
			get inputBox() {
J
Joao Moreno 已提交
577
				return extHostSCM.getLastInputBox(extension);
578
			},
J
Joao Moreno 已提交
579 580
			createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
				return extHostSCM.createSourceControl(extension, id, label, rootUri);
J
Joao Moreno 已提交
581
			}
582
		};
J
Joao Moreno 已提交
583

584 585
		// namespace: debug
		const debug: typeof vscode.debug = {
586 587 588
			get activeDebugSession() {
				return extHostDebugService.activeDebugSession;
			},
589 590
			get activeDebugConsole() {
				return extHostDebugService.activeDebugConsole;
591
			},
592 593
			get breakpoints() {
				return extHostDebugService.breakpoints;
594
			},
595 596 597
			onDidStartDebugSession(listener, thisArg?, disposables?) {
				return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
			},
598
			onDidTerminateDebugSession(listener, thisArg?, disposables?) {
599
				return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
600
			},
A
Andre Weinand 已提交
601
			onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
602
				return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
A
Andre Weinand 已提交
603 604
			},
			onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
A
Andre Weinand 已提交
605
				return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
606
			},
607
			onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
608 609
				return extHostDebugService.onDidChangeBreakpoints(listener, thisArgs, disposables);
			},
A
Andre Weinand 已提交
610
			registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) {
611
				return extHostDebugService.registerDebugConfigurationProvider(debugType, provider);
612
			},
613 614 615 616
			startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration) {
				return extHostDebugService.startDebugging(folder, nameOrConfig);
			},
			addBreakpoints(breakpoints: vscode.Breakpoint[]) {
617
				return extHostDebugService.addBreakpoints(breakpoints);
618 619
			},
			removeBreakpoints(breakpoints: vscode.Breakpoint[]) {
620
				return extHostDebugService.removeBreakpoints(breakpoints);
621
			}
622 623 624
		};


625
		return <typeof vscode>{
626 627 628 629 630 631 632 633
			version: pkg.version,
			// namespaces
			commands,
			env,
			extensions,
			languages,
			window,
			workspace,
J
Joao Moreno 已提交
634
			scm,
635
			debug,
636
			// types
637
			Breakpoint: extHostTypes.Breakpoint,
638
			CancellationTokenSource: CancellationTokenSource,
639
			CodeAction: extHostTypes.CodeAction,
M
Matt Bierner 已提交
640
			CodeActionKind: extHostTypes.CodeActionKind,
641
			CodeLens: extHostTypes.CodeLens,
642
			Color: extHostTypes.Color,
643 644
			ColorPresentation: extHostTypes.ColorPresentation,
			ColorInformation: extHostTypes.ColorInformation,
645
			EndOfLine: extHostTypes.EndOfLine,
646 647 648
			CompletionItem: extHostTypes.CompletionItem,
			CompletionItemKind: extHostTypes.CompletionItemKind,
			CompletionList: extHostTypes.CompletionList,
M
Matt Bierner 已提交
649
			CompletionTriggerKind: extHostTypes.CompletionTriggerKind,
650
			DebugAdapterExecutable: extHostTypes.DebugAdapterExecutable,
651
			Diagnostic: extHostTypes.Diagnostic,
652
			DiagnosticRelatedInformation: extHostTypes.DiagnosticRelatedInformation,
653 654 655 656
			DiagnosticSeverity: extHostTypes.DiagnosticSeverity,
			Disposable: extHostTypes.Disposable,
			DocumentHighlight: extHostTypes.DocumentHighlight,
			DocumentHighlightKind: extHostTypes.DocumentHighlightKind,
657
			DocumentLink: extHostTypes.DocumentLink,
658
			EventEmitter: Emitter,
659
			FunctionBreakpoint: extHostTypes.FunctionBreakpoint,
660
			Hover: extHostTypes.Hover,
661
			IndentAction: languageConfiguration.IndentAction,
662
			Location: extHostTypes.Location,
663
			LogLevel: extHostTypes.LogLevel,
664
			MarkdownString: extHostTypes.MarkdownString,
665
			OverviewRulerLane: OverviewRulerLane,
666 667 668 669 670 671 672
			ParameterInformation: extHostTypes.ParameterInformation,
			Position: extHostTypes.Position,
			Range: extHostTypes.Range,
			Selection: extHostTypes.Selection,
			SignatureHelp: extHostTypes.SignatureHelp,
			SignatureInformation: extHostTypes.SignatureInformation,
			SnippetString: extHostTypes.SnippetString,
673
			SourceBreakpoint: extHostTypes.SourceBreakpoint,
674 675 676
			StatusBarAlignment: extHostTypes.StatusBarAlignment,
			SymbolInformation: extHostTypes.SymbolInformation,
			SymbolKind: extHostTypes.SymbolKind,
677
			SourceControlInputBoxValidationType: extHostTypes.SourceControlInputBoxValidationType,
678 679
			TextDocumentSaveReason: extHostTypes.TextDocumentSaveReason,
			TextEdit: extHostTypes.TextEdit,
680
			TextEditorCursorStyle: TextEditorCursorStyle,
681
			TextEditorLineNumbersStyle: extHostTypes.TextEditorLineNumbersStyle,
682
			TextEditorRevealType: extHostTypes.TextEditorRevealType,
683
			TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind,
684
			DecorationRangeBehavior: extHostTypes.DecorationRangeBehavior,
685
			Uri: URI,
686 687
			ViewColumn: extHostTypes.ViewColumn,
			WorkspaceEdit: extHostTypes.WorkspaceEdit,
J
Johannes Rieken 已提交
688
			ProgressLocation: extHostTypes.ProgressLocation,
S
Sandeep Somavarapu 已提交
689
			TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState,
690
			ThemeIcon: extHostTypes.ThemeIcon,
S
Sandeep Somavarapu 已提交
691
			TreeItem: extHostTypes.TreeItem,
692
			ThemeColor: extHostTypes.ThemeColor,
J
Joao Moreno 已提交
693
			// functions
694
			TaskRevealKind: extHostTypes.TaskRevealKind,
695
			TaskPanelKind: extHostTypes.TaskPanelKind,
696
			TaskGroup: extHostTypes.TaskGroup,
D
Dirk Baeumer 已提交
697 698
			ProcessExecution: extHostTypes.ProcessExecution,
			ShellExecution: extHostTypes.ShellExecution,
699
			ShellQuoting: extHostTypes.ShellQuoting,
D
Dirk Baeumer 已提交
700
			TaskScope: extHostTypes.TaskScope,
S
Sandeep Somavarapu 已提交
701
			Task: extHostTypes.Task,
702
			ConfigurationTarget: extHostTypes.ConfigurationTarget,
703
			RelativePattern: extHostTypes.RelativePattern,
704

J
Johannes Rieken 已提交
705
			FileChangeType: extHostTypes.FileChangeType,
706
			FileType: extHostTypes.FileType,
707 708
			FileChangeType2: extHostTypes.FileChangeType2,
			FileType2: extHostTypes.FileType2,
709 710 711
			FoldingRangeList: extHostTypes.FoldingRangeList,
			FoldingRange: extHostTypes.FoldingRange,
			FoldingRangeType: extHostTypes.FoldingRangeType
712
		};
713
	};
E
Erich Gamma 已提交
714 715 716 717
}

class Extension<T> implements vscode.Extension<T> {

A
Alex Dima 已提交
718
	private _extensionService: ExtHostExtensionService;
E
Erich Gamma 已提交
719 720 721 722 723

	public id: string;
	public extensionPath: string;
	public packageJSON: any;

J
Johannes Rieken 已提交
724
	constructor(extensionService: ExtHostExtensionService, description: IExtensionDescription) {
A
Alex Dima 已提交
725
		this._extensionService = extensionService;
E
Erich Gamma 已提交
726 727 728 729 730 731
		this.id = description.id;
		this.extensionPath = paths.normalize(description.extensionFolderPath, true);
		this.packageJSON = description;
	}

	get isActive(): boolean {
A
Alex Dima 已提交
732
		return this._extensionService.isActivated(this.id);
E
Erich Gamma 已提交
733 734 735
	}

	get exports(): T {
A
Alex Dima 已提交
736
		return <T>this._extensionService.getExtensionExports(this.id);
E
Erich Gamma 已提交
737 738 739
	}

	activate(): Thenable<T> {
740
		return this._extensionService.activateByIdWithErrors(this.id, new ExtensionActivatedByAPI(false)).then(() => this.exports);
E
Erich Gamma 已提交
741 742 743
	}
}

J
Johannes Rieken 已提交
744
export function initializeExtensionApi(extensionService: ExtHostExtensionService, apiFactory: IExtensionApiFactory): TPromise<void> {
745
	return extensionService.getExtensionPathIndex().then(trie => defineAPI(apiFactory, trie));
J
Johannes Rieken 已提交
746 747
}

748
function defineAPI(factory: IExtensionApiFactory, extensionPaths: TernarySearchTree<IExtensionDescription>): void {
J
Johannes Rieken 已提交
749 750

	// each extension is meant to get its own api implementation
J
Johannes Rieken 已提交
751
	const extApiImpl = new Map<string, typeof vscode>();
J
Johannes Rieken 已提交
752
	let defaultApiImpl: typeof vscode;
753 754 755

	const node_module = <any>require.__$__nodeRequire('module');
	const original = node_module._load;
E
Erich Gamma 已提交
756
	node_module._load = function load(request, parent, isMain) {
757 758 759 760 761
		if (request !== 'vscode') {
			return original.apply(this, arguments);
		}

		// get extension id from filename and api for extension
J
Johannes Rieken 已提交
762
		const ext = extensionPaths.findSubstr(parent.filename);
763
		if (ext) {
J
Johannes Rieken 已提交
764
			let apiImpl = extApiImpl.get(ext.id);
765
			if (!apiImpl) {
J
Johannes Rieken 已提交
766 767
				apiImpl = factory(ext);
				extApiImpl.set(ext.id, apiImpl);
768 769 770 771 772 773
			}
			return apiImpl;
		}

		// fall back to a default implementation
		if (!defaultApiImpl) {
774
			defaultApiImpl = factory(nullExtensionDescription);
E
Erich Gamma 已提交
775
		}
776
		return defaultApiImpl;
E
Erich Gamma 已提交
777 778
	};
}
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793

const nullExtensionDescription: IExtensionDescription = {
	id: 'nullExtensionDescription',
	name: 'Null Extension Description',
	publisher: 'vscode',
	activationEvents: undefined,
	contributes: undefined,
	enableProposedApi: false,
	engines: undefined,
	extensionDependencies: undefined,
	extensionFolderPath: undefined,
	isBuiltin: false,
	main: undefined,
	version: undefined
};