extHost.api.impl.ts 49.8 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, UIKind } 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';
71
import { ExtHostUserData } from 'vs/workbench/api/common/extHostUserData';
E
Erich Gamma 已提交
72

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

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

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

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

J
Johannes Rieken 已提交
99
	// automatically create and register addressable instances
100
	const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, accessor.get(IExtHostDecorations));
J
Johannes Rieken 已提交
101 102 103 104 105 106 107 108 109
	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 已提交
110
	const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol, initData.environment));
J
Joao Moreno 已提交
111
	const extHostUrls = rpcProtocol.set(ExtHostContext.ExtHostUrls, new ExtHostUrls(rpcProtocol));
A
Alex Dima 已提交
112
	const extHostDocuments = rpcProtocol.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors));
113
	const extHostDocumentContentProviders = rpcProtocol.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(rpcProtocol, extHostDocumentsAndEditors, extHostLogService));
114
	const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostLogService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadTextEditors)));
A
Alex Dima 已提交
115
	const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(rpcProtocol, extHostDocumentsAndEditors));
S
Sandeep Somavarapu 已提交
116
	const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands, extHostLogService));
M
Matt Bierner 已提交
117
	const extHostEditorInsets = rpcProtocol.set(ExtHostContext.ExtHostEditorInsets, new ExtHostEditorInsets(rpcProtocol.getProxy(MainContext.MainThreadEditorInsets), extHostEditors, initData.environment));
A
Alex Dima 已提交
118
	const extHostDiagnostics = rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(rpcProtocol));
119
	const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, uriTransformer, extHostDocuments, extHostCommands, extHostDiagnostics, extHostLogService));
120
	const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
121
	const extHostFileSystemEvent = rpcProtocol.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService(rpcProtocol, extHostDocumentsAndEditors));
A
Alex Dima 已提交
122
	const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(rpcProtocol, extHostWorkspace, extHostCommands));
123
	const extHostSCM = rpcProtocol.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(rpcProtocol, extHostCommands, extHostLogService));
P
Peng Lyu 已提交
124
	const extHostComment = rpcProtocol.set(ExtHostContext.ExtHostComments, new ExtHostComments(rpcProtocol, extHostCommands, extHostDocuments));
A
Alex Dima 已提交
125
	const extHostWindow = rpcProtocol.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(rpcProtocol));
126
	const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
127
	const extHostLabelService = rpcProtocol.set(ExtHostContext.ExtHosLabelService, new ExtHostLabelService(rpcProtocol));
S
Sandeep Somavarapu 已提交
128
	const extHostUserData = rpcProtocol.set(ExtHostContext.ExtHostUserData, new ExtHostUserData(rpcProtocol.getProxy(MainContext.MainThreadUserData), extHostLogService));
129

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

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

141
	// Register API-ish commands
142
	ExtHostApiCommands.register(extHostCommands);
143

144
	return function (extension: IExtensionDescription, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode {
145

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

176

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

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

224
		// namespace: env
225
		const env: typeof vscode.env = {
226 227
			get machineId() { return initData.telemetryInfo.machineId; },
			get sessionId() { return initData.telemetryInfo.sessionId; },
228 229
			get language() { return initData.environment.appLanguage; },
			get appName() { return initData.environment.appName; },
230
			get appRoot() { return initData.environment.appRoot!.fsPath; },
231
			get uriScheme() { return initData.environment.appUriScheme; },
232 233 234 235
			createAppUri(options?) {
				checkProposedApiEnabled(extension);
				return extHostUrls.createAppUri(extension.identifier, options);
			},
236 237
			get logLevel() {
				checkProposedApiEnabled(extension);
238
				return typeConverters.LogLevel.to(extHostLogService.getLevel());
239 240 241
			},
			get onDidChangeLogLevel() {
				checkProposedApiEnabled(extension);
J
Joao Moreno 已提交
242
				return Event.map(extHostLogService.onDidChangeLogLevel, l => typeConverters.LogLevel.to(l));
243 244 245
			},
			get clipboard(): vscode.Clipboard {
				return extHostClipboard;
246
			},
D
Daniel Imms 已提交
247
			get shell() {
248
				return extHostTerminalService.getDefaultShell(false, configProvider);
D
Daniel Imms 已提交
249
			},
J
Johannes Rieken 已提交
250
			openExternal(uri: URI) {
251
				return extHostWindow.openUri(uri, { allowTunneling: !!initData.remote.isRemote });
252
			},
253
			get remoteName() {
254
				return getRemoteName(initData.remote.authority);
255 256 257 258
			},
			get uiKind() {
				checkProposedApiEnabled(extension);
				return initData.uiKind;
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 268 269
		const extensionKind = initData.remote.isRemote
			? extHostTypes.ExtensionKind.Workspace
			: extHostTypes.ExtensionKind.UI;

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

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

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

480 481 482 483 484 485 486 487 488 489 490 491 492
				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);
493 494 495 496
			},
			setStatusBarMessage(text: string, timeoutOrThenable?: number | Thenable<any>): vscode.Disposable {
				return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable);
			},
497
			withScmProgress<R>(task: (progress: vscode.Progress<number>) => Thenable<R>) {
498
				console.warn(`[Deprecation Warning] function 'withScmProgress' is deprecated and should no longer be used. Use 'withProgress' instead.`);
499
				return extHostProgress.withProgress(extension, { location: extHostTypes.ProgressLocation.SourceControl }, (progress, token) => task({ report(n: number) { /*noop*/ } }));
J
Johannes Rieken 已提交
500
			},
501
			withProgress<R>(options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string; worked?: number }>, token: vscode.CancellationToken) => Thenable<R>) {
J
Johannes Rieken 已提交
502
				return extHostProgress.withProgress(extension, options, task);
503
			},
S
Sandeep Somavarapu 已提交
504 505
			createOutputChannel(name: string): vscode.OutputChannel {
				return extHostOutputService.createOutputChannel(name);
506
			},
507
			createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel {
508
				return extHostWebviews.createWebviewPanel(extension, viewType, title, showOptions, options);
509
			},
510
			createWebviewTextEditorInset(editor: vscode.TextEditor, line: number, height: number, options: vscode.WebviewOptions): vscode.WebviewEditorInset {
511
				checkProposedApiEnabled(extension);
512
				return extHostEditorInsets.createWebviewEditorInset(editor, line, height, options, extension);
513
			},
514
			createTerminal(nameOrOptions?: vscode.TerminalOptions | vscode.ExtensionTerminalOptions | string, shellPath?: string, shellArgs?: string[] | string): vscode.Terminal {
515
				if (typeof nameOrOptions === 'object') {
516 517
					if ('pty' in nameOrOptions) {
						return extHostTerminalService.createExtensionTerminal(nameOrOptions);
518
					}
519
					return extHostTerminalService.createTerminalFromOptions(nameOrOptions);
520
				}
521
				return extHostTerminalService.createTerminal(nameOrOptions, shellPath, shellArgs);
522
			},
523
			registerTreeDataProvider(viewId: string, treeDataProvider: vscode.TreeDataProvider<any>): vscode.Disposable {
524
				return extHostTreeViews.registerTreeDataProvider(viewId, treeDataProvider, extension);
525
			},
526
			createTreeView(viewId: string, options: { treeDataProvider: vscode.TreeDataProvider<any> }): vscode.TreeView<any> {
527
				return extHostTreeViews.createTreeView(viewId, options, extension);
S
Sandeep Somavarapu 已提交
528
			},
529 530 531
			registerWebviewPanelSerializer: (viewType: string, serializer: vscode.WebviewPanelSerializer) => {
				return extHostWebviews.registerWebviewPanelSerializer(viewType, serializer);
			},
532 533 534 535
			registerWebviewEditorProvider: (viewType: string, provider: vscode.WebviewEditorProvider) => {
				checkProposedApiEnabled(extension);
				return extHostWebviews.registerWebviewEditorProvider(viewType, provider);
			},
536 537
			registerDecorationProvider(provider: vscode.DecorationProvider) {
				checkProposedApiEnabled(extension);
538
				return extHostDecorations.registerDecorationProvider(provider, extension.identifier);
539
			},
J
Joao Moreno 已提交
540
			registerUriHandler(handler: vscode.UriHandler) {
541
				return extHostUrls.registerUriHandler(extension.identifier, handler);
J
Joao Moreno 已提交
542
			},
C
Christof Marti 已提交
543
			createQuickPick<T extends vscode.QuickPickItem>(): vscode.QuickPick<T> {
M
Matt Bierner 已提交
544
				return extHostQuickOpen.createQuickPick(extension.identifier, !!extension.enableProposedApi);
C
Christof Marti 已提交
545 546
			},
			createInputBox(): vscode.InputBox {
547
				return extHostQuickOpen.createInputBox(extension.identifier);
548
			},
549
			registerUserDataSyncProvider: (name: string, userDataProvider: vscode.UserDataSyncProvider): vscode.Disposable => {
S
Sandeep Somavarapu 已提交
550
				checkProposedApiEnabled(extension);
551
				return extHostUserData.registerUserDataProvider(extension.identifier.value, name, userDataProvider);
S
Sandeep Somavarapu 已提交
552
			}
553
		};
E
Erich Gamma 已提交
554

555
		// namespace: workspace
R
Rob Lourens 已提交
556
		let warnedRootPathDeprecated = false;
557 558
		const workspace: typeof vscode.workspace = {
			get rootPath() {
R
Rob Lourens 已提交
559 560 561 562 563
				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`);
				}

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

				if (typeof optionsOrCallback === 'object') {
					options = optionsOrCallback;
606
					callback = callbackOrToken as (result: vscode.TextSearchResult) => void;
607 608 609
				} else {
					options = {};
					callback = optionsOrCallback;
610
					token = callbackOrToken as vscode.CancellationToken;
611 612
				}

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

633
				const options = uriOrFileNameOrOptions as { language?: string; content?: string; };
B
Benjamin Pasero 已提交
634
				if (typeof uriOrFileNameOrOptions === 'string') {
635
					uriPromise = Promise.resolve(URI.file(uriOrFileNameOrOptions));
B
Benjamin Pasero 已提交
636
				} else if (uriOrFileNameOrOptions instanceof URI) {
637
					uriPromise = Promise.resolve(uriOrFileNameOrOptions);
B
Benjamin Pasero 已提交
638 639
				} else if (!options || typeof options === 'object') {
					uriPromise = extHostDocuments.createDocumentData(options);
640
				} else {
B
Benjamin Pasero 已提交
641
					throw new Error('illegal argument - uriOrFileNameOrOptions');
642
				}
B
Benjamin Pasero 已提交
643 644 645

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

710 711
		// namespace: scm
		const scm: typeof vscode.scm = {
712
			get inputBox() {
713
				return extHostSCM.getLastInputBox(extension)!; // Strict null override - Deprecated api
714
			},
J
Joao Moreno 已提交
715 716
			createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
				return extHostSCM.createSourceControl(extension, id, label, rootUri);
J
Joao Moreno 已提交
717
			}
718
		};
J
Joao Moreno 已提交
719

720
		const comment: typeof vscode.comments = {
P
Peng Lyu 已提交
721 722
			createCommentController(id: string, label: string) {
				return extHostComment.createCommentController(extension, id, label);
723
			}
J
Joao Moreno 已提交
724
		};
725

P
Peng Lyu 已提交
726 727
		const comments = comment;

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

D
Dirk Baeumer 已提交
774 775
		const tasks: typeof vscode.tasks = {
			registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
776
				return extHostTask.registerTaskProvider(extension, type, provider);
D
Dirk Baeumer 已提交
777
			},
778
			fetchTasks: (filter?: vscode.TaskFilter): Thenable<vscode.Task[]> => {
D
Dirk Baeumer 已提交
779
				return extHostTask.fetchTasks(filter);
780 781
			},
			executeTask: (task: vscode.Task): Thenable<vscode.TaskExecution> => {
D
Dirk Baeumer 已提交
782
				return extHostTask.executeTask(extension, task);
783
			},
D
Dirk Baeumer 已提交
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
			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);
			}
		};
800

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

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

919
	private _extensionService: IExtHostExtensionService;
920
	private _identifier: ExtensionIdentifier;
E
Erich Gamma 已提交
921

922 923 924 925
	readonly id: string;
	readonly extensionPath: string;
	readonly packageJSON: IExtensionDescription;
	readonly extensionKind: vscode.ExtensionKind;
E
Erich Gamma 已提交
926

927
	constructor(extensionService: IExtHostExtensionService, description: IExtensionDescription, kind: extHostTypes.ExtensionKind) {
A
Alex Dima 已提交
928
		this._extensionService = extensionService;
929 930
		this._identifier = description.identifier;
		this.id = description.identifier.value;
931
		this.extensionPath = path.normalize(originalFSPath(description.extensionLocation));
E
Erich Gamma 已提交
932
		this.packageJSON = description;
933
		this.extensionKind = kind;
E
Erich Gamma 已提交
934 935 936
	}

	get isActive(): boolean {
937
		return this._extensionService.isActivated(this._identifier);
E
Erich Gamma 已提交
938 939 940
	}

	get exports(): T {
941
		if (this.packageJSON.api === 'none') {
942
			return undefined!; // Strict nulloverride - Public api
943
		}
944
		return <T>this._extensionService.getExtensionExports(this._identifier);
E
Erich Gamma 已提交
945 946 947
	}

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