extHost.api.impl.ts 39.1 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';
A
Alex Dima 已提交
57
import { OverviewRulerLane } from 'vs/editor/common/model';
58
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
M
Matt Bierner 已提交
59
import { ExtHostWebviews } from 'vs/workbench/api/node/extHostWebview';
60
import * as files from 'vs/platform/files/common/files';
61
import { ExtHostSearch } from './extHostSearch';
E
Erich Gamma 已提交
62

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

67 68 69 70 71 72 73 74 75 76
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}`);
}

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

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

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

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

129
	// Other instances
A
Alex Dima 已提交
130 131 132 133 134
	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);
135

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

139
	return function (extension: IExtensionDescription): typeof vscode {
140

141 142 143 144 145 146 147 148
		// 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) {
149
				console.info(`Extension '${extension.id}' uses a document selector without scheme. Learn more about this: https://go.microsoft.com/fwlink/?linkid=872305`);
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
				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;
			};
		})();

166 167
		// namespace: commands
		const commands: typeof vscode.commands = {
M
Matt Bierner 已提交
168
			registerCommand(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable {
169
				return extHostCommands.registerCommand(true, id, command, thisArgs);
170
			},
171
			registerTextEditorCommand(id: string, callback: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => void, thisArg?: any): vscode.Disposable {
172
				return extHostCommands.registerCommand(true, id, (...args: any[]): any => {
173 174 175
					let activeTextEditor = extHostEditors.getActiveTextEditor();
					if (!activeTextEditor) {
						console.warn('Cannot execute ' + id + ' because there is no active text editor.');
176
						return undefined;
177
					}
178 179 180 181 182 183 184 185 186 187

					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) => {
188
						console.warn('An error occurred while running command ' + id, err);
189
					});
190
				});
191 192
			},
			registerDiffInformationCommand: proposedApiFunction(extension, (id: string, callback: (diff: vscode.LineChange[], ...args: any[]) => any, thisArg?: any): vscode.Disposable => {
193
				return extHostCommands.registerCommand(true, id, async (...args: any[]) => {
194 195 196 197 198 199 200 201 202
					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]);
				});
203
			}),
204
			executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
205
				return extHostCommands.executeCommand<T>(id, ...args);
206
			},
207 208 209
			getCommands(filterInternal: boolean = false): Thenable<string[]> {
				return extHostCommands.getCommands(filterInternal);
			}
210
		};
211

212 213
		// namespace: env
		const env: typeof vscode.env = Object.freeze({
214 215
			get machineId() { return initData.telemetryInfo.machineId; },
			get sessionId() { return initData.telemetryInfo.sessionId; },
216
			get language() { return Platform.language; },
J
Johannes Rieken 已提交
217 218
			get appName() { return product.nameLong; },
			get appRoot() { return initData.environment.appRoot; },
M
Matt Bierner 已提交
219
			get logLevel() { return extHostLogService.getLevel(); }
220
		});
E
Erich Gamma 已提交
221

222 223 224
		// namespace: extensions
		const extensions: typeof vscode.extensions = {
			getExtension(extensionId: string): Extension<any> {
225
				let desc = extensionService.getExtensionDescription(extensionId);
226 227 228
				if (desc) {
					return new Extension(extensionService, desc);
				}
229
				return undefined;
230 231
			},
			get all(): Extension<any>[] {
232
				return extensionService.getAllExtensionDescriptions().map((desc) => new Extension(extensionService, desc));
E
Erich Gamma 已提交
233
			}
234
		};
E
Erich Gamma 已提交
235

236 237 238 239 240
		// namespace: languages
		const languages: typeof vscode.languages = {
			createDiagnosticCollection(name?: string): vscode.DiagnosticCollection {
				return extHostDiagnostics.createDiagnosticCollection(name);
			},
241 242 243 244
			get onDidChangeDiagnostics() {
				checkProposedApiEnabled(extension);
				return extHostDiagnostics.onDidChangeDiagnostics;
			},
245 246 247
			getDiagnostics: (resource?) => {
				return <any>extHostDiagnostics.getDiagnostics(resource);
			},
248 249 250 251
			getLanguages(): TPromise<string[]> {
				return extHostLanguages.getLanguages();
			},
			match(selector: vscode.DocumentSelector, document: vscode.TextDocument): number {
252
				return score(toLanguageSelector(selector), document.uri, document.languageId, true);
253
			},
254 255
			registerCodeActionsProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider, metadata?: vscode.CodeActionProviderMetadata): vscode.Disposable {
				return extHostLanguageFeatures.registerCodeActionProvider(checkSelector(selector), provider, metadata);
256 257
			},
			registerCodeLensProvider(selector: vscode.DocumentSelector, provider: vscode.CodeLensProvider): vscode.Disposable {
258
				return extHostLanguageFeatures.registerCodeLensProvider(checkSelector(selector), provider);
259 260
			},
			registerDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.DefinitionProvider): vscode.Disposable {
261
				return extHostLanguageFeatures.registerDefinitionProvider(checkSelector(selector), provider);
262
			},
M
Matt Bierner 已提交
263
			registerImplementationProvider(selector: vscode.DocumentSelector, provider: vscode.ImplementationProvider): vscode.Disposable {
264
				return extHostLanguageFeatures.registerImplementationProvider(checkSelector(selector), provider);
265
			},
266
			registerTypeDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.TypeDefinitionProvider): vscode.Disposable {
267
				return extHostLanguageFeatures.registerTypeDefinitionProvider(checkSelector(selector), provider);
268
			},
269
			registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider): vscode.Disposable {
270
				return extHostLanguageFeatures.registerHoverProvider(checkSelector(selector), provider, extension.id);
271 272
			},
			registerDocumentHighlightProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentHighlightProvider): vscode.Disposable {
273
				return extHostLanguageFeatures.registerDocumentHighlightProvider(checkSelector(selector), provider);
274 275
			},
			registerReferenceProvider(selector: vscode.DocumentSelector, provider: vscode.ReferenceProvider): vscode.Disposable {
276
				return extHostLanguageFeatures.registerReferenceProvider(checkSelector(selector), provider);
277 278
			},
			registerRenameProvider(selector: vscode.DocumentSelector, provider: vscode.RenameProvider): vscode.Disposable {
279
				return extHostLanguageFeatures.registerRenameProvider(checkSelector(selector), provider, extension.enableProposedApi);
280 281
			},
			registerDocumentSymbolProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentSymbolProvider): vscode.Disposable {
282
				return extHostLanguageFeatures.registerDocumentSymbolProvider(checkSelector(selector), provider);
283 284
			},
			registerWorkspaceSymbolProvider(provider: vscode.WorkspaceSymbolProvider): vscode.Disposable {
285
				return extHostLanguageFeatures.registerWorkspaceSymbolProvider(provider);
286 287
			},
			registerDocumentFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
288
				return extHostLanguageFeatures.registerDocumentFormattingEditProvider(checkSelector(selector), provider);
289 290
			},
			registerDocumentRangeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider): vscode.Disposable {
291
				return extHostLanguageFeatures.registerDocumentRangeFormattingEditProvider(checkSelector(selector), provider);
292 293
			},
			registerOnTypeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, firstTriggerCharacter: string, ...moreTriggerCharacters: string[]): vscode.Disposable {
294
				return extHostLanguageFeatures.registerOnTypeFormattingEditProvider(checkSelector(selector), provider, [firstTriggerCharacter].concat(moreTriggerCharacters));
295 296
			},
			registerSignatureHelpProvider(selector: vscode.DocumentSelector, provider: vscode.SignatureHelpProvider, ...triggerCharacters: string[]): vscode.Disposable {
297
				return extHostLanguageFeatures.registerSignatureHelpProvider(checkSelector(selector), provider, triggerCharacters);
298 299
			},
			registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, ...triggerCharacters: string[]): vscode.Disposable {
300
				return extHostLanguageFeatures.registerCompletionItemProvider(checkSelector(selector), provider, triggerCharacters);
301 302
			},
			registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
303
				return extHostLanguageFeatures.registerDocumentLinkProvider(checkSelector(selector), provider);
304
			},
305
			registerColorProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentColorProvider): vscode.Disposable {
306
				return extHostLanguageFeatures.registerColorProvider(checkSelector(selector), provider);
307
			},
308
			registerFoldingRangeProvider(selector: vscode.DocumentSelector, provider: vscode.FoldingRangeProvider): vscode.Disposable {
309
				return extHostLanguageFeatures.registerFoldingRangeProvider(checkSelector(selector), provider);
310
			},
311
			setLanguageConfiguration: (language: string, configuration: vscode.LanguageConfiguration): vscode.Disposable => {
312
				return extHostLanguageFeatures.setLanguageConfiguration(language, configuration);
313
			}
314
		};
E
Erich Gamma 已提交
315

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

438 439 440 441 442 443 444 445
		// namespace: workspace
		const workspace: typeof vscode.workspace = {
			get rootPath() {
				return extHostWorkspace.getPath();
			},
			set rootPath(value) {
				throw errors.readonly();
			},
446 447
			getWorkspaceFolder(resource) {
				return extHostWorkspace.getWorkspaceFolder(resource);
448
			},
449
			get workspaceFolders() {
450
				return extHostWorkspace.getWorkspaceFolders();
451
			},
452 453 454 455 456 457
			get name() {
				return extHostWorkspace.workspace ? extHostWorkspace.workspace.name : undefined;
			},
			set name(value) {
				throw errors.readonly();
			},
458 459 460
			updateWorkspaceFolders: (index, deleteCount, ...workspaceFoldersToAdd) => {
				return extHostWorkspace.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
			},
461
			onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
462
				return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
463
			},
J
Johannes Rieken 已提交
464 465
			asRelativePath: (pathOrUri, includeWorkspace) => {
				return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
466 467
			},
			findFiles: (include, exclude, maxResults?, token?) => {
468
				return extHostWorkspace.findFiles(toGlobPattern(include), toGlobPattern(exclude), maxResults, extension.id, token);
469 470 471 472 473
			},
			saveAll: (includeUntitled?) => {
				return extHostWorkspace.saveAll(includeUntitled);
			},
			applyEdit(edit: vscode.WorkspaceEdit): TPromise<boolean> {
474
				return extHostEditors.applyWorkspaceEdit(edit);
475 476
			},
			createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
477
				return extHostFileSystemEvent.createFileSystemWatcher(toGlobPattern(pattern), ignoreCreate, ignoreChange, ignoreDelete);
478 479 480 481 482 483 484
			},
			get textDocuments() {
				return extHostDocuments.getAllDocumentData().map(data => data.document);
			},
			set textDocuments(value) {
				throw errors.readonly();
			},
485
			openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) {
B
Benjamin Pasero 已提交
486 487
				let uriPromise: TPromise<URI>;

488
				let options = uriOrFileNameOrOptions as { language?: string; content?: string; };
B
Benjamin Pasero 已提交
489
				if (typeof uriOrFileNameOrOptions === 'string') {
B
Benjamin Pasero 已提交
490 491
					uriPromise = TPromise.as(URI.file(uriOrFileNameOrOptions));
				} else if (uriOrFileNameOrOptions instanceof URI) {
J
Johannes Rieken 已提交
492
					uriPromise = TPromise.as(uriOrFileNameOrOptions);
B
Benjamin Pasero 已提交
493 494
				} else if (!options || typeof options === 'object') {
					uriPromise = extHostDocuments.createDocumentData(options);
495
				} else {
B
Benjamin Pasero 已提交
496
					throw new Error('illegal argument - uriOrFileNameOrOptions');
497
				}
B
Benjamin Pasero 已提交
498 499 500 501 502 503

				return uriPromise.then(uri => {
					return extHostDocuments.ensureDocumentData(uri).then(() => {
						const data = extHostDocuments.getDocumentData(uri);
						return data && data.document;
					});
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
				});
			},
			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?) => {
519
				return extHostDocumentSaveParticipant.getOnWillSaveTextDocumentEvent(extension)(listener, thisArgs, disposables);
520
			},
521
			onDidChangeConfiguration: (listener: (_: any) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
522 523
				return extHostConfiguration.onDidChangeConfiguration(listener, thisArgs, disposables);
			},
524 525
			getConfiguration(section?: string, resource?: vscode.Uri): vscode.WorkspaceConfiguration {
				resource = arguments.length === 1 ? void 0 : resource;
S
Sandeep Somavarapu 已提交
526
				return extHostConfiguration.getConfiguration(section, resource, extension.id);
527
			},
528 529
			registerTextDocumentContentProvider(scheme: string, provider: vscode.TextDocumentContentProvider) {
				return extHostDocumentContentProviders.registerTextDocumentContentProvider(scheme, provider);
530
			},
531
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
532
				return extHostTask.registerTaskProvider(extension, provider);
J
Johannes Rieken 已提交
533
			},
534
			fetchTasks: proposedApiFunction(extension, (): Thenable<vscode.Task[]> => {
535
				return extHostTask.executeTaskProvider();
536 537
			}),
			executeTask: proposedApiFunction(extension, (task: vscode.Task): Thenable<vscode.TaskExecution> => {
538
				return extHostTask.executeTask(extension, task);
539
			}),
540 541 542 543 544 545
			onDidStartTask: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidStartTask(listeners, thisArgs, disposables);
			},
			onDidEndTask: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidEndTask(listeners, thisArgs, disposables);
			},
546 547
			registerFileSystemProvider: proposedApiFunction(extension, (scheme, provider, newProvider?) => {
				return extHostFileSystem.registerFileSystemProvider(scheme, provider, newProvider);
548
			}),
549 550 551
			registerDeprecatedFileSystemProvider: proposedApiFunction(extension, (scheme, provider) => {
				return extHostFileSystem.registerDeprecatedFileSystemProvider(scheme, provider);
			}),
552
			registerSearchProvider: proposedApiFunction(extension, (scheme, provider) => {
553
				return extHostSearch.registerSearchProvider(scheme, provider);
J
Johannes Rieken 已提交
554
			})
555
		};
556

557 558
		// namespace: scm
		const scm: typeof vscode.scm = {
559
			get inputBox() {
J
Joao Moreno 已提交
560
				return extHostSCM.getLastInputBox(extension);
561
			},
J
Joao Moreno 已提交
562 563
			createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
				return extHostSCM.createSourceControl(extension, id, label, rootUri);
J
Joao Moreno 已提交
564
			}
565
		};
J
Joao Moreno 已提交
566

567 568
		// namespace: debug
		const debug: typeof vscode.debug = {
569 570 571
			get activeDebugSession() {
				return extHostDebugService.activeDebugSession;
			},
572 573
			get activeDebugConsole() {
				return extHostDebugService.activeDebugConsole;
574
			},
575 576
			get breakpoints() {
				return extHostDebugService.breakpoints;
577
			},
578 579 580
			onDidStartDebugSession(listener, thisArg?, disposables?) {
				return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
			},
581
			onDidTerminateDebugSession(listener, thisArg?, disposables?) {
582
				return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
583
			},
A
Andre Weinand 已提交
584
			onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
585
				return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
A
Andre Weinand 已提交
586 587
			},
			onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
A
Andre Weinand 已提交
588
				return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
589
			},
590
			onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
591 592
				return extHostDebugService.onDidChangeBreakpoints(listener, thisArgs, disposables);
			},
A
Andre Weinand 已提交
593
			registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) {
594
				return extHostDebugService.registerDebugConfigurationProvider(debugType, provider);
595
			},
596 597 598 599
			startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration) {
				return extHostDebugService.startDebugging(folder, nameOrConfig);
			},
			addBreakpoints(breakpoints: vscode.Breakpoint[]) {
600
				return extHostDebugService.addBreakpoints(breakpoints);
601 602
			},
			removeBreakpoints(breakpoints: vscode.Breakpoint[]) {
603
				return extHostDebugService.removeBreakpoints(breakpoints);
604
			}
605 606 607
		};


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

J
Johannes Rieken 已提交
688
			FileChangeType: extHostTypes.FileChangeType,
689
			FileType: extHostTypes.FileType,
690 691
			DeprecatedFileChangeType: extHostTypes.FileChangeType,
			DeprecatedFileType: extHostTypes.FileType,
692 693
			FileChangeType2: extHostTypes.FileChangeType2,
			FileType2: extHostTypes.FileType2,
694
			FileOpenFlags: files.FileOpenFlags,
J
Johannes Rieken 已提交
695
			FileError: extHostTypes.FileError,
696
			FoldingRange: extHostTypes.FoldingRange,
697
			FoldingRangeKind: extHostTypes.FoldingRangeKind
698
		};
699
	};
E
Erich Gamma 已提交
700 701 702 703
}

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

A
Alex Dima 已提交
704
	private _extensionService: ExtHostExtensionService;
E
Erich Gamma 已提交
705 706 707 708 709

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

J
Johannes Rieken 已提交
710
	constructor(extensionService: ExtHostExtensionService, description: IExtensionDescription) {
A
Alex Dima 已提交
711
		this._extensionService = extensionService;
E
Erich Gamma 已提交
712 713 714 715 716 717
		this.id = description.id;
		this.extensionPath = paths.normalize(description.extensionFolderPath, true);
		this.packageJSON = description;
	}

	get isActive(): boolean {
A
Alex Dima 已提交
718
		return this._extensionService.isActivated(this.id);
E
Erich Gamma 已提交
719 720 721
	}

	get exports(): T {
A
Alex Dima 已提交
722
		return <T>this._extensionService.getExtensionExports(this.id);
E
Erich Gamma 已提交
723 724 725
	}

	activate(): Thenable<T> {
726
		return this._extensionService.activateByIdWithErrors(this.id, new ExtensionActivatedByAPI(false)).then(() => this.exports);
E
Erich Gamma 已提交
727 728 729
	}
}

J
Johannes Rieken 已提交
730
export function initializeExtensionApi(extensionService: ExtHostExtensionService, apiFactory: IExtensionApiFactory): TPromise<void> {
731
	return extensionService.getExtensionPathIndex().then(trie => defineAPI(apiFactory, trie));
J
Johannes Rieken 已提交
732 733
}

734
function defineAPI(factory: IExtensionApiFactory, extensionPaths: TernarySearchTree<IExtensionDescription>): void {
J
Johannes Rieken 已提交
735 736

	// each extension is meant to get its own api implementation
J
Johannes Rieken 已提交
737
	const extApiImpl = new Map<string, typeof vscode>();
J
Johannes Rieken 已提交
738
	let defaultApiImpl: typeof vscode;
739 740 741

	const node_module = <any>require.__$__nodeRequire('module');
	const original = node_module._load;
E
Erich Gamma 已提交
742
	node_module._load = function load(request, parent, isMain) {
743 744 745 746 747
		if (request !== 'vscode') {
			return original.apply(this, arguments);
		}

		// get extension id from filename and api for extension
J
Johannes Rieken 已提交
748
		const ext = extensionPaths.findSubstr(parent.filename);
749
		if (ext) {
J
Johannes Rieken 已提交
750
			let apiImpl = extApiImpl.get(ext.id);
751
			if (!apiImpl) {
J
Johannes Rieken 已提交
752 753
				apiImpl = factory(ext);
				extApiImpl.set(ext.id, apiImpl);
754 755 756 757 758 759
			}
			return apiImpl;
		}

		// fall back to a default implementation
		if (!defaultApiImpl) {
760
			defaultApiImpl = factory(nullExtensionDescription);
E
Erich Gamma 已提交
761
		}
762
		return defaultApiImpl;
E
Erich Gamma 已提交
763 764
	};
}
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779

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
};