extHost.api.impl.ts 48.5 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
import { ExtHostFileSystem } from 'vs/workbench/api/common/extHostFileSystem';
import { ExtHostFileSystemEventService } from 'vs/workbench/api/common/extHostFileSystemEventService';
36
import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures';
J
Johannes Rieken 已提交
37
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';
68
import { IURITransformer } from 'vs/base/common/uriIpc';
69
import { ExtHostEditorInsets } from 'vs/workbench/api/common/extHostCodeInsets';
E
Erich Gamma 已提交
70

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

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

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

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

		registerEHSearchProviders(extHostSearch, extHostLogService);

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

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

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

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

156
	// Register API-ish commands
157
	ExtHostApiCommands.register(extHostCommands);
158

159
	return function (extension: IExtensionDescription, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode {
160

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

191

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

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

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

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

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

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

474 475 476 477 478 479 480 481 482 483 484 485 486
				if (alignmentOrOptions && typeof alignmentOrOptions !== 'number') {
					id = alignmentOrOptions.id;
					name = alignmentOrOptions.name;
					alignment = alignmentOrOptions.alignment;
					priority = alignmentOrOptions.priority;
				} else {
					id = extension.identifier.value;
					name = nls.localize('extensionLabel', "{0} (Extension)", extension.displayName || extension.name);
					alignment = alignmentOrOptions;
					priority = priority;
				}

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

541 542 543
		// namespace: workspace
		const workspace: typeof vscode.workspace = {
			get rootPath() {
544
				return extHostWorkspace.getPath();
545 546 547 548
			},
			set rootPath(value) {
				throw errors.readonly();
			},
549
			getWorkspaceFolder(resource) {
550
				return extHostWorkspace.getWorkspaceFolder(resource);
551
			},
552
			get workspaceFolders() {
553
				return extHostWorkspace.getWorkspaceFolders();
554
			},
555
			get name() {
556
				return extHostWorkspace.name;
557 558 559 560
			},
			set name(value) {
				throw errors.readonly();
			},
561 562 563 564 565 566
			get workspaceFile() {
				return extHostWorkspace.workspaceFile;
			},
			set workspaceFile(value) {
				throw errors.readonly();
			},
567
			updateWorkspaceFolders: (index, deleteCount, ...workspaceFoldersToAdd) => {
568
				return extHostWorkspace.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
569
			},
570
			onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
571
				return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
572
			},
573
			asRelativePath: (pathOrUri, includeWorkspace?) => {
574
				return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
575 576
			},
			findFiles: (include, exclude, maxResults?, token?) => {
577
				return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(withNullAsUndefined(exclude)), maxResults, extension.identifier, token);
578
			},
579
			findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback: vscode.FindTextInFilesOptions | ((result: vscode.TextSearchResult) => void), callbackOrToken?: vscode.CancellationToken | ((result: vscode.TextSearchResult) => void), token?: vscode.CancellationToken) => {
580 581 582 583 584
				let options: vscode.FindTextInFilesOptions;
				let callback: (result: vscode.TextSearchResult) => void;

				if (typeof optionsOrCallback === 'object') {
					options = optionsOrCallback;
585
					callback = callbackOrToken as (result: vscode.TextSearchResult) => void;
586 587 588
				} else {
					options = {};
					callback = optionsOrCallback;
589
					token = callbackOrToken as vscode.CancellationToken;
590 591
				}

592
				return extHostWorkspace.findTextInFiles(query, options || {}, callback, extension.identifier, token);
R
Rob Lourens 已提交
593
			},
594
			saveAll: (includeUntitled?) => {
595
				return extHostWorkspace.saveAll(includeUntitled);
596
			},
597
			applyEdit(edit: vscode.WorkspaceEdit): Thenable<boolean> {
598
				return extHostEditors.applyWorkspaceEdit(edit);
599 600
			},
			createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
601
				return extHostFileSystemEvent.createFileSystemWatcher(typeConverters.GlobPattern.from(pattern), ignoreCreate, ignoreChange, ignoreDelete);
602 603 604 605 606 607 608
			},
			get textDocuments() {
				return extHostDocuments.getAllDocumentData().map(data => data.document);
			},
			set textDocuments(value) {
				throw errors.readonly();
			},
609
			openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) {
610
				let uriPromise: Thenable<URI>;
B
Benjamin Pasero 已提交
611

612
				const options = uriOrFileNameOrOptions as { language?: string; content?: string; };
B
Benjamin Pasero 已提交
613
				if (typeof uriOrFileNameOrOptions === 'string') {
614
					uriPromise = Promise.resolve(URI.file(uriOrFileNameOrOptions));
B
Benjamin Pasero 已提交
615
				} else if (uriOrFileNameOrOptions instanceof URI) {
616
					uriPromise = Promise.resolve(uriOrFileNameOrOptions);
B
Benjamin Pasero 已提交
617 618
				} else if (!options || typeof options === 'object') {
					uriPromise = extHostDocuments.createDocumentData(options);
619
				} else {
B
Benjamin Pasero 已提交
620
					throw new Error('illegal argument - uriOrFileNameOrOptions');
621
				}
B
Benjamin Pasero 已提交
622 623 624

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

686 687
		// namespace: scm
		const scm: typeof vscode.scm = {
688
			get inputBox() {
689
				return extHostSCM.getLastInputBox(extension)!; // Strict null override - Deprecated api
690
			},
J
Joao Moreno 已提交
691 692
			createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
				return extHostSCM.createSourceControl(extension, id, label, rootUri);
J
Joao Moreno 已提交
693
			}
694
		};
J
Joao Moreno 已提交
695

696
		const comment: typeof vscode.comment = {
P
Peng Lyu 已提交
697 698
			createCommentController(id: string, label: string) {
				return extHostComment.createCommentController(extension, id, label);
699
			}
J
Joao Moreno 已提交
700
		};
701

P
Peng Lyu 已提交
702 703
		const comments = comment;

704 705
		// namespace: debug
		const debug: typeof vscode.debug = {
706 707 708
			get activeDebugSession() {
				return extHostDebugService.activeDebugSession;
			},
709 710
			get activeDebugConsole() {
				return extHostDebugService.activeDebugConsole;
711
			},
712 713
			get breakpoints() {
				return extHostDebugService.breakpoints;
714
			},
715 716 717
			onDidStartDebugSession(listener, thisArg?, disposables?) {
				return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
			},
718
			onDidTerminateDebugSession(listener, thisArg?, disposables?) {
719
				return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
720
			},
A
Andre Weinand 已提交
721
			onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
722
				return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
A
Andre Weinand 已提交
723 724
			},
			onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
A
Andre Weinand 已提交
725
				return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
726
			},
727
			onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
728 729
				return extHostDebugService.onDidChangeBreakpoints(listener, thisArgs, disposables);
			},
A
Andre Weinand 已提交
730
			registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) {
731
				return extHostDebugService.registerDebugConfigurationProvider(debugType, provider);
732
			},
A
Andre Weinand 已提交
733 734
			registerDebugAdapterDescriptorFactory(debugType: string, factory: vscode.DebugAdapterDescriptorFactory) {
				return extHostDebugService.registerDebugAdapterDescriptorFactory(extension, debugType, factory);
735
			},
A
Andre Weinand 已提交
736 737
			registerDebugAdapterTrackerFactory(debugType: string, factory: vscode.DebugAdapterTrackerFactory) {
				return extHostDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
738
			},
739 740
			startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration, parentSession?: vscode.DebugSession) {
				return extHostDebugService.startDebugging(folder, nameOrConfig, parentSession);
741 742
			},
			addBreakpoints(breakpoints: vscode.Breakpoint[]) {
743
				return extHostDebugService.addBreakpoints(breakpoints);
744 745
			},
			removeBreakpoints(breakpoints: vscode.Breakpoint[]) {
746
				return extHostDebugService.removeBreakpoints(breakpoints);
747
			}
748 749
		};

D
Dirk Baeumer 已提交
750 751 752 753
		const tasks: typeof vscode.tasks = {
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
				return extHostTask.registerTaskProvider(extension, provider);
			},
754
			fetchTasks: (filter?: vscode.TaskFilter): Thenable<vscode.Task[]> => {
D
Dirk Baeumer 已提交
755
				return extHostTask.fetchTasks(filter);
756 757
			},
			executeTask: (task: vscode.Task): Thenable<vscode.TaskExecution> => {
D
Dirk Baeumer 已提交
758
				return extHostTask.executeTask(extension, task);
759
			},
D
Dirk Baeumer 已提交
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
			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);
			}
		};
776

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

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

A
Alex Dima 已提交
888
	private _extensionService: ExtHostExtensionService;
889
	private _identifier: ExtensionIdentifier;
E
Erich Gamma 已提交
890 891 892

	public id: string;
	public extensionPath: string;
893
	public packageJSON: IExtensionDescription;
E
Erich Gamma 已提交
894

J
Johannes Rieken 已提交
895
	constructor(extensionService: ExtHostExtensionService, description: IExtensionDescription) {
A
Alex Dima 已提交
896
		this._extensionService = extensionService;
897 898
		this._identifier = description.identifier;
		this.id = description.identifier.value;
899
		this.extensionPath = path.normalize(originalFSPath(description.extensionLocation));
E
Erich Gamma 已提交
900 901 902 903
		this.packageJSON = description;
	}

	get isActive(): boolean {
904
		return this._extensionService.isActivated(this._identifier);
E
Erich Gamma 已提交
905 906 907
	}

	get exports(): T {
908
		if (this.packageJSON.api === 'none') {
909
			return undefined!; // Strict nulloverride - Public api
910
		}
911
		return <T>this._extensionService.getExtensionExports(this._identifier);
E
Erich Gamma 已提交
912 913 914
	}

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