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

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';
18
import { ExtHostContext, MainContext, ExtHostLogServiceShape } from 'vs/workbench/api/common/extHost.protocol';
J
Johannes Rieken 已提交
19 20
import { ExtHostApiCommands } from 'vs/workbench/api/common/extHostApiCommands';
import { ExtHostClipboard } from 'vs/workbench/api/common/extHostClipboard';
21
import { IExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
J
Johannes Rieken 已提交
22
import { ExtHostComments } from 'vs/workbench/api/common/extHostComments';
23
import { ExtHostConfigProvider, IExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration';
J
Johannes Rieken 已提交
24 25 26 27 28
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';
29
import { IExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
30
import { ExtensionActivatedByAPI } from 'vs/workbench/api/common/extHostExtensionActivator';
31
import { IExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
J
Johannes Rieken 已提交
32 33
import { ExtHostFileSystem } from 'vs/workbench/api/common/extHostFileSystem';
import { ExtHostFileSystemEventService } from 'vs/workbench/api/common/extHostFileSystemEventService';
34
import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures';
J
Johannes Rieken 已提交
35 36
import { ExtHostLanguages } from 'vs/workbench/api/common/extHostLanguages';
import { ExtHostMessageService } from 'vs/workbench/api/common/extHostMessageService';
37
import { IExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
J
Johannes Rieken 已提交
38 39 40 41
import { ExtHostProgress } from 'vs/workbench/api/common/extHostProgress';
import { ExtHostQuickOpen } from 'vs/workbench/api/common/extHostQuickOpen';
import { ExtHostSCM } from 'vs/workbench/api/common/extHostSCM';
import { ExtHostStatusBar } from 'vs/workbench/api/common/extHostStatusBar';
42
import { IExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
43
import { IExtHostTerminalService } from 'vs/workbench/api/common/extHostTerminalService';
J
Johannes Rieken 已提交
44 45 46 47 48 49 50
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';
51
import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
J
Johannes Rieken 已提交
52
import { throwProposedApiError, checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
J
Johannes Rieken 已提交
53
import { ProxyIdentifier } from 'vs/workbench/services/extensions/common/proxyIdentifier';
54
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
A
Alex Dima 已提交
55
import * as vscode from 'vscode';
56
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
57
import { originalFSPath } from 'vs/base/common/resources';
J
Johannes Rieken 已提交
58
import { values } from 'vs/base/common/collections';
59
import { ExtHostEditorInsets } from 'vs/workbench/api/common/extHostCodeInsets';
60
import { ExtHostLabelService } from 'vs/workbench/api/common/extHostLabelService';
61
import { getRemoteName } from 'vs/platform/remote/common/remoteHosts';
62
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
63
import { IExtHostDecorations } from 'vs/workbench/api/common/extHostDecorations';
64
import { IExtHostTask } from 'vs/workbench/api/common/extHostTask';
65
import { IExtHostDebugService } from 'vs/workbench/api/common/extHostDebugService';
J
Johannes Rieken 已提交
66
import { IExtHostSearch } from 'vs/workbench/api/common/extHostSearch';
67
import { ILogService } from 'vs/platform/log/common/log';
68
import { IURITransformerService } from 'vs/workbench/api/common/extHostUriTransformerService';
69
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
70
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
E
Erich Gamma 已提交
71

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

E
Erich Gamma 已提交
76
/**
77
 * This method instantiates and returns the extension API surface
E
Erich Gamma 已提交
78
 */
79
export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): IExtensionApiFactory {
80

81
	// services
82
	const initData = accessor.get(IExtHostInitDataService);
83
	const extensionService = accessor.get(IExtHostExtensionService);
84 85
	const extHostWorkspace = accessor.get(IExtHostWorkspace);
	const extHostConfiguration = accessor.get(IExtHostConfiguration);
86 87
	const uriTransformer = accessor.get(IURITransformerService);
	const rpcProtocol = accessor.get(IExtHostRpcService);
88
	const extHostStorage = accessor.get(IExtHostStorage);
89
	const extHostLogService = accessor.get(ILogService);
90

91
	// register addressable instances
92
	rpcProtocol.set(ExtHostContext.ExtHostLogService, <ExtHostLogServiceShape><any>extHostLogService);
93 94 95 96 97
	rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
	rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
	rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
	rpcProtocol.set(ExtHostContext.ExtHostStorage, extHostStorage);

J
Johannes Rieken 已提交
98
	// automatically create and register addressable instances
99
	const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, accessor.get(IExtHostDecorations));
J
Johannes Rieken 已提交
100 101 102 103 104 105 106 107 108
	const extHostDocumentsAndEditors = rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, accessor.get(IExtHostDocumentsAndEditors));
	const extHostCommands = rpcProtocol.set(ExtHostContext.ExtHostCommands, accessor.get(IExtHostCommands));
	const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, accessor.get(IExtHostTerminalService));
	const extHostDebugService = rpcProtocol.set(ExtHostContext.ExtHostDebugService, accessor.get(IExtHostDebugService));
	const extHostSearch = rpcProtocol.set(ExtHostContext.ExtHostSearch, accessor.get(IExtHostSearch));
	const extHostTask = rpcProtocol.set(ExtHostContext.ExtHostTask, accessor.get(IExtHostTask));
	const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, accessor.get(IExtHostOutputService));

	// manually create and register addressable instances
M
Matt Bierner 已提交
109
	const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol, initData.environment));
J
Joao Moreno 已提交
110
	const extHostUrls = rpcProtocol.set(ExtHostContext.ExtHostUrls, new ExtHostUrls(rpcProtocol));
A
Alex Dima 已提交
111
	const extHostDocuments = rpcProtocol.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors));
112
	const extHostDocumentContentProviders = rpcProtocol.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(rpcProtocol, extHostDocumentsAndEditors, extHostLogService));
113
	const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostLogService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadTextEditors)));
A
Alex Dima 已提交
114
	const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(rpcProtocol, extHostDocumentsAndEditors));
S
Sandeep Somavarapu 已提交
115
	const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands, extHostLogService));
M
Matt Bierner 已提交
116
	const extHostEditorInsets = rpcProtocol.set(ExtHostContext.ExtHostEditorInsets, new ExtHostEditorInsets(rpcProtocol.getProxy(MainContext.MainThreadEditorInsets), extHostEditors, initData.environment));
A
Alex Dima 已提交
117
	const extHostDiagnostics = rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(rpcProtocol));
118
	const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, uriTransformer, extHostDocuments, extHostCommands, extHostDiagnostics, extHostLogService));
119
	const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
120
	const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, extHostDocumentsAndEditors));
A
Alex Dima 已提交
121
	const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands));
122
	const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));
P
Peng Lyu 已提交
123
	const extHostComment = rpcProtocol.set(ExtHostContext.ExtHostComments, new ExtHostComments(rpcProtocol, extHostCommands, extHostDocuments));
A
Alex Dima 已提交
124
	const extHostWindow = rpcProtocol.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(rpcProtocol));
125
	const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
126
	const extHostLabelService = rpcProtocol.set(ExtHostContext.ExtHosLabelService, new ExtHostLabelService(rpcProtocol));
127

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

132
	// Other instances
133
	const extHostClipboard = new ExtHostClipboard(rpcProtocol);
A
Alex Dima 已提交
134 135 136
	const extHostMessageService = new ExtHostMessageService(rpcProtocol);
	const extHostDialogs = new ExtHostDialogs(rpcProtocol);
	const extHostStatusBar = new ExtHostStatusBar(rpcProtocol);
137
	const extHostLanguages = new ExtHostLanguages(rpcProtocol, extHostDocuments);
138

139
	// Register API-ish commands
140
	ExtHostApiCommands.register(extHostCommands);
141

142
	return function (extension: IExtensionDescription, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode {
143

144 145
		// 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
146
		// extension should specify then the `file`-scheme, e.g. `{ scheme: 'fooLang', language: 'fooLang' }`
147 148
		// 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...
149
		const checkSelector = (function () {
A
Alex Dima 已提交
150
			let done = (!extension.isUnderDevelopment);
151 152
			function informOnce(selector: vscode.DocumentSelector) {
				if (!done) {
153
					console.info(`Extension '${extension.identifier.value}' uses a document selector without scheme. Learn more about this: https://go.microsoft.com/fwlink/?linkid=872305`);
154 155
					done = true;
				}
156
			}
157
			return function perform(selector: vscode.DocumentSelector): vscode.DocumentSelector {
158 159 160 161 162 163 164 165 166 167
				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);
168 169 170 171 172
					}
				}
				return selector;
			};
		})();
173

174

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

					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) => {
197
						console.warn('An error occurred while running command ' + id, err);
198
					});
199
				});
200
			},
201 202
			registerDiffInformationCommand: (id: string, callback: (diff: vscode.LineChange[], ...args: any[]) => any, thisArg?: any): vscode.Disposable => {
				checkProposedApiEnabled(extension);
203
				return extHostCommands.registerCommand(true, id, async (...args: any[]): Promise<any> => {
204
					const activeTextEditor = extHostEditors.getActiveTextEditor();
205 206 207 208 209 210 211 212
					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]);
				});
213
			},
214
			executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
M
Matt Bierner 已提交
215
				return extHostCommands.executeCommand<T>(id, ...args);
216
			},
217 218
			getCommands(filterInternal: boolean = false): Thenable<string[]> {
				return extHostCommands.getCommands(filterInternal);
219
			}
220
		};
221

222
		// namespace: env
223
		const env: typeof vscode.env = {
224 225
			get machineId() { return initData.telemetryInfo.machineId; },
			get sessionId() { return initData.telemetryInfo.sessionId; },
226 227
			get language() { return initData.environment.appLanguage; },
			get appName() { return initData.environment.appName; },
228
			get appRoot() { return initData.environment.appRoot!.fsPath; },
229
			get uriScheme() { return initData.environment.appUriScheme; },
230 231 232 233
			createAppUri(options?) {
				checkProposedApiEnabled(extension);
				return extHostUrls.createAppUri(extension.identifier, options);
			},
234 235
			get logLevel() {
				checkProposedApiEnabled(extension);
236
				return typeConverters.LogLevel.to(extHostLogService.getLevel());
237 238 239
			},
			get onDidChangeLogLevel() {
				checkProposedApiEnabled(extension);
J
Joao Moreno 已提交
240
				return Event.map(extHostLogService.onDidChangeLogLevel, l => typeConverters.LogLevel.to(l));
241 242 243
			},
			get clipboard(): vscode.Clipboard {
				return extHostClipboard;
244
			},
D
Daniel Imms 已提交
245
			get shell() {
246
				return extHostTerminalService.getDefaultShell(false, configProvider);
D
Daniel Imms 已提交
247
			},
J
Johannes Rieken 已提交
248
			openExternal(uri: URI) {
249
				return extHostWindow.openUri(uri, { allowTunneling: !!initData.remote.isRemote });
250
			},
251
			get remoteName() {
252
				return getRemoteName(initData.remote.authority);
253
			}
254 255 256 257 258
		};
		if (!initData.environment.extensionTestsLocationURI) {
			// allow to patch env-function when running tests
			Object.freeze(env);
		}
E
Erich Gamma 已提交
259

260 261 262 263
		const extensionKind = initData.remote.isRemote
			? extHostTypes.ExtensionKind.Workspace
			: extHostTypes.ExtensionKind.UI;

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

281 282 283 284 285
		// namespace: languages
		const languages: typeof vscode.languages = {
			createDiagnosticCollection(name?: string): vscode.DiagnosticCollection {
				return extHostDiagnostics.createDiagnosticCollection(name);
			},
286 287 288
			get onDidChangeDiagnostics() {
				return extHostDiagnostics.onDidChangeDiagnostics;
			},
A
Alex Dima 已提交
289
			getDiagnostics: (resource?: vscode.Uri) => {
290 291
				return <any>extHostDiagnostics.getDiagnostics(resource);
			},
292
			getLanguages(): Thenable<string[]> {
293 294
				return extHostLanguages.getLanguages();
			},
295
			setTextDocumentLanguage(document: vscode.TextDocument, languageId: string): Thenable<vscode.TextDocument> {
M
mechatroner 已提交
296
				return extHostLanguages.changeLanguage(document.uri, languageId);
297
			},
298
			match(selector: vscode.DocumentSelector, document: vscode.TextDocument): number {
299
				return score(typeConverters.LanguageSelector.from(selector), document.uri, document.languageId, true);
300
			},
301
			registerCodeActionsProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider, metadata?: vscode.CodeActionProviderMetadata): vscode.Disposable {
302
				return extHostLanguageFeatures.registerCodeActionProvider(extension, checkSelector(selector), provider, metadata);
303 304
			},
			registerCodeLensProvider(selector: vscode.DocumentSelector, provider: vscode.CodeLensProvider): vscode.Disposable {
305
				return extHostLanguageFeatures.registerCodeLensProvider(extension, checkSelector(selector), provider);
306 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
			onDidChangeTerminalDimensions(listener, thisArg?, disposables?) {
432
				checkProposedApiEnabled(extension);
433 434
				return extHostTerminalService.onDidChangeTerminalDimensions(listener, thisArg, disposables);
			},
435 436 437 438
			onDidWriteTerminalData(listener, thisArg?, disposables?) {
				checkProposedApiEnabled(extension);
				return extHostTerminalService.onDidWriteTerminalData(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
			createWebviewTextEditorInset(editor: vscode.TextEditor, line: number, height: number, options: vscode.WebviewOptions): vscode.WebviewEditorInset {
505
				checkProposedApiEnabled(extension);
506
				return extHostEditorInsets.createWebviewEditorInset(editor, line, height, options, extension);
507
			},
508
			createTerminal(nameOrOptions?: vscode.TerminalOptions | vscode.ExtensionTerminalOptions | string, shellPath?: string, shellArgs?: string[] | string): vscode.Terminal {
509
				if (typeof nameOrOptions === 'object') {
510 511
					if ('pty' in nameOrOptions) {
						return extHostTerminalService.createExtensionTerminal(nameOrOptions);
512
					}
513
					return extHostTerminalService.createTerminalFromOptions(nameOrOptions);
514
				}
515
				return extHostTerminalService.createTerminal(nameOrOptions, shellPath, shellArgs);
516
			},
517
			registerTreeDataProvider(viewId: string, treeDataProvider: vscode.TreeDataProvider<any>): vscode.Disposable {
518
				return extHostTreeViews.registerTreeDataProvider(viewId, treeDataProvider, extension);
519
			},
520
			createTreeView(viewId: string, options: { treeDataProvider: vscode.TreeDataProvider<any> }): vscode.TreeView<any> {
521
				return extHostTreeViews.createTreeView(viewId, options, extension);
S
Sandeep Somavarapu 已提交
522
			},
523 524 525
			registerWebviewPanelSerializer: (viewType: string, serializer: vscode.WebviewPanelSerializer) => {
				return extHostWebviews.registerWebviewPanelSerializer(viewType, serializer);
			},
526 527 528 529
			registerWebviewEditorProvider: (viewType: string, provider: vscode.WebviewEditorProvider) => {
				checkProposedApiEnabled(extension);
				return extHostWebviews.registerWebviewEditorProvider(viewType, provider);
			},
530 531
			registerDecorationProvider(provider: vscode.DecorationProvider) {
				checkProposedApiEnabled(extension);
532
				return extHostDecorations.registerDecorationProvider(provider, extension.identifier);
533
			},
J
Joao Moreno 已提交
534
			registerUriHandler(handler: vscode.UriHandler) {
535
				return extHostUrls.registerUriHandler(extension.identifier, handler);
J
Joao Moreno 已提交
536
			},
C
Christof Marti 已提交
537
			createQuickPick<T extends vscode.QuickPickItem>(): vscode.QuickPick<T> {
M
Matt Bierner 已提交
538
				return extHostQuickOpen.createQuickPick(extension.identifier, !!extension.enableProposedApi);
C
Christof Marti 已提交
539 540
			},
			createInputBox(): vscode.InputBox {
541
				return extHostQuickOpen.createInputBox(extension.identifier);
542
			}
543
		};
E
Erich Gamma 已提交
544

545
		// namespace: workspace
R
Rob Lourens 已提交
546
		let warnedRootPathDeprecated = false;
547 548
		const workspace: typeof vscode.workspace = {
			get rootPath() {
R
Rob Lourens 已提交
549 550 551 552 553
				if (extension.isUnderDevelopment && !warnedRootPathDeprecated) {
					warnedRootPathDeprecated = true;
					console.warn(`[Deprecation Warning] 'workspace.rootPath' is deprecated and should no longer be used. Please use 'workspace.workspaceFolders' instead. More details: https://aka.ms/vscode-eliminating-rootpath`);
				}

554
				return extHostWorkspace.getPath();
555 556 557 558
			},
			set rootPath(value) {
				throw errors.readonly();
			},
559
			getWorkspaceFolder(resource) {
560
				return extHostWorkspace.getWorkspaceFolder(resource);
561
			},
562
			get workspaceFolders() {
563
				return extHostWorkspace.getWorkspaceFolders();
564
			},
565
			get name() {
566
				return extHostWorkspace.name;
567 568 569 570
			},
			set name(value) {
				throw errors.readonly();
			},
571 572 573 574 575 576
			get workspaceFile() {
				return extHostWorkspace.workspaceFile;
			},
			set workspaceFile(value) {
				throw errors.readonly();
			},
577
			updateWorkspaceFolders: (index, deleteCount, ...workspaceFoldersToAdd) => {
578
				return extHostWorkspace.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
579
			},
580
			onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
581
				return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
582
			},
583
			asRelativePath: (pathOrUri, includeWorkspace?) => {
584
				return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
585 586
			},
			findFiles: (include, exclude, maxResults?, token?) => {
587 588
				// Note, undefined/null have different meanings on "exclude"
				return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(exclude), maxResults, extension.identifier, token);
589
			},
590
			findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback: vscode.FindTextInFilesOptions | ((result: vscode.TextSearchResult) => void), callbackOrToken?: vscode.CancellationToken | ((result: vscode.TextSearchResult) => void), token?: vscode.CancellationToken) => {
591 592 593 594 595
				let options: vscode.FindTextInFilesOptions;
				let callback: (result: vscode.TextSearchResult) => void;

				if (typeof optionsOrCallback === 'object') {
					options = optionsOrCallback;
596
					callback = callbackOrToken as (result: vscode.TextSearchResult) => void;
597 598 599
				} else {
					options = {};
					callback = optionsOrCallback;
600
					token = callbackOrToken as vscode.CancellationToken;
601 602
				}

603
				return extHostWorkspace.findTextInFiles(query, options || {}, callback, extension.identifier, token);
R
Rob Lourens 已提交
604
			},
605
			saveAll: (includeUntitled?) => {
606
				return extHostWorkspace.saveAll(includeUntitled);
607
			},
608
			applyEdit(edit: vscode.WorkspaceEdit): Thenable<boolean> {
609
				return extHostEditors.applyWorkspaceEdit(edit);
610 611
			},
			createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
612
				return extHostFileSystemEvent.createFileSystemWatcher(typeConverters.GlobPattern.from(pattern), ignoreCreate, ignoreChange, ignoreDelete);
613 614 615 616 617 618 619
			},
			get textDocuments() {
				return extHostDocuments.getAllDocumentData().map(data => data.document);
			},
			set textDocuments(value) {
				throw errors.readonly();
			},
620
			openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; content?: string; }) {
621
				let uriPromise: Thenable<URI>;
B
Benjamin Pasero 已提交
622

623
				const options = uriOrFileNameOrOptions as { language?: string; content?: string; };
B
Benjamin Pasero 已提交
624
				if (typeof uriOrFileNameOrOptions === 'string') {
625
					uriPromise = Promise.resolve(URI.file(uriOrFileNameOrOptions));
B
Benjamin Pasero 已提交
626
				} else if (uriOrFileNameOrOptions instanceof URI) {
627
					uriPromise = Promise.resolve(uriOrFileNameOrOptions);
B
Benjamin Pasero 已提交
628 629
				} else if (!options || typeof options === 'object') {
					uriPromise = extHostDocuments.createDocumentData(options);
630
				} else {
B
Benjamin Pasero 已提交
631
					throw new Error('illegal argument - uriOrFileNameOrOptions');
632
				}
B
Benjamin Pasero 已提交
633 634 635

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

700 701
		// namespace: scm
		const scm: typeof vscode.scm = {
702
			get inputBox() {
703
				return extHostSCM.getLastInputBox(extension)!; // Strict null override - Deprecated api
704
			},
J
Joao Moreno 已提交
705 706
			createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
				return extHostSCM.createSourceControl(extension, id, label, rootUri);
J
Joao Moreno 已提交
707
			}
708
		};
J
Joao Moreno 已提交
709

710
		const comment: typeof vscode.comments = {
P
Peng Lyu 已提交
711 712
			createCommentController(id: string, label: string) {
				return extHostComment.createCommentController(extension, id, label);
713
			}
J
Joao Moreno 已提交
714
		};
715

P
Peng Lyu 已提交
716 717
		const comments = comment;

718 719
		// namespace: debug
		const debug: typeof vscode.debug = {
720 721 722
			get activeDebugSession() {
				return extHostDebugService.activeDebugSession;
			},
723 724
			get activeDebugConsole() {
				return extHostDebugService.activeDebugConsole;
725
			},
726 727
			get breakpoints() {
				return extHostDebugService.breakpoints;
728
			},
729 730 731
			onDidStartDebugSession(listener, thisArg?, disposables?) {
				return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
			},
732
			onDidTerminateDebugSession(listener, thisArg?, disposables?) {
733
				return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
734
			},
A
Andre Weinand 已提交
735
			onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
736
				return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
A
Andre Weinand 已提交
737 738
			},
			onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
A
Andre Weinand 已提交
739
				return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
740
			},
741
			onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
742 743
				return extHostDebugService.onDidChangeBreakpoints(listener, thisArgs, disposables);
			},
A
Andre Weinand 已提交
744
			registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) {
745
				return extHostDebugService.registerDebugConfigurationProvider(debugType, provider);
746
			},
A
Andre Weinand 已提交
747 748
			registerDebugAdapterDescriptorFactory(debugType: string, factory: vscode.DebugAdapterDescriptorFactory) {
				return extHostDebugService.registerDebugAdapterDescriptorFactory(extension, debugType, factory);
749
			},
A
Andre Weinand 已提交
750 751
			registerDebugAdapterTrackerFactory(debugType: string, factory: vscode.DebugAdapterTrackerFactory) {
				return extHostDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
752
			},
753 754
			startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration, parentSession?: vscode.DebugSession) {
				return extHostDebugService.startDebugging(folder, nameOrConfig, parentSession);
755 756
			},
			addBreakpoints(breakpoints: vscode.Breakpoint[]) {
757
				return extHostDebugService.addBreakpoints(breakpoints);
758 759
			},
			removeBreakpoints(breakpoints: vscode.Breakpoint[]) {
760
				return extHostDebugService.removeBreakpoints(breakpoints);
761
			}
762 763
		};

D
Dirk Baeumer 已提交
764 765
		const tasks: typeof vscode.tasks = {
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
766
				return extHostTask.registerTaskProvider(extension, type, provider);
D
Dirk Baeumer 已提交
767
			},
768
			fetchTasks: (filter?: vscode.TaskFilter): Thenable<vscode.Task[]> => {
D
Dirk Baeumer 已提交
769
				return extHostTask.fetchTasks(filter);
770 771
			},
			executeTask: (task: vscode.Task): Thenable<vscode.TaskExecution> => {
D
Dirk Baeumer 已提交
772
				return extHostTask.executeTask(extension, task);
773
			},
D
Dirk Baeumer 已提交
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
			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);
			}
		};
790

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

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

906
	private _extensionService: IExtHostExtensionService;
907
	private _identifier: ExtensionIdentifier;
E
Erich Gamma 已提交
908

909 910 911 912
	readonly id: string;
	readonly extensionPath: string;
	readonly packageJSON: IExtensionDescription;
	readonly extensionKind: vscode.ExtensionKind;
E
Erich Gamma 已提交
913

914
	constructor(extensionService: IExtHostExtensionService, description: IExtensionDescription, kind: extHostTypes.ExtensionKind) {
A
Alex Dima 已提交
915
		this._extensionService = extensionService;
916 917
		this._identifier = description.identifier;
		this.id = description.identifier.value;
918
		this.extensionPath = path.normalize(originalFSPath(description.extensionLocation));
E
Erich Gamma 已提交
919
		this.packageJSON = description;
920
		this.extensionKind = kind;
E
Erich Gamma 已提交
921 922 923
	}

	get isActive(): boolean {
924
		return this._extensionService.isActivated(this._identifier);
E
Erich Gamma 已提交
925 926 927
	}

	get exports(): T {
928
		if (this.packageJSON.api === 'none') {
929
			return undefined!; // Strict nulloverride - Public api
930
		}
931
		return <T>this._extensionService.getExtensionExports(this._identifier);
E
Erich Gamma 已提交
932 933 934
	}

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