extHost.api.impl.ts 48.2 KB
Newer Older
E
Erich Gamma 已提交
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';
A
Alex Dima 已提交
7 8
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import * as errors from 'vs/base/common/errors';
J
Joao Moreno 已提交
9
import { Emitter, Event } from 'vs/base/common/event';
10
import * as path from 'vs/base/common/path';
A
Alex Dima 已提交
11 12 13 14 15 16 17
import Severity from 'vs/base/common/severity';
import { URI } from 'vs/base/common/uri';
import { TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions';
import { OverviewRulerLane } from 'vs/editor/common/model';
import * as languageConfiguration from 'vs/editor/common/modes/languageConfiguration';
import { score } from 'vs/editor/common/modes/languageSelector';
import * as files from 'vs/platform/files/common/files';
J
Johannes Rieken 已提交
18
import { ExtHostContext, IInitData, IMainContext, MainContext } from 'vs/workbench/api/common/extHost.protocol';
J
Johannes Rieken 已提交
19 20 21 22 23
import { ExtHostApiCommands } from 'vs/workbench/api/common/extHostApiCommands';
import { ExtHostClipboard } from 'vs/workbench/api/common/extHostClipboard';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { ExtHostComments } from 'vs/workbench/api/common/extHostComments';
import { ExtHostConfiguration, ExtHostConfigProvider } from 'vs/workbench/api/common/extHostConfiguration';
A
Alex Dima 已提交
24
import { ExtHostDebugService } from 'vs/workbench/api/node/extHostDebugService';
J
Johannes Rieken 已提交
25 26 27 28 29 30 31
import { ExtHostDecorations } from 'vs/workbench/api/common/extHostDecorations';
import { ExtHostDiagnostics } from 'vs/workbench/api/common/extHostDiagnostics';
import { ExtHostDialogs } from 'vs/workbench/api/common/extHostDialogs';
import { ExtHostDocumentContentProvider } from 'vs/workbench/api/common/extHostDocumentContentProviders';
import { ExtHostDocumentSaveParticipant } from 'vs/workbench/api/common/extHostDocumentSaveParticipant';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
32
import { ExtensionActivatedByAPI } from 'vs/workbench/api/common/extHostExtensionActivator';
A
Alex Dima 已提交
33
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
J
Johannes Rieken 已提交
34 35 36
import { ExtHostFileSystem } from 'vs/workbench/api/common/extHostFileSystem';
import { ExtHostFileSystemEventService } from 'vs/workbench/api/common/extHostFileSystemEventService';
import { ExtHostHeapService } from 'vs/workbench/api/common/extHostHeapService';
37
import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures';
J
Johannes Rieken 已提交
38
import { ExtHostLanguages } from 'vs/workbench/api/common/extHostLanguages';
J
Johannes Rieken 已提交
39
import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService';
J
Johannes Rieken 已提交
40
import { ExtHostMessageService } from 'vs/workbench/api/common/extHostMessageService';
41 42
import { ExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
import { LogOutputChannelFactory } from 'vs/workbench/api/node/extHostOutputService';
J
Johannes Rieken 已提交
43 44 45
import { ExtHostProgress } from 'vs/workbench/api/common/extHostProgress';
import { ExtHostQuickOpen } from 'vs/workbench/api/common/extHostQuickOpen';
import { ExtHostSCM } from 'vs/workbench/api/common/extHostSCM';
A
Alex Dima 已提交
46
import { ExtHostSearch, registerEHSearchProviders } from 'vs/workbench/api/node/extHostSearch';
J
Johannes Rieken 已提交
47 48
import { ExtHostStatusBar } from 'vs/workbench/api/common/extHostStatusBar';
import { ExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
A
Alex Dima 已提交
49
import { ExtHostTask } from 'vs/workbench/api/node/extHostTask';
J
Johannes Rieken 已提交
50
import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalService';
J
Johannes Rieken 已提交
51 52 53 54 55 56 57 58
import { ExtHostEditors } from 'vs/workbench/api/common/extHostTextEditors';
import { ExtHostTreeViews } from 'vs/workbench/api/common/extHostTreeViews';
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { ExtHostUrls } from 'vs/workbench/api/common/extHostUrls';
import { ExtHostWebviews } from 'vs/workbench/api/common/extHostWebview';
import { ExtHostWindow } from 'vs/workbench/api/common/extHostWindow';
import { ExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
J
Johannes Rieken 已提交
59
import { throwProposedApiError, checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
J
Johannes Rieken 已提交
60
import { ProxyIdentifier } from 'vs/workbench/services/extensions/common/proxyIdentifier';
61
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
A
Alex Dima 已提交
62
import * as vscode from 'vscode';
63
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
64
import { originalFSPath } from 'vs/base/common/resources';
65
import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
66
import { withNullAsUndefined } from 'vs/base/common/types';
J
Johannes Rieken 已提交
67
import { values } from 'vs/base/common/collections';
A
Alex Dima 已提交
68
import { Schemas } from 'vs/base/common/network';
69
import { IURITransformer } from 'vs/base/common/uriIpc';
70
import { ExtHostEditorInsets } from 'vs/workbench/api/common/extHostCodeInsets';
E
Erich Gamma 已提交
71

72
export interface IExtensionApiFactory {
73
	(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
74 75
}

76
function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
77
	if (extension.enableProposedApi) {
78 79
		return fn;
	} else {
80
		return throwProposedApiError.bind(null, extension) as any as T;
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,
89
	rpcProtocol: IMainContext,
90 91
	extHostWorkspace: ExtHostWorkspace,
	extHostConfiguration: ExtHostConfiguration,
J
Joao Moreno 已提交
92
	extensionService: ExtHostExtensionService,
93
	extHostLogService: ExtHostLogService,
A
Alex Dima 已提交
94
	extHostStorage: ExtHostStorage,
95
	uriTransformer: IURITransformer | null
96
): IExtensionApiFactory {
97

98
	// Addressable instances
99
	rpcProtocol.set(ExtHostContext.ExtHostLogService, extHostLogService);
A
Alex Dima 已提交
100 101
	const extHostHeapService = rpcProtocol.set(ExtHostContext.ExtHostHeapService, new ExtHostHeapService());
	const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, new ExtHostDecorations(rpcProtocol));
M
Matt Bierner 已提交
102
	const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol));
J
Joao Moreno 已提交
103
	const extHostUrls = rpcProtocol.set(ExtHostContext.ExtHostUrls, new ExtHostUrls(rpcProtocol));
104
	const extHostDocumentsAndEditors = rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, new ExtHostDocumentsAndEditors(rpcProtocol));
A
Alex Dima 已提交
105
	const extHostDocuments = rpcProtocol.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors));
106
	const extHostDocumentContentProviders = rpcProtocol.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(rpcProtocol, extHostDocumentsAndEditors, extHostLogService));
107
	const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostLogService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadTextEditors)));
A
Alex Dima 已提交
108
	const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(rpcProtocol, extHostDocumentsAndEditors));
109
	const extHostCommands = rpcProtocol.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(rpcProtocol, extHostHeapService, extHostLogService));
S
Sandeep Somavarapu 已提交
110
	const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands, extHostLogService));
A
Alex Dima 已提交
111 112
	rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
	rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
113
	const extHostEditorInsets = rpcProtocol.set(ExtHostContext.ExtHostEditorInsets, new ExtHostEditorInsets(rpcProtocol.getProxy(MainContext.MainThreadEditorInsets), extHostEditors));
A
Alex Dima 已提交
114
	const extHostDiagnostics = rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(rpcProtocol));
115
	const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, uriTransformer, extHostDocuments, extHostCommands, extHostHeapService, extHostDiagnostics, extHostLogService));
116
	const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
117
	const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, extHostDocumentsAndEditors));
A
Alex Dima 已提交
118
	const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands));
119
	const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(rpcProtocol, extHostConfiguration, extHostWorkspace, extHostDocumentsAndEditors, extHostLogService));
120
	const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(rpcProtocol, extHostWorkspace, extensionService, extHostDocumentsAndEditors, extHostConfiguration, extHostTerminalService, extHostCommands));
121
	const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));
P
Peng Lyu 已提交
122
	const extHostComment = rpcProtocol.set(ExtHostContext.ExtHostComments, new ExtHostComments(rpcProtocol, extHostCommands, extHostDocuments));
123
	const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, new ExtHostSearch(rpcProtocol, uriTransformer, extHostLogService));
124
	const extHostTask = rpcProtocol.set(ExtHostContext.ExtHostTask, new ExtHostTask(rpcProtocol, extHostWorkspace, extHostDocumentsAndEditors, extHostConfiguration, extHostTerminalService));
A
Alex Dima 已提交
125 126
	const extHostWindow = rpcProtocol.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(rpcProtocol));
	rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
127
	const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
128
	const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, new ExtHostOutputService(LogOutputChannelFactory, initData.logsLocation, rpcProtocol));
129
	rpcProtocol.set(ExtHostContext.ExtHostStorage, extHostStorage);
130
	if (initData.remoteAuthority) {
A
Alex Dima 已提交
131 132 133 134 135 136 137 138
		extHostTask.registerTaskSystem(Schemas.vscodeRemote, {
			scheme: Schemas.vscodeRemote,
			authority: initData.remoteAuthority,
			platform: process.platform
		});

		registerEHSearchProviders(extHostSearch, extHostLogService);

139 140 141
		const cliServer = new CLIServer(extHostCommands);
		process.env['VSCODE_IPC_HOOK_CLI'] = cliServer.ipcHandlePath;
	}
142 143

	// Check that no named customers are missing
J
Johannes Rieken 已提交
144
	const expected: ProxyIdentifier<any>[] = values(ExtHostContext);
A
Alex Dima 已提交
145
	rpcProtocol.assertRegistered(expected);
146

147
	// Other instances
148
	const extHostClipboard = new ExtHostClipboard(rpcProtocol);
A
Alex Dima 已提交
149 150 151
	const extHostMessageService = new ExtHostMessageService(rpcProtocol);
	const extHostDialogs = new ExtHostDialogs(rpcProtocol);
	const extHostStatusBar = new ExtHostStatusBar(rpcProtocol);
152
	const extHostLanguages = new ExtHostLanguages(rpcProtocol, extHostDocuments);
153

154
	// Register an output channel for exthost log
155
	const outputChannelName = initData.remoteAuthority ? nls.localize('remote extension host Log', "Remote Extension Host") : nls.localize('extension host Log', "Extension Host");
A
Alex Dima 已提交
156
	extHostOutputService.createOutputChannelFromLogFile(outputChannelName, extHostLogService.logFile);
157

158
	// Register API-ish commands
159
	ExtHostApiCommands.register(extHostCommands);
160

161
	return function (extension: IExtensionDescription, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode {
162

163 164
		// 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
165
		// extension should specify then the `file`-scheme, e.g. `{ scheme: 'fooLang', language: 'fooLang' }`
166 167
		// 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...
168
		const checkSelector = (function () {
A
Alex Dima 已提交
169
			let done = (!extension.isUnderDevelopment);
170 171
			function informOnce(selector: vscode.DocumentSelector) {
				if (!done) {
172
					console.info(`Extension '${extension.identifier.value}' uses a document selector without scheme. Learn more about this: https://go.microsoft.com/fwlink/?linkid=872305`);
173 174
					done = true;
				}
175
			}
176
			return function perform(selector: vscode.DocumentSelector): vscode.DocumentSelector {
177 178 179 180 181 182 183 184 185 186
				if (Array.isArray(selector)) {
					selector.forEach(perform);
				} else if (typeof selector === 'string') {
					informOnce(selector);
				} else {
					if (typeof selector.scheme === 'undefined') {
						informOnce(selector);
					}
					if (!extension.enableProposedApi && typeof selector.exclusive === 'boolean') {
						throwProposedApiError(extension);
187 188 189 190 191
					}
				}
				return selector;
			};
		})();
192

193

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

					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) => {
216
						console.warn('An error occurred while running command ' + id, err);
217
					});
218
				});
219 220
			},
			registerDiffInformationCommand: proposedApiFunction(extension, (id: string, callback: (diff: vscode.LineChange[], ...args: any[]) => any, thisArg?: any): vscode.Disposable => {
221
				return extHostCommands.registerCommand(true, id, async (...args: any[]): Promise<any> => {
222
					const activeTextEditor = extHostEditors.getActiveTextEditor();
223 224 225 226 227 228 229 230
					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]);
				});
231
			}),
232
			executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
M
Matt Bierner 已提交
233
				return extHostCommands.executeCommand<T>(id, ...args);
234
			},
235 236 237
			getCommands(filterInternal: boolean = false): Thenable<string[]> {
				return extHostCommands.getCommands(filterInternal);
			}
238
		};
239

240
		// namespace: env
241
		const env: typeof vscode.env = {
242 243
			get machineId() { return initData.telemetryInfo.machineId; },
			get sessionId() { return initData.telemetryInfo.sessionId; },
244 245
			get language() { return initData.environment.appLanguage; },
			get appName() { return initData.environment.appName; },
246
			get appRoot() { return initData.environment.appRoot!.fsPath; },
247
			get uriScheme() { return initData.environment.appUriScheme; },
248 249
			get logLevel() {
				checkProposedApiEnabled(extension);
250
				return typeConverters.LogLevel.to(extHostLogService.getLevel());
251 252 253
			},
			get onDidChangeLogLevel() {
				checkProposedApiEnabled(extension);
J
Joao Moreno 已提交
254
				return Event.map(extHostLogService.onDidChangeLogLevel, l => typeConverters.LogLevel.to(l));
255 256 257
			},
			get clipboard(): vscode.Clipboard {
				return extHostClipboard;
258
			},
J
Johannes Rieken 已提交
259
			openExternal(uri: URI) {
260
				return extHostWindow.openUri(uri, { allowTunneling: !!initData.remoteAuthority });
261
			}
262 263 264 265 266
		};
		if (!initData.environment.extensionTestsLocationURI) {
			// allow to patch env-function when running tests
			Object.freeze(env);
		}
E
Erich Gamma 已提交
267

268 269
		// namespace: extensions
		const extensions: typeof vscode.extensions = {
270 271
			getExtension(extensionId: string): Extension<any> | undefined {
				const desc = extensionRegistry.getExtensionDescription(extensionId);
272 273 274
				if (desc) {
					return new Extension(extensionService, desc);
				}
275
				return undefined;
276 277
			},
			get all(): Extension<any>[] {
A
Alex Dima 已提交
278
				return extensionRegistry.getAllExtensionDescriptions().map((desc) => new Extension(extensionService, desc));
279 280 281
			},
			get onDidChange() {
				return extensionRegistry.onDidChange;
E
Erich Gamma 已提交
282
			}
283
		};
E
Erich Gamma 已提交
284

285 286 287 288 289
		// namespace: languages
		const languages: typeof vscode.languages = {
			createDiagnosticCollection(name?: string): vscode.DiagnosticCollection {
				return extHostDiagnostics.createDiagnosticCollection(name);
			},
290 291 292
			get onDidChangeDiagnostics() {
				return extHostDiagnostics.onDidChangeDiagnostics;
			},
A
Alex Dima 已提交
293
			getDiagnostics: (resource?: vscode.Uri) => {
294 295
				return <any>extHostDiagnostics.getDiagnostics(resource);
			},
296
			getLanguages(): Thenable<string[]> {
297 298
				return extHostLanguages.getLanguages();
			},
299
			setTextDocumentLanguage(document: vscode.TextDocument, languageId: string): Thenable<vscode.TextDocument> {
M
mechatroner 已提交
300
				return extHostLanguages.changeLanguage(document.uri, languageId);
301
			},
302
			match(selector: vscode.DocumentSelector, document: vscode.TextDocument): number {
303
				return score(typeConverters.LanguageSelector.from(selector), document.uri, document.languageId, true);
304
			},
305
			registerCodeActionsProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider, metadata?: vscode.CodeActionProviderMetadata): vscode.Disposable {
306
				return extHostLanguageFeatures.registerCodeActionProvider(extension, checkSelector(selector), provider, metadata);
307 308
			},
			registerCodeLensProvider(selector: vscode.DocumentSelector, provider: vscode.CodeLensProvider): vscode.Disposable {
309
				return extHostLanguageFeatures.registerCodeLensProvider(extension, checkSelector(selector), provider);
310 311
			},
			registerDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.DefinitionProvider): vscode.Disposable {
312
				return extHostLanguageFeatures.registerDefinitionProvider(extension, checkSelector(selector), provider);
313
			},
314 315 316
			registerDeclarationProvider(selector: vscode.DocumentSelector, provider: vscode.DeclarationProvider): vscode.Disposable {
				return extHostLanguageFeatures.registerDeclarationProvider(extension, checkSelector(selector), provider);
			},
M
Matt Bierner 已提交
317
			registerImplementationProvider(selector: vscode.DocumentSelector, provider: vscode.ImplementationProvider): vscode.Disposable {
318
				return extHostLanguageFeatures.registerImplementationProvider(extension, checkSelector(selector), provider);
319
			},
320
			registerTypeDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.TypeDefinitionProvider): vscode.Disposable {
321
				return extHostLanguageFeatures.registerTypeDefinitionProvider(extension, checkSelector(selector), provider);
322
			},
323
			registerHoverProvider(selector: vscode.DocumentSelector, provider: vscode.HoverProvider): vscode.Disposable {
324
				return extHostLanguageFeatures.registerHoverProvider(extension, checkSelector(selector), provider, extension.identifier);
325 326
			},
			registerDocumentHighlightProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentHighlightProvider): vscode.Disposable {
327
				return extHostLanguageFeatures.registerDocumentHighlightProvider(extension, checkSelector(selector), provider);
328 329
			},
			registerReferenceProvider(selector: vscode.DocumentSelector, provider: vscode.ReferenceProvider): vscode.Disposable {
330
				return extHostLanguageFeatures.registerReferenceProvider(extension, checkSelector(selector), provider);
331 332
			},
			registerRenameProvider(selector: vscode.DocumentSelector, provider: vscode.RenameProvider): vscode.Disposable {
333
				return extHostLanguageFeatures.registerRenameProvider(extension, checkSelector(selector), provider);
334
			},
335 336
			registerDocumentSymbolProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentSymbolProvider, metadata?: vscode.DocumentSymbolProviderMetadata): vscode.Disposable {
				return extHostLanguageFeatures.registerDocumentSymbolProvider(extension, checkSelector(selector), provider, metadata);
337 338
			},
			registerWorkspaceSymbolProvider(provider: vscode.WorkspaceSymbolProvider): vscode.Disposable {
339
				return extHostLanguageFeatures.registerWorkspaceSymbolProvider(extension, provider);
340 341
			},
			registerDocumentFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentFormattingEditProvider): vscode.Disposable {
342
				return extHostLanguageFeatures.registerDocumentFormattingEditProvider(extension, checkSelector(selector), provider);
343 344
			},
			registerDocumentRangeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentRangeFormattingEditProvider): vscode.Disposable {
345
				return extHostLanguageFeatures.registerDocumentRangeFormattingEditProvider(extension, checkSelector(selector), provider);
346 347
			},
			registerOnTypeFormattingEditProvider(selector: vscode.DocumentSelector, provider: vscode.OnTypeFormattingEditProvider, firstTriggerCharacter: string, ...moreTriggerCharacters: string[]): vscode.Disposable {
348
				return extHostLanguageFeatures.registerOnTypeFormattingEditProvider(extension, checkSelector(selector), provider, [firstTriggerCharacter].concat(moreTriggerCharacters));
349
			},
350 351
			registerSignatureHelpProvider(selector: vscode.DocumentSelector, provider: vscode.SignatureHelpProvider, firstItem?: string | vscode.SignatureHelpProviderMetadata, ...remaining: string[]): vscode.Disposable {
				if (typeof firstItem === 'object') {
352
					return extHostLanguageFeatures.registerSignatureHelpProvider(extension, checkSelector(selector), provider, firstItem);
353
				}
354
				return extHostLanguageFeatures.registerSignatureHelpProvider(extension, checkSelector(selector), provider, typeof firstItem === 'undefined' ? [] : [firstItem, ...remaining]);
355 356
			},
			registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, ...triggerCharacters: string[]): vscode.Disposable {
357
				return extHostLanguageFeatures.registerCompletionItemProvider(extension, checkSelector(selector), provider, triggerCharacters);
358 359
			},
			registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable {
360
				return extHostLanguageFeatures.registerDocumentLinkProvider(extension, checkSelector(selector), provider);
361
			},
362
			registerColorProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentColorProvider): vscode.Disposable {
363
				return extHostLanguageFeatures.registerColorProvider(extension, checkSelector(selector), provider);
364
			},
365
			registerFoldingRangeProvider(selector: vscode.DocumentSelector, provider: vscode.FoldingRangeProvider): vscode.Disposable {
366
				return extHostLanguageFeatures.registerFoldingRangeProvider(extension, checkSelector(selector), provider);
367
			},
368 369 370
			registerSelectionRangeProvider(selector: vscode.DocumentSelector, provider: vscode.SelectionRangeProvider): vscode.Disposable {
				return extHostLanguageFeatures.registerSelectionRangeProvider(extension, selector, provider);
			},
371 372 373 374
			registerCallHierarchyProvider(selector: vscode.DocumentSelector, provider: vscode.CallHierarchyItemProvider): vscode.Disposable {
				checkProposedApiEnabled(extension);
				return extHostLanguageFeatures.registerCallHierarchyProvider(extension, selector, provider);
			},
375
			setLanguageConfiguration: (language: string, configuration: vscode.LanguageConfiguration): vscode.Disposable => {
376
				return extHostLanguageFeatures.setLanguageConfiguration(language, configuration);
377
			}
378
		};
E
Erich Gamma 已提交
379

380 381 382 383 384 385 386 387
		// namespace: window
		const window: typeof vscode.window = {
			get activeTextEditor() {
				return extHostEditors.getActiveTextEditor();
			},
			get visibleTextEditors() {
				return extHostEditors.getVisibleTextEditors();
			},
388
			get activeTerminal() {
D
Daniel Imms 已提交
389
				return extHostTerminalService.activeTerminal;
390
			},
D
Daniel Imms 已提交
391
			get terminals() {
D
Daniel Imms 已提交
392
				return extHostTerminalService.terminals;
D
Daniel Imms 已提交
393
			},
394
			showTextDocument(documentOrUri: vscode.TextDocument | vscode.Uri, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, preserveFocus?: boolean): Thenable<vscode.TextEditor> {
395
				let documentPromise: Promise<vscode.TextDocument>;
J
Johannes Rieken 已提交
396
				if (URI.isUri(documentOrUri)) {
397
					documentPromise = Promise.resolve(workspace.openTextDocument(documentOrUri));
B
Benjamin Pasero 已提交
398
				} else {
399
					documentPromise = Promise.resolve(<vscode.TextDocument>documentOrUri);
B
Benjamin Pasero 已提交
400 401 402 403
				}
				return documentPromise.then(document => {
					return extHostEditors.showTextDocument(document, columnOrOptions, preserveFocus);
				});
404 405 406 407
			},
			createTextEditorDecorationType(options: vscode.DecorationRenderOptions): vscode.TextEditorDecorationType {
				return extHostEditors.createTextEditorDecorationType(options);
			},
408 409 410
			onDidChangeActiveTextEditor(listener, thisArg?, disposables?) {
				return extHostEditors.onDidChangeActiveTextEditor(listener, thisArg, disposables);
			},
411 412 413
			onDidChangeVisibleTextEditors(listener, thisArg, disposables) {
				return extHostEditors.onDidChangeVisibleTextEditors(listener, thisArg, disposables);
			},
414
			onDidChangeTextEditorSelection(listener: (e: vscode.TextEditorSelectionChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
415 416
				return extHostEditors.onDidChangeTextEditorSelection(listener, thisArgs, disposables);
			},
417
			onDidChangeTextEditorOptions(listener: (e: vscode.TextEditorOptionsChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
418 419
				return extHostEditors.onDidChangeTextEditorOptions(listener, thisArgs, disposables);
			},
420
			onDidChangeTextEditorVisibleRanges(listener: (e: vscode.TextEditorVisibleRangesChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
421
				return extHostEditors.onDidChangeTextEditorVisibleRanges(listener, thisArgs, disposables);
422
			},
423 424 425
			onDidChangeTextEditorViewColumn(listener, thisArg?, disposables?) {
				return extHostEditors.onDidChangeTextEditorViewColumn(listener, thisArg, disposables);
			},
426 427 428
			onDidCloseTerminal(listener, thisArg?, disposables?) {
				return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables);
			},
D
Daniel Imms 已提交
429
			onDidOpenTerminal(listener, thisArg?, disposables?) {
430
				return extHostTerminalService.onDidOpenTerminal(listener, thisArg, disposables);
D
Daniel Imms 已提交
431
			},
D
Daniel Imms 已提交
432
			onDidChangeActiveTerminal(listener, thisArg?, disposables?) {
433
				return extHostTerminalService.onDidChangeActiveTerminal(listener, thisArg, disposables);
D
Daniel Imms 已提交
434
			},
435 436 437
			onDidChangeTerminalDimensions(listener, thisArg?, disposables?) {
				return extHostTerminalService.onDidChangeTerminalDimensions(listener, thisArg, disposables);
			},
J
Joao Moreno 已提交
438 439
			get state() {
				return extHostWindow.state;
440
			},
J
Joao Moreno 已提交
441
			onDidChangeWindowState(listener, thisArg?, disposables?) {
J
Joao Moreno 已提交
442
				return extHostWindow.onDidChangeWindowState(listener, thisArg, disposables);
J
Joao Moreno 已提交
443
			},
444
			showInformationMessage(message: string, first: vscode.MessageOptions | string | vscode.MessageItem, ...rest: Array<string | vscode.MessageItem>) {
445
				return extHostMessageService.showMessage(extension, Severity.Info, message, first, rest);
446
			},
447
			showWarningMessage(message: string, first: vscode.MessageOptions | string | vscode.MessageItem, ...rest: Array<string | vscode.MessageItem>) {
448
				return extHostMessageService.showMessage(extension, Severity.Warning, message, first, rest);
449
			},
450
			showErrorMessage(message: string, first: vscode.MessageOptions | string | vscode.MessageItem, ...rest: Array<string | vscode.MessageItem>) {
451
				return extHostMessageService.showMessage(extension, Severity.Error, message, first, rest);
452
			},
C
Christof Marti 已提交
453
			showQuickPick(items: any, options: vscode.QuickPickOptions, token?: vscode.CancellationToken): any {
454
				return extHostQuickOpen.showQuickPick(items, !!extension.enableProposedApi, options, token);
455
			},
456
			showWorkspaceFolderPick(options: vscode.WorkspaceFolderPickOptions) {
457
				return extHostQuickOpen.showWorkspaceFolderPick(options);
458
			},
459
			showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken) {
460
				return extHostQuickOpen.showInput(options, token);
C
Christof Marti 已提交
461
			},
462 463 464 465 466 467
			showOpenDialog(options) {
				return extHostDialogs.showOpenDialog(options);
			},
			showSaveDialog(options) {
				return extHostDialogs.showSaveDialog(options);
			},
468
			createStatusBarItem(position?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem {
B
Benjamin Pasero 已提交
469 470 471 472
				const id = extension.identifier.value;
				const name = nls.localize('extensionLabel', "{0} (Extension)", extension.displayName || extension.name);

				return extHostStatusBar.createStatusBarEntry(id, name, <number>position, priority);
473 474 475 476
			},
			setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): vscode.Disposable {
				return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable);
			},
477
			withScmProgress<R>(task: (progress: vscode.Progress<number>) => Thenable<R>) {
478
				console.warn(`[Deprecation Warning] function 'withScmProgress' is deprecated and should no longer be used. Use 'withProgress' instead.`);
479
				return extHostProgress.withProgress(extension, { location: extHostTypes.ProgressLocation.SourceControl }, (progress, token) => task({ report(n: number) { /*noop*/ } }));
J
Johannes Rieken 已提交
480
			},
481
			withProgress<R>(options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string; worked?: number }>, token: vscode.CancellationToken) => Thenable<R>) {
J
Johannes Rieken 已提交
482
				return extHostProgress.withProgress(extension, options, task);
483
			},
S
Sandeep Somavarapu 已提交
484 485
			createOutputChannel(name: string): vscode.OutputChannel {
				return extHostOutputService.createOutputChannel(name);
486
			},
487
			createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel {
488
				return extHostWebviews.createWebviewPanel(extension, viewType, title, showOptions, options);
489
			},
490 491
			createWebviewTextEditorInset(editor: vscode.TextEditor, range: vscode.Range, options: vscode.WebviewOptions): vscode.WebviewEditorInset {
				checkProposedApiEnabled(extension);
492
				return extHostEditorInsets.createWebviewEditorInset(editor, range, options, extension);
493
			},
494
			createTerminal(nameOrOptions?: vscode.TerminalOptions | string, shellPath?: string, shellArgs?: string[] | string): vscode.Terminal {
495
				if (typeof nameOrOptions === 'object') {
496 497
					nameOrOptions.runInBackground = nameOrOptions.runInBackground && extension.enableProposedApi;
					return extHostTerminalService.createTerminalFromOptions(nameOrOptions);
498
				}
D
Daniel Imms 已提交
499
				return extHostTerminalService.createTerminal(<string>nameOrOptions, shellPath, shellArgs);
500
			},
501
			createTerminalRenderer(name: string): vscode.TerminalRenderer {
502
				return extHostTerminalService.createTerminalRenderer(name);
503
			},
504
			registerTreeDataProvider(viewId: string, treeDataProvider: vscode.TreeDataProvider<any>): vscode.Disposable {
505
				return extHostTreeViews.registerTreeDataProvider(viewId, treeDataProvider, extension);
506
			},
507
			createTreeView(viewId: string, options: { treeDataProvider: vscode.TreeDataProvider<any> }): vscode.TreeView<any> {
508
				return extHostTreeViews.createTreeView(viewId, options, extension);
S
Sandeep Somavarapu 已提交
509
			},
510 511 512
			registerWebviewPanelSerializer: (viewType: string, serializer: vscode.WebviewPanelSerializer) => {
				return extHostWebviews.registerWebviewPanelSerializer(viewType, serializer);
			},
513
			registerDecorationProvider: proposedApiFunction(extension, (provider: vscode.DecorationProvider) => {
514
				return extHostDecorations.registerDecorationProvider(provider, extension.identifier);
M
Matt Bierner 已提交
515
			}),
J
Joao Moreno 已提交
516
			registerUriHandler(handler: vscode.UriHandler) {
517
				return extHostUrls.registerUriHandler(extension.identifier, handler);
J
Joao Moreno 已提交
518
			},
C
Christof Marti 已提交
519
			createQuickPick<T extends vscode.QuickPickItem>(): vscode.QuickPick<T> {
M
Matt Bierner 已提交
520
				return extHostQuickOpen.createQuickPick(extension.identifier, !!extension.enableProposedApi);
C
Christof Marti 已提交
521 522
			},
			createInputBox(): vscode.InputBox {
523
				return extHostQuickOpen.createInputBox(extension.identifier);
524
			}
525
		};
E
Erich Gamma 已提交
526

527 528 529
		// namespace: workspace
		const workspace: typeof vscode.workspace = {
			get rootPath() {
530
				return extHostWorkspace.getPath();
531 532 533 534
			},
			set rootPath(value) {
				throw errors.readonly();
			},
535
			getWorkspaceFolder(resource) {
536
				return extHostWorkspace.getWorkspaceFolder(resource);
537
			},
538
			get workspaceFolders() {
539
				return extHostWorkspace.getWorkspaceFolders();
540
			},
541
			get name() {
542
				return extHostWorkspace.name;
543 544 545 546
			},
			set name(value) {
				throw errors.readonly();
			},
547 548 549 550 551 552
			get workspaceFile() {
				return extHostWorkspace.workspaceFile;
			},
			set workspaceFile(value) {
				throw errors.readonly();
			},
553
			updateWorkspaceFolders: (index, deleteCount, ...workspaceFoldersToAdd) => {
554
				return extHostWorkspace.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
555
			},
556
			onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
557
				return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
558
			},
559
			asRelativePath: (pathOrUri, includeWorkspace?) => {
560
				return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
561 562
			},
			findFiles: (include, exclude, maxResults?, token?) => {
563
				return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(withNullAsUndefined(exclude)), maxResults, extension.identifier, token);
564
			},
565
			findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback: vscode.FindTextInFilesOptions | ((result: vscode.TextSearchResult) => void), callbackOrToken?: vscode.CancellationToken | ((result: vscode.TextSearchResult) => void), token?: vscode.CancellationToken) => {
566 567 568 569 570
				let options: vscode.FindTextInFilesOptions;
				let callback: (result: vscode.TextSearchResult) => void;

				if (typeof optionsOrCallback === 'object') {
					options = optionsOrCallback;
571
					callback = callbackOrToken as (result: vscode.TextSearchResult) => void;
572 573 574
				} else {
					options = {};
					callback = optionsOrCallback;
575
					token = callbackOrToken as vscode.CancellationToken;
576 577
				}

578
				return extHostWorkspace.findTextInFiles(query, options || {}, callback, extension.identifier, token);
R
Rob Lourens 已提交
579
			},
580
			saveAll: (includeUntitled?) => {
581
				return extHostWorkspace.saveAll(includeUntitled);
582
			},
583
			applyEdit(edit: vscode.WorkspaceEdit): Thenable<boolean> {
584
				return extHostEditors.applyWorkspaceEdit(edit);
585 586
			},
			createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
587
				return extHostFileSystemEvent.createFileSystemWatcher(typeConverters.GlobPattern.from(pattern), ignoreCreate, ignoreChange, ignoreDelete);
588 589 590 591 592 593 594
			},
			get textDocuments() {
				return extHostDocuments.getAllDocumentData().map(data => data.document);
			},
			set textDocuments(value) {
				throw errors.readonly();
			},
595
			openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) {
596
				let uriPromise: Thenable<URI>;
B
Benjamin Pasero 已提交
597

598
				const options = uriOrFileNameOrOptions as { language?: string; content?: string; };
B
Benjamin Pasero 已提交
599
				if (typeof uriOrFileNameOrOptions === 'string') {
600
					uriPromise = Promise.resolve(URI.file(uriOrFileNameOrOptions));
B
Benjamin Pasero 已提交
601
				} else if (uriOrFileNameOrOptions instanceof URI) {
602
					uriPromise = Promise.resolve(uriOrFileNameOrOptions);
B
Benjamin Pasero 已提交
603 604
				} else if (!options || typeof options === 'object') {
					uriPromise = extHostDocuments.createDocumentData(options);
605
				} else {
B
Benjamin Pasero 已提交
606
					throw new Error('illegal argument - uriOrFileNameOrOptions');
607
				}
B
Benjamin Pasero 已提交
608 609 610

				return uriPromise.then(uri => {
					return extHostDocuments.ensureDocumentData(uri).then(() => {
M
Matt Bierner 已提交
611
						return extHostDocuments.getDocument(uri);
B
Benjamin Pasero 已提交
612
					});
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
				});
			},
			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?) => {
628
				return extHostDocumentSaveParticipant.getOnWillSaveTextDocumentEvent(extension)(listener, thisArgs, disposables);
629
			},
630
			onDidChangeConfiguration: (listener: (_: any) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
631
				return configProvider.onDidChangeConfiguration(listener, thisArgs, disposables);
632
			},
633
			getConfiguration(section?: string, resource?: vscode.Uri): vscode.WorkspaceConfiguration {
R
Rob Lourens 已提交
634
				resource = arguments.length === 1 ? undefined : resource;
635
				return configProvider.getConfiguration(section, resource, extension.identifier);
636
			},
637 638
			registerTextDocumentContentProvider(scheme: string, provider: vscode.TextDocumentContentProvider) {
				return extHostDocumentContentProviders.registerTextDocumentContentProvider(scheme, provider);
639
			},
640
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
641
				return extHostTask.registerTaskProvider(extension, provider);
J
Johannes Rieken 已提交
642
			},
643
			registerFileSystemProvider(scheme, provider, options) {
644
				return extHostFileSystem.registerFileSystemProvider(scheme, provider, options);
645
			},
B
Benjamin Pasero 已提交
646
			registerFileSearchProvider: proposedApiFunction(extension, (scheme: string, provider: vscode.FileSearchProvider) => {
647
				return extHostSearch.registerFileSearchProvider(scheme, provider);
M
Matt Bierner 已提交
648
			}),
B
Benjamin Pasero 已提交
649
			registerTextSearchProvider: proposedApiFunction(extension, (scheme: string, provider: vscode.TextSearchProvider) => {
650 651
				return extHostSearch.registerTextSearchProvider(scheme, provider);
			}),
652
			registerDocumentCommentProvider: proposedApiFunction(extension, (provider: vscode.DocumentCommentProvider) => {
653
				return extHostComment.registerDocumentCommentProvider(extension.identifier, provider);
654 655
			}),
			registerWorkspaceCommentProvider: proposedApiFunction(extension, (provider: vscode.WorkspaceCommentProvider) => {
656
				return extHostComment.registerWorkspaceCommentProvider(extension.identifier, provider);
657
			}),
A
Alex Dima 已提交
658 659 660
			registerRemoteAuthorityResolver: proposedApiFunction(extension, (authorityPrefix: string, resolver: vscode.RemoteAuthorityResolver) => {
				return extensionService.registerRemoteAuthorityResolver(authorityPrefix, resolver);
			}),
661 662 663
			registerResourceLabelFormatter: proposedApiFunction(extension, (formatter: vscode.ResourceLabelFormatter) => {
				return extHostFileSystem.registerResourceLabelFormatter(formatter);
			}),
J
Johannes Rieken 已提交
664
			onDidRenameFile: proposedApiFunction(extension, (listener: (e: vscode.FileRenameEvent) => any, thisArg?: any, disposables?: vscode.Disposable[]) => {
665
				return extHostFileSystemEvent.onDidRenameFile(listener, thisArg, disposables);
666
			}),
J
Johannes Rieken 已提交
667
			onWillRenameFile: proposedApiFunction(extension, (listener: (e: vscode.FileWillRenameEvent) => any, thisArg?: any, disposables?: vscode.Disposable[]) => {
668
				return extHostFileSystemEvent.getOnWillRenameFileEvent(extension)(listener, thisArg, disposables);
J
Johannes Rieken 已提交
669
			})
670
		};
671

672 673
		// namespace: scm
		const scm: typeof vscode.scm = {
674
			get inputBox() {
675
				return extHostSCM.getLastInputBox(extension)!; // Strict null override - Deprecated api
676
			},
J
Joao Moreno 已提交
677 678
			createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
				return extHostSCM.createSourceControl(extension, id, label, rootUri);
J
Joao Moreno 已提交
679
			}
680
		};
J
Joao Moreno 已提交
681

682
		const comment: typeof vscode.comment = {
P
Peng Lyu 已提交
683 684
			createCommentController(id: string, label: string) {
				return extHostComment.createCommentController(extension, id, label);
685
			}
J
Joao Moreno 已提交
686
		};
687

P
Peng Lyu 已提交
688 689
		const comments = comment;

690 691
		// namespace: debug
		const debug: typeof vscode.debug = {
692 693 694
			get activeDebugSession() {
				return extHostDebugService.activeDebugSession;
			},
695 696
			get activeDebugConsole() {
				return extHostDebugService.activeDebugConsole;
697
			},
698 699
			get breakpoints() {
				return extHostDebugService.breakpoints;
700
			},
701 702 703
			onDidStartDebugSession(listener, thisArg?, disposables?) {
				return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
			},
704
			onDidTerminateDebugSession(listener, thisArg?, disposables?) {
705
				return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
706
			},
A
Andre Weinand 已提交
707
			onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
708
				return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
A
Andre Weinand 已提交
709 710
			},
			onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
A
Andre Weinand 已提交
711
				return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
712
			},
713
			onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
714 715
				return extHostDebugService.onDidChangeBreakpoints(listener, thisArgs, disposables);
			},
A
Andre Weinand 已提交
716
			registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) {
717
				return extHostDebugService.registerDebugConfigurationProvider(debugType, provider);
718
			},
A
Andre Weinand 已提交
719 720
			registerDebugAdapterDescriptorFactory(debugType: string, factory: vscode.DebugAdapterDescriptorFactory) {
				return extHostDebugService.registerDebugAdapterDescriptorFactory(extension, debugType, factory);
721
			},
A
Andre Weinand 已提交
722 723
			registerDebugAdapterTrackerFactory(debugType: string, factory: vscode.DebugAdapterTrackerFactory) {
				return extHostDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
724
			},
725 726
			startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration, parentSession?: vscode.DebugSession) {
				return extHostDebugService.startDebugging(folder, nameOrConfig, parentSession);
727 728
			},
			addBreakpoints(breakpoints: vscode.Breakpoint[]) {
729
				return extHostDebugService.addBreakpoints(breakpoints);
730 731
			},
			removeBreakpoints(breakpoints: vscode.Breakpoint[]) {
732
				return extHostDebugService.removeBreakpoints(breakpoints);
733
			}
734 735
		};

D
Dirk Baeumer 已提交
736 737 738 739
		const tasks: typeof vscode.tasks = {
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
				return extHostTask.registerTaskProvider(extension, provider);
			},
740
			fetchTasks: (filter?: vscode.TaskFilter): Thenable<vscode.Task[]> => {
D
Dirk Baeumer 已提交
741
				return extHostTask.fetchTasks(filter);
742 743
			},
			executeTask: (task: vscode.Task): Thenable<vscode.TaskExecution> => {
D
Dirk Baeumer 已提交
744
				return extHostTask.executeTask(extension, task);
745
			},
D
Dirk Baeumer 已提交
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
			get taskExecutions(): vscode.TaskExecution[] {
				return extHostTask.taskExecutions;
			},
			onDidStartTask: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidStartTask(listeners, thisArgs, disposables);
			},
			onDidEndTask: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidEndTask(listeners, thisArgs, disposables);
			},
			onDidStartTaskProcess: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidStartTaskProcess(listeners, thisArgs, disposables);
			},
			onDidEndTaskProcess: (listeners, thisArgs?, disposables?) => {
				return extHostTask.onDidEndTaskProcess(listeners, thisArgs, disposables);
			}
		};
762

763
		return <typeof vscode>{
764
			version: initData.version,
765 766
			// namespaces
			commands,
767
			debug,
768 769 770
			env,
			extensions,
			languages,
J
Joao Moreno 已提交
771
			scm,
772
			comment,
P
Peng Lyu 已提交
773
			comments,
D
Dirk Baeumer 已提交
774
			tasks,
775 776
			window,
			workspace,
777
			// types
778
			Breakpoint: extHostTypes.Breakpoint,
779
			CancellationTokenSource: CancellationTokenSource,
780
			CodeAction: extHostTypes.CodeAction,
M
Matt Bierner 已提交
781
			CodeActionKind: extHostTypes.CodeActionKind,
782
			CodeActionTrigger: extHostTypes.CodeActionTrigger,
783
			CodeLens: extHostTypes.CodeLens,
R
Rob DeLine 已提交
784
			CodeInset: extHostTypes.CodeInset,
785
			Color: extHostTypes.Color,
786
			ColorInformation: extHostTypes.ColorInformation,
787 788
			ColorPresentation: extHostTypes.ColorPresentation,
			CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState,
P
Peng Lyu 已提交
789
			CommentMode: extHostTypes.CommentMode,
790 791 792
			CompletionItem: extHostTypes.CompletionItem,
			CompletionItemKind: extHostTypes.CompletionItemKind,
			CompletionList: extHostTypes.CompletionList,
M
Matt Bierner 已提交
793
			CompletionTriggerKind: extHostTypes.CompletionTriggerKind,
794
			ConfigurationTarget: extHostTypes.ConfigurationTarget,
795
			DebugAdapterExecutable: extHostTypes.DebugAdapterExecutable,
796
			DebugAdapterServer: extHostTypes.DebugAdapterServer,
797
			DecorationRangeBehavior: extHostTypes.DecorationRangeBehavior,
798
			Diagnostic: extHostTypes.Diagnostic,
799
			DiagnosticRelatedInformation: extHostTypes.DiagnosticRelatedInformation,
800
			DiagnosticSeverity: extHostTypes.DiagnosticSeverity,
801
			DiagnosticTag: extHostTypes.DiagnosticTag,
802 803 804
			Disposable: extHostTypes.Disposable,
			DocumentHighlight: extHostTypes.DocumentHighlight,
			DocumentHighlightKind: extHostTypes.DocumentHighlightKind,
805
			DocumentLink: extHostTypes.DocumentLink,
806 807
			DocumentSymbol: extHostTypes.DocumentSymbol,
			EndOfLine: extHostTypes.EndOfLine,
808
			EventEmitter: Emitter,
809
			ExtensionExecutionContext: extHostTypes.ExtensionExecutionContext,
G
Gabriel DeBacker 已提交
810
			CustomExecution: extHostTypes.CustomExecution,
811 812 813 814 815
			FileChangeType: extHostTypes.FileChangeType,
			FileSystemError: extHostTypes.FileSystemError,
			FileType: files.FileType,
			FoldingRange: extHostTypes.FoldingRange,
			FoldingRangeKind: extHostTypes.FoldingRangeKind,
816
			FunctionBreakpoint: extHostTypes.FunctionBreakpoint,
817
			Hover: extHostTypes.Hover,
818
			IndentAction: languageConfiguration.IndentAction,
819
			Location: extHostTypes.Location,
820
			LogLevel: extHostTypes.LogLevel,
821
			MarkdownString: extHostTypes.MarkdownString,
822
			OverviewRulerLane: OverviewRulerLane,
823 824
			ParameterInformation: extHostTypes.ParameterInformation,
			Position: extHostTypes.Position,
825 826
			ProcessExecution: extHostTypes.ProcessExecution,
			ProgressLocation: extHostTypes.ProgressLocation,
827
			QuickInputButtons: extHostTypes.QuickInputButtons,
828
			Range: extHostTypes.Range,
829
			RelativePattern: extHostTypes.RelativePattern,
A
Alex Dima 已提交
830
			ResolvedAuthority: extHostTypes.ResolvedAuthority,
A
Tweaks  
Alex Dima 已提交
831
			RemoteAuthorityResolverError: extHostTypes.RemoteAuthorityResolverError,
832
			Selection: extHostTypes.Selection,
833
			SelectionRange: extHostTypes.SelectionRange,
834 835
			ShellExecution: extHostTypes.ShellExecution,
			ShellQuoting: extHostTypes.ShellQuoting,
M
Matt Bierner 已提交
836
			SignatureHelpTriggerKind: extHostTypes.SignatureHelpTriggerKind,
837 838 839
			SignatureHelp: extHostTypes.SignatureHelp,
			SignatureInformation: extHostTypes.SignatureInformation,
			SnippetString: extHostTypes.SnippetString,
840
			SourceBreakpoint: extHostTypes.SourceBreakpoint,
841
			SourceControlInputBoxValidationType: extHostTypes.SourceControlInputBoxValidationType,
842 843 844
			StatusBarAlignment: extHostTypes.StatusBarAlignment,
			SymbolInformation: extHostTypes.SymbolInformation,
			SymbolKind: extHostTypes.SymbolKind,
845
			Task: extHostTypes.Task,
A
Alex Ross 已提交
846
			Task2: extHostTypes.Task,
847 848 849 850
			TaskGroup: extHostTypes.TaskGroup,
			TaskPanelKind: extHostTypes.TaskPanelKind,
			TaskRevealKind: extHostTypes.TaskRevealKind,
			TaskScope: extHostTypes.TaskScope,
851 852
			TextDocumentSaveReason: extHostTypes.TextDocumentSaveReason,
			TextEdit: extHostTypes.TextEdit,
853
			TextEditorCursorStyle: TextEditorCursorStyle,
854
			TextEditorLineNumbersStyle: extHostTypes.TextEditorLineNumbersStyle,
855
			TextEditorRevealType: extHostTypes.TextEditorRevealType,
856
			TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind,
857 858 859
			ThemeColor: extHostTypes.ThemeColor,
			ThemeIcon: extHostTypes.ThemeIcon,
			TreeItem: extHostTypes.TreeItem,
860
			TreeItem2: extHostTypes.TreeItem,
861
			TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState,
862
			Uri: URI,
863 864
			ViewColumn: extHostTypes.ViewColumn,
			WorkspaceEdit: extHostTypes.WorkspaceEdit,
865 866 867
			// proposed
			CallHierarchyDirection: extHostTypes.CallHierarchyDirection,
			CallHierarchyItem: extHostTypes.CallHierarchyItem
868
		};
869
	};
E
Erich Gamma 已提交
870 871 872 873
}

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

A
Alex Dima 已提交
874
	private _extensionService: ExtHostExtensionService;
875
	private _identifier: ExtensionIdentifier;
E
Erich Gamma 已提交
876 877 878

	public id: string;
	public extensionPath: string;
879
	public packageJSON: IExtensionDescription;
E
Erich Gamma 已提交
880

J
Johannes Rieken 已提交
881
	constructor(extensionService: ExtHostExtensionService, description: IExtensionDescription) {
A
Alex Dima 已提交
882
		this._extensionService = extensionService;
883 884
		this._identifier = description.identifier;
		this.id = description.identifier.value;
885
		this.extensionPath = path.normalize(originalFSPath(description.extensionLocation));
E
Erich Gamma 已提交
886 887 888 889
		this.packageJSON = description;
	}

	get isActive(): boolean {
890
		return this._extensionService.isActivated(this._identifier);
E
Erich Gamma 已提交
891 892 893
	}

	get exports(): T {
894
		if (this.packageJSON.api === 'none') {
895
			return undefined!; // Strict nulloverride - Public api
896
		}
897
		return <T>this._extensionService.getExtensionExports(this._identifier);
E
Erich Gamma 已提交
898 899 900
	}

	activate(): Thenable<T> {
901
		return this._extensionService.activateByIdWithErrors(this._identifier, new ExtensionActivatedByAPI(false)).then(() => this.exports);
E
Erich Gamma 已提交
902 903
	}
}