extHost.api.impl.ts 47.1 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.
 *--------------------------------------------------------------------------------------------*/

A
Alex Dima 已提交
6 7
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import * as errors from 'vs/base/common/errors';
J
Joao Moreno 已提交
8
import { Emitter, Event } from 'vs/base/common/event';
9
import * as path from 'vs/base/common/path';
A
Alex Dima 已提交
10 11 12 13 14 15 16
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 已提交
17
import { ExtHostContext, IInitData, IMainContext, MainContext } from 'vs/workbench/api/common/extHost.protocol';
J
Johannes Rieken 已提交
18 19 20 21 22
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 已提交
23
import { ExtHostDebugService } from 'vs/workbench/api/node/extHostDebugService';
J
Johannes Rieken 已提交
24 25 26 27 28 29 30
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';
31
import { ExtensionActivatedByAPI } from 'vs/workbench/api/common/extHostExtensionActivator';
A
Alex Dima 已提交
32
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
J
Johannes Rieken 已提交
33 34 35 36 37
import { ExtHostFileSystem } from 'vs/workbench/api/common/extHostFileSystem';
import { ExtHostFileSystemEventService } from 'vs/workbench/api/common/extHostFileSystemEventService';
import { ExtHostHeapService } from 'vs/workbench/api/common/extHostHeapService';
import { ExtHostLanguageFeatures, ISchemeTransformer } from 'vs/workbench/api/common/extHostLanguageFeatures';
import { ExtHostLanguages } from 'vs/workbench/api/common/extHostLanguages';
J
Johannes Rieken 已提交
38
import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService';
J
Johannes Rieken 已提交
39
import { ExtHostMessageService } from 'vs/workbench/api/common/extHostMessageService';
40 41
import { ExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
import { LogOutputChannelFactory } from 'vs/workbench/api/node/extHostOutputService';
J
Johannes Rieken 已提交
42 43 44
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 已提交
45
import { ExtHostSearch, registerEHSearchProviders } from 'vs/workbench/api/node/extHostSearch';
J
Johannes Rieken 已提交
46 47
import { ExtHostStatusBar } from 'vs/workbench/api/common/extHostStatusBar';
import { ExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
A
Alex Dima 已提交
48
import { ExtHostTask } from 'vs/workbench/api/node/extHostTask';
J
Johannes Rieken 已提交
49
import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalService';
J
Johannes Rieken 已提交
50 51 52 53 54 55 56 57
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 已提交
58
import { throwProposedApiError, checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
J
Johannes Rieken 已提交
59
import { ProxyIdentifier } from 'vs/workbench/services/extensions/common/proxyIdentifier';
60
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
A
Alex Dima 已提交
61
import * as vscode from 'vscode';
62
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
63
import { originalFSPath } from 'vs/base/common/resources';
64
import { CLIServer } from 'vs/workbench/api/node/extHostCLIServer';
65
import { withNullAsUndefined } from 'vs/base/common/types';
J
Johannes Rieken 已提交
66
import { values } from 'vs/base/common/collections';
A
Alex Dima 已提交
67
import { Schemas } from 'vs/base/common/network';
E
Erich Gamma 已提交
68

69
export interface IExtensionApiFactory {
70
	(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
71 72
}

73
function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
74
	if (extension.enableProposedApi) {
75 76
		return fn;
	} else {
77
		return throwProposedApiError.bind(null, extension) as any as T;
78 79 80
	}
}

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

96
	// Addressable instances
97
	rpcProtocol.set(ExtHostContext.ExtHostLogService, extHostLogService);
A
Alex Dima 已提交
98 99
	const extHostHeapService = rpcProtocol.set(ExtHostContext.ExtHostHeapService, new ExtHostHeapService());
	const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, new ExtHostDecorations(rpcProtocol));
M
Matt Bierner 已提交
100
	const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol));
J
Joao Moreno 已提交
101
	const extHostUrls = rpcProtocol.set(ExtHostContext.ExtHostUrls, new ExtHostUrls(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));
S
Sandeep Somavarapu 已提交
108
	const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands, extHostLogService));
A
Alex Dima 已提交
109 110 111
	rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
	rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
	const extHostDiagnostics = rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(rpcProtocol));
112
	const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, schemeTransformer, extHostDocuments, extHostCommands, extHostHeapService, extHostDiagnostics, extHostLogService));
113
	const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
114
	const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, extHostDocumentsAndEditors));
A
Alex Dima 已提交
115
	const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands));
116
	const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(rpcProtocol, extHostConfiguration, extHostLogService));
117
	const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(rpcProtocol, extHostWorkspace, extensionService, extHostDocumentsAndEditors, extHostConfiguration, extHostTerminalService, extHostCommands));
118
	const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));
P
Peng Lyu 已提交
119
	const extHostComment = rpcProtocol.set(ExtHostContext.ExtHostComments, new ExtHostComments(rpcProtocol, extHostCommands, extHostDocuments));
R
Rob Lourens 已提交
120
	const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, new ExtHostSearch(rpcProtocol, schemeTransformer, extHostLogService));
121
	const extHostTask = rpcProtocol.set(ExtHostContext.ExtHostTask, new ExtHostTask(rpcProtocol, extHostWorkspace, extHostDocumentsAndEditors, extHostConfiguration, extHostTerminalService));
A
Alex Dima 已提交
122 123
	const extHostWindow = rpcProtocol.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(rpcProtocol));
	rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
124
	const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
125
	const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, new ExtHostOutputService(LogOutputChannelFactory, initData.logsLocation, rpcProtocol));
126
	rpcProtocol.set(ExtHostContext.ExtHostStorage, extHostStorage);
127
	if (initData.remoteAuthority) {
A
Alex Dima 已提交
128 129 130 131 132 133 134 135
		extHostTask.registerTaskSystem(Schemas.vscodeRemote, {
			scheme: Schemas.vscodeRemote,
			authority: initData.remoteAuthority,
			platform: process.platform
		});

		registerEHSearchProviders(extHostSearch, extHostLogService);

136 137 138
		const cliServer = new CLIServer(extHostCommands);
		process.env['VSCODE_IPC_HOOK_CLI'] = cliServer.ipcHandlePath;
	}
139 140

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

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

151
	// Register an output channel for exthost log
A
Alex Dima 已提交
152
	extHostOutputService.createOutputChannelFromLogFile(outputChannelName, extHostLogService.logFile);
153

154
	// Register API-ish commands
155
	ExtHostApiCommands.register(extHostCommands);
156

157
	return function (extension: IExtensionDescription, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode {
158

159 160 161 162 163
		// Check document selectors for being overly generic. Technically this isn't a problem but
		// in practice many extensions say they support `fooLang` but need fs-access to do so. Those
		// extension should specify then the `file`-scheme, e.g `{ scheme: 'fooLang', language: 'fooLang' }`
		// We only inform once, it is not a warning because we just want to raise awareness and because
		// we cannot say if the extension is doing it right or wrong...
164
		const checkSelector = (function () {
A
Alex Dima 已提交
165
			let done = (!extension.isUnderDevelopment);
166 167
			function informOnce(selector: vscode.DocumentSelector) {
				if (!done) {
168
					console.info(`Extension '${extension.identifier.value}' uses a document selector without scheme. Learn more about this: https://go.microsoft.com/fwlink/?linkid=872305`);
169 170
					done = true;
				}
171
			}
172
			return function perform(selector: vscode.DocumentSelector): vscode.DocumentSelector {
173 174 175 176 177 178 179 180 181 182
				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);
183 184 185 186 187
					}
				}
				return selector;
			};
		})();
188

189

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

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

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

260 261
		// namespace: extensions
		const extensions: typeof vscode.extensions = {
262 263
			getExtension(extensionId: string): Extension<any> | undefined {
				const desc = extensionRegistry.getExtensionDescription(extensionId);
264 265 266
				if (desc) {
					return new Extension(extensionService, desc);
				}
267
				return undefined;
268 269
			},
			get all(): Extension<any>[] {
A
Alex Dima 已提交
270
				return extensionRegistry.getAllExtensionDescriptions().map((desc) => new Extension(extensionService, desc));
271 272 273
			},
			get onDidChange() {
				return extensionRegistry.onDidChange;
E
Erich Gamma 已提交
274
			}
275
		};
E
Erich Gamma 已提交
276

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

376 377 378 379 380 381 382 383
		// namespace: window
		const window: typeof vscode.window = {
			get activeTextEditor() {
				return extHostEditors.getActiveTextEditor();
			},
			get visibleTextEditors() {
				return extHostEditors.getVisibleTextEditors();
			},
384
			get activeTerminal() {
D
Daniel Imms 已提交
385
				return extHostTerminalService.activeTerminal;
386
			},
D
Daniel Imms 已提交
387
			get terminals() {
D
Daniel Imms 已提交
388
				return extHostTerminalService.terminals;
D
Daniel Imms 已提交
389
			},
390
			showTextDocument(documentOrUri: vscode.TextDocument | vscode.Uri, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, preserveFocus?: boolean): Thenable<vscode.TextEditor> {
391
				let documentPromise: Promise<vscode.TextDocument>;
J
Johannes Rieken 已提交
392
				if (URI.isUri(documentOrUri)) {
393
					documentPromise = Promise.resolve(workspace.openTextDocument(documentOrUri));
B
Benjamin Pasero 已提交
394
				} else {
395
					documentPromise = Promise.resolve(<vscode.TextDocument>documentOrUri);
B
Benjamin Pasero 已提交
396 397 398 399
				}
				return documentPromise.then(document => {
					return extHostEditors.showTextDocument(document, columnOrOptions, preserveFocus);
				});
400 401 402 403
			},
			createTextEditorDecorationType(options: vscode.DecorationRenderOptions): vscode.TextEditorDecorationType {
				return extHostEditors.createTextEditorDecorationType(options);
			},
404 405 406
			onDidChangeActiveTextEditor(listener, thisArg?, disposables?) {
				return extHostEditors.onDidChangeActiveTextEditor(listener, thisArg, disposables);
			},
407 408 409
			onDidChangeVisibleTextEditors(listener, thisArg, disposables) {
				return extHostEditors.onDidChangeVisibleTextEditors(listener, thisArg, disposables);
			},
410
			onDidChangeTextEditorSelection(listener: (e: vscode.TextEditorSelectionChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
411 412
				return extHostEditors.onDidChangeTextEditorSelection(listener, thisArgs, disposables);
			},
413
			onDidChangeTextEditorOptions(listener: (e: vscode.TextEditorOptionsChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
414 415
				return extHostEditors.onDidChangeTextEditorOptions(listener, thisArgs, disposables);
			},
416
			onDidChangeTextEditorVisibleRanges(listener: (e: vscode.TextEditorVisibleRangesChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) {
417
				return extHostEditors.onDidChangeTextEditorVisibleRanges(listener, thisArgs, disposables);
418
			},
419 420 421
			onDidChangeTextEditorViewColumn(listener, thisArg?, disposables?) {
				return extHostEditors.onDidChangeTextEditorViewColumn(listener, thisArg, disposables);
			},
422 423 424
			onDidCloseTerminal(listener, thisArg?, disposables?) {
				return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables);
			},
D
Daniel Imms 已提交
425
			onDidOpenTerminal(listener, thisArg?, disposables?) {
426
				return extHostTerminalService.onDidOpenTerminal(listener, thisArg, disposables);
D
Daniel Imms 已提交
427
			},
D
Daniel Imms 已提交
428
			onDidChangeActiveTerminal(listener, thisArg?, disposables?) {
429
				return extHostTerminalService.onDidChangeActiveTerminal(listener, thisArg, disposables);
D
Daniel Imms 已提交
430
			},
431 432 433
			onDidChangeTerminalDimensions(listener, thisArg?, disposables?) {
				return extHostTerminalService.onDidChangeTerminalDimensions(listener, thisArg, disposables);
			},
J
Joao Moreno 已提交
434 435
			get state() {
				return extHostWindow.state;
436
			},
J
Joao Moreno 已提交
437
			onDidChangeWindowState(listener, thisArg?, disposables?) {
J
Joao Moreno 已提交
438
				return extHostWindow.onDidChangeWindowState(listener, thisArg, disposables);
J
Joao Moreno 已提交
439
			},
440
			showInformationMessage(message: string, first: vscode.MessageOptions | string | vscode.MessageItem, ...rest: Array<string | vscode.MessageItem>) {
441
				return extHostMessageService.showMessage(extension, Severity.Info, message, first, rest);
442
			},
443
			showWarningMessage(message: string, first: vscode.MessageOptions | string | vscode.MessageItem, ...rest: Array<string | vscode.MessageItem>) {
444
				return extHostMessageService.showMessage(extension, Severity.Warning, message, first, rest);
445
			},
446
			showErrorMessage(message: string, first: vscode.MessageOptions | string | vscode.MessageItem, ...rest: Array<string | vscode.MessageItem>) {
447
				return extHostMessageService.showMessage(extension, Severity.Error, message, first, rest);
448
			},
C
Christof Marti 已提交
449
			showQuickPick(items: any, options: vscode.QuickPickOptions, token?: vscode.CancellationToken): any {
450
				return extHostQuickOpen.showQuickPick(items, !!extension.enableProposedApi, options, token);
451
			},
452
			showWorkspaceFolderPick(options: vscode.WorkspaceFolderPickOptions) {
453
				return extHostQuickOpen.showWorkspaceFolderPick(options);
454
			},
455
			showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken) {
456
				return extHostQuickOpen.showInput(options, token);
C
Christof Marti 已提交
457
			},
458 459 460 461 462 463
			showOpenDialog(options) {
				return extHostDialogs.showOpenDialog(options);
			},
			showSaveDialog(options) {
				return extHostDialogs.showSaveDialog(options);
			},
464
			createStatusBarItem(position?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem {
465
				return extHostStatusBar.createStatusBarEntry(extension.identifier, <number>position, priority);
466 467 468 469
			},
			setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): vscode.Disposable {
				return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable);
			},
470
			withScmProgress<R>(task: (progress: vscode.Progress<number>) => Thenable<R>) {
471
				console.warn(`[Deprecation Warning] function 'withScmProgress' is deprecated and should no longer be used. Use 'withProgress' instead.`);
472
				return extHostProgress.withProgress(extension, { location: extHostTypes.ProgressLocation.SourceControl }, (progress, token) => task({ report(n: number) { /*noop*/ } }));
J
Johannes Rieken 已提交
473
			},
474
			withProgress<R>(options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string; worked?: number }>, token: vscode.CancellationToken) => Thenable<R>) {
J
Johannes Rieken 已提交
475
				return extHostProgress.withProgress(extension, options, task);
476
			},
S
Sandeep Somavarapu 已提交
477 478
			createOutputChannel(name: string): vscode.OutputChannel {
				return extHostOutputService.createOutputChannel(name);
479
			},
480
			createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel {
481
				return extHostWebviews.createWebviewPanel(extension, viewType, title, showOptions, options);
482
			},
483
			createTerminal(nameOrOptions?: vscode.TerminalOptions | string, shellPath?: string, shellArgs?: string[] | string): vscode.Terminal {
484 485 486
				if (typeof nameOrOptions === 'object') {
					return extHostTerminalService.createTerminalFromOptions(<vscode.TerminalOptions>nameOrOptions);
				}
D
Daniel Imms 已提交
487
				return extHostTerminalService.createTerminal(<string>nameOrOptions, shellPath, shellArgs);
488
			},
489
			createTerminalRenderer(name: string): vscode.TerminalRenderer {
490
				return extHostTerminalService.createTerminalRenderer(name);
491
			},
492
			registerTreeDataProvider(viewId: string, treeDataProvider: vscode.TreeDataProvider<any>): vscode.Disposable {
493
				return extHostTreeViews.registerTreeDataProvider(viewId, treeDataProvider, extension);
494
			},
495
			createTreeView(viewId: string, options: { treeDataProvider: vscode.TreeDataProvider<any> }): vscode.TreeView<any> {
496
				return extHostTreeViews.createTreeView(viewId, options, extension);
S
Sandeep Somavarapu 已提交
497
			},
498 499 500
			registerWebviewPanelSerializer: (viewType: string, serializer: vscode.WebviewPanelSerializer) => {
				return extHostWebviews.registerWebviewPanelSerializer(viewType, serializer);
			},
501
			registerDecorationProvider: proposedApiFunction(extension, (provider: vscode.DecorationProvider) => {
502
				return extHostDecorations.registerDecorationProvider(provider, extension.identifier);
M
Matt Bierner 已提交
503
			}),
J
Joao Moreno 已提交
504
			registerUriHandler(handler: vscode.UriHandler) {
505
				return extHostUrls.registerUriHandler(extension.identifier, handler);
J
Joao Moreno 已提交
506
			},
C
Christof Marti 已提交
507
			createQuickPick<T extends vscode.QuickPickItem>(): vscode.QuickPick<T> {
M
Matt Bierner 已提交
508
				return extHostQuickOpen.createQuickPick(extension.identifier, !!extension.enableProposedApi);
C
Christof Marti 已提交
509 510
			},
			createInputBox(): vscode.InputBox {
511
				return extHostQuickOpen.createInputBox(extension.identifier);
512
			}
513
		};
E
Erich Gamma 已提交
514

515 516 517
		// namespace: workspace
		const workspace: typeof vscode.workspace = {
			get rootPath() {
518
				return extHostWorkspace.getPath();
519 520 521 522
			},
			set rootPath(value) {
				throw errors.readonly();
			},
523
			getWorkspaceFolder(resource) {
524
				return extHostWorkspace.getWorkspaceFolder(resource);
525
			},
526
			get workspaceFolders() {
527
				return extHostWorkspace.getWorkspaceFolders();
528
			},
529
			get name() {
530
				return extHostWorkspace.name;
531 532 533 534
			},
			set name(value) {
				throw errors.readonly();
			},
535
			updateWorkspaceFolders: (index, deleteCount, ...workspaceFoldersToAdd) => {
536
				return extHostWorkspace.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
537
			},
538
			onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
539
				return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
540
			},
541
			asRelativePath: (pathOrUri, includeWorkspace?) => {
542
				return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
543 544
			},
			findFiles: (include, exclude, maxResults?, token?) => {
545
				return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(withNullAsUndefined(exclude)), maxResults, extension.identifier, token);
546
			},
547
			findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback: vscode.FindTextInFilesOptions | ((result: vscode.TextSearchResult) => void), callbackOrToken?: vscode.CancellationToken | ((result: vscode.TextSearchResult) => void), token?: vscode.CancellationToken) => {
548 549 550 551 552
				let options: vscode.FindTextInFilesOptions;
				let callback: (result: vscode.TextSearchResult) => void;

				if (typeof optionsOrCallback === 'object') {
					options = optionsOrCallback;
553
					callback = callbackOrToken as (result: vscode.TextSearchResult) => void;
554 555 556
				} else {
					options = {};
					callback = optionsOrCallback;
557
					token = callbackOrToken as vscode.CancellationToken;
558 559
				}

560
				return extHostWorkspace.findTextInFiles(query, options || {}, callback, extension.identifier, token);
R
Rob Lourens 已提交
561
			},
562
			saveAll: (includeUntitled?) => {
563
				return extHostWorkspace.saveAll(includeUntitled);
564
			},
565
			applyEdit(edit: vscode.WorkspaceEdit): Thenable<boolean> {
566
				return extHostEditors.applyWorkspaceEdit(edit);
567 568
			},
			createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
569
				return extHostFileSystemEvent.createFileSystemWatcher(typeConverters.GlobPattern.from(pattern), ignoreCreate, ignoreChange, ignoreDelete);
570 571 572 573 574 575 576
			},
			get textDocuments() {
				return extHostDocuments.getAllDocumentData().map(data => data.document);
			},
			set textDocuments(value) {
				throw errors.readonly();
			},
577
			openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) {
578
				let uriPromise: Thenable<URI>;
B
Benjamin Pasero 已提交
579

580
				const options = uriOrFileNameOrOptions as { language?: string; content?: string; };
B
Benjamin Pasero 已提交
581
				if (typeof uriOrFileNameOrOptions === 'string') {
582
					uriPromise = Promise.resolve(URI.file(uriOrFileNameOrOptions));
B
Benjamin Pasero 已提交
583
				} else if (uriOrFileNameOrOptions instanceof URI) {
584
					uriPromise = Promise.resolve(uriOrFileNameOrOptions);
B
Benjamin Pasero 已提交
585 586
				} else if (!options || typeof options === 'object') {
					uriPromise = extHostDocuments.createDocumentData(options);
587
				} else {
B
Benjamin Pasero 已提交
588
					throw new Error('illegal argument - uriOrFileNameOrOptions');
589
				}
B
Benjamin Pasero 已提交
590 591 592

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

654 655
		// namespace: scm
		const scm: typeof vscode.scm = {
656
			get inputBox() {
657
				return extHostSCM.getLastInputBox(extension)!; // Strict null override - Deprecated api
658
			},
J
Joao Moreno 已提交
659 660
			createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
				return extHostSCM.createSourceControl(extension, id, label, rootUri);
J
Joao Moreno 已提交
661
			}
662
		};
J
Joao Moreno 已提交
663

664
		const comment: typeof vscode.comment = {
P
Peng Lyu 已提交
665 666
			createCommentController(id: string, label: string) {
				return extHostComment.createCommentController(extension, id, label);
667
			}
J
Joao Moreno 已提交
668
		};
669

670 671
		// namespace: debug
		const debug: typeof vscode.debug = {
672 673 674
			get activeDebugSession() {
				return extHostDebugService.activeDebugSession;
			},
675 676
			get activeDebugConsole() {
				return extHostDebugService.activeDebugConsole;
677
			},
678 679
			get breakpoints() {
				return extHostDebugService.breakpoints;
680
			},
681 682 683
			onDidStartDebugSession(listener, thisArg?, disposables?) {
				return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
			},
684
			onDidTerminateDebugSession(listener, thisArg?, disposables?) {
685
				return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
686
			},
A
Andre Weinand 已提交
687
			onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
688
				return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
A
Andre Weinand 已提交
689 690
			},
			onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
A
Andre Weinand 已提交
691
				return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
692
			},
693
			onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
694 695
				return extHostDebugService.onDidChangeBreakpoints(listener, thisArgs, disposables);
			},
A
Andre Weinand 已提交
696
			registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) {
697
				return extHostDebugService.registerDebugConfigurationProvider(debugType, provider);
698
			},
A
Andre Weinand 已提交
699 700
			registerDebugAdapterDescriptorFactory(debugType: string, factory: vscode.DebugAdapterDescriptorFactory) {
				return extHostDebugService.registerDebugAdapterDescriptorFactory(extension, debugType, factory);
701
			},
A
Andre Weinand 已提交
702 703
			registerDebugAdapterTrackerFactory(debugType: string, factory: vscode.DebugAdapterTrackerFactory) {
				return extHostDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
704
			},
705 706
			startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration, parentSession?: vscode.DebugSession) {
				return extHostDebugService.startDebugging(folder, nameOrConfig, parentSession);
707 708
			},
			addBreakpoints(breakpoints: vscode.Breakpoint[]) {
709
				return extHostDebugService.addBreakpoints(breakpoints);
710 711
			},
			removeBreakpoints(breakpoints: vscode.Breakpoint[]) {
712
				return extHostDebugService.removeBreakpoints(breakpoints);
713
			}
714 715
		};

D
Dirk Baeumer 已提交
716 717 718 719
		const tasks: typeof vscode.tasks = {
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
				return extHostTask.registerTaskProvider(extension, provider);
			},
720
			fetchTasks: (filter?: vscode.TaskFilter): Thenable<vscode.Task[]> => {
D
Dirk Baeumer 已提交
721
				return extHostTask.fetchTasks(filter);
722 723
			},
			executeTask: (task: vscode.Task): Thenable<vscode.TaskExecution> => {
D
Dirk Baeumer 已提交
724
				return extHostTask.executeTask(extension, task);
725
			},
D
Dirk Baeumer 已提交
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
			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);
			}
		};
742

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

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

A
Alex Dima 已提交
851
	private _extensionService: ExtHostExtensionService;
852
	private _identifier: ExtensionIdentifier;
E
Erich Gamma 已提交
853 854 855

	public id: string;
	public extensionPath: string;
856
	public packageJSON: IExtensionDescription;
E
Erich Gamma 已提交
857

J
Johannes Rieken 已提交
858
	constructor(extensionService: ExtHostExtensionService, description: IExtensionDescription) {
A
Alex Dima 已提交
859
		this._extensionService = extensionService;
860 861
		this._identifier = description.identifier;
		this.id = description.identifier.value;
862
		this.extensionPath = path.normalize(originalFSPath(description.extensionLocation));
E
Erich Gamma 已提交
863 864 865 866
		this.packageJSON = description;
	}

	get isActive(): boolean {
867
		return this._extensionService.isActivated(this._identifier);
E
Erich Gamma 已提交
868 869 870
	}

	get exports(): T {
871
		if (this.packageJSON.api === 'none') {
872
			return undefined!; // Strict nulloverride - Public api
873
		}
874
		return <T>this._extensionService.getExtensionExports(this._identifier);
E
Erich Gamma 已提交
875 876 877
	}

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