simpleServices.ts 20.5 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

J
Johannes Rieken 已提交
7
import { Schemas } from 'vs/base/common/network';
E
Erich Gamma 已提交
8
import Severity from 'vs/base/common/severity';
9
import URI from 'vs/base/common/uri';
J
Johannes Rieken 已提交
10
import { TPromise } from 'vs/base/common/winjs.base';
11
import { IConfigurationService, IConfigurationChangeEvent, IConfigurationOverrides } from 'vs/platform/configuration/common/configuration';
12
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
J
Joao Moreno 已提交
13
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, Position } from 'vs/platform/editor/common/editor';
14
import { ICommandService, ICommand, ICommandEvent, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
15 16
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
17
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
18
import { IKeybindingEvent, KeybindingSource, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
19
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
20
import { IWorkspaceContextService, IWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
A
Alex Dima 已提交
21
import * as editorCommon from 'vs/editor/common/editorCommon';
22
import { ICodeEditor, IDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
M
Matt Bierner 已提交
23
import { Event, Emitter } from 'vs/base/common/event';
S
Sandeep Somavarapu 已提交
24
import { Configuration, DefaultConfigurationModel, ConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
J
Johannes Rieken 已提交
25 26
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
27
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
28
import { ITextModelService, ITextModelContentProvider, ITextEditorModel } from 'vs/editor/common/services/resolverService';
29
import { IDisposable, IReference, ImmortalReference, combinedDisposable } from 'vs/base/common/lifecycle';
30 31
import * as dom from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
A
Renames  
Alex Dima 已提交
32
import { KeybindingsRegistry, IKeybindingItem } from 'vs/platform/keybinding/common/keybindingsRegistry';
33
import { MenuId, IMenu, IMenuService } from 'vs/platform/actions/common/actions';
A
Alex Dima 已提交
34
import { Menu } from 'vs/platform/actions/common/menu';
35
import { ITelemetryService, ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
36
import { ResolvedKeybinding, Keybinding, createKeybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
37
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
A
Alex Dima 已提交
38
import { OS } from 'vs/base/common/platform';
39
import { IRange } from 'vs/editor/common/core/range';
A
Alex Dima 已提交
40
import { ITextModel } from 'vs/editor/common/model';
41
import { INotificationService, INotification, INotificationHandle, NoOpNotification, PromptOption } from 'vs/platform/notification/common/notification';
42
import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions } from 'vs/platform/dialogs/common/dialogs';
43
import { IPosition, Position as Pos } from 'vs/editor/common/core/position';
E
Erich Gamma 已提交
44 45 46

export class SimpleEditor implements IEditor {

J
Johannes Rieken 已提交
47 48 49
	public input: IEditorInput;
	public options: IEditorOptions;
	public position: Position;
E
Erich Gamma 已提交
50

J
Johannes Rieken 已提交
51
	public _widget: editorCommon.IEditor;
E
Erich Gamma 已提交
52

J
Johannes Rieken 已提交
53
	constructor(editor: editorCommon.IEditor) {
E
Erich Gamma 已提交
54 55 56
		this._widget = editor;
	}

J
Johannes Rieken 已提交
57 58 59 60
	public getId(): string { return 'editor'; }
	public getControl(): editorCommon.IEditor { return this._widget; }
	public focus(): void { this._widget.focus(); }
	public isVisible(): boolean { return true; }
E
Erich Gamma 已提交
61

J
Johannes Rieken 已提交
62
	public withTypedEditor<T>(codeEditorCallback: (editor: ICodeEditor) => T, diffEditorCallback: (editor: IDiffEditor) => T): T {
63
		if (isCodeEditor(this._widget)) {
E
Erich Gamma 已提交
64
			// Single Editor
A
Alex Dima 已提交
65
			return codeEditorCallback(<ICodeEditor>this._widget);
E
Erich Gamma 已提交
66 67
		} else {
			// Diff Editor
A
Alex Dima 已提交
68
			return diffEditorCallback(<IDiffEditor>this._widget);
E
Erich Gamma 已提交
69 70 71 72
		}
	}
}

J
Johannes Rieken 已提交
73
export class SimpleModel implements ITextEditorModel {
E
Erich Gamma 已提交
74

A
Alex Dima 已提交
75
	private model: ITextModel;
M
Matt Bierner 已提交
76
	private readonly _onDispose: Emitter<void>;
E
Erich Gamma 已提交
77

A
Alex Dima 已提交
78
	constructor(model: ITextModel) {
E
Erich Gamma 已提交
79
		this.model = model;
80 81 82 83 84
		this._onDispose = new Emitter<void>();
	}

	public get onDispose(): Event<void> {
		return this._onDispose.event;
E
Erich Gamma 已提交
85 86
	}

87 88 89 90
	public load(): TPromise<SimpleModel> {
		return TPromise.as(this);
	}

A
Alex Dima 已提交
91
	public get textEditorModel(): ITextModel {
E
Erich Gamma 已提交
92 93
		return this.model;
	}
94 95 96 97

	public dispose(): void {
		this._onDispose.fire();
	}
E
Erich Gamma 已提交
98 99 100
}

export interface IOpenEditorDelegate {
J
Johannes Rieken 已提交
101
	(url: string): boolean;
E
Erich Gamma 已提交
102 103 104
}

export class SimpleEditorService implements IEditorService {
105
	public _serviceBrand: any;
E
Erich Gamma 已提交
106

J
Johannes Rieken 已提交
107 108
	private editor: SimpleEditor;
	private openEditorDelegate: IOpenEditorDelegate;
E
Erich Gamma 已提交
109 110 111 112 113

	constructor() {
		this.openEditorDelegate = null;
	}

J
Johannes Rieken 已提交
114
	public setEditor(editor: editorCommon.IEditor): void {
E
Erich Gamma 已提交
115 116 117
		this.editor = new SimpleEditor(editor);
	}

J
Johannes Rieken 已提交
118
	public setOpenEditorDelegate(openEditorDelegate: IOpenEditorDelegate): void {
E
Erich Gamma 已提交
119 120 121
		this.openEditorDelegate = openEditorDelegate;
	}

J
Johannes Rieken 已提交
122
	public openEditor(typedData: IResourceInput, sideBySide?: boolean): TPromise<IEditor> {
E
Erich Gamma 已提交
123 124 125 126 127 128 129 130 131
		return TPromise.as(this.editor.withTypedEditor(
			(editor) => this.doOpenEditor(editor, typedData),
			(diffEditor) => (
				this.doOpenEditor(diffEditor.getOriginalEditor(), typedData) ||
				this.doOpenEditor(diffEditor.getModifiedEditor(), typedData)
			)
		));
	}

132
	private doOpenEditor(editor: ICodeEditor, data: IResourceInput): IEditor {
A
Alex Dima 已提交
133
		let model = this.findModel(editor, data);
E
Erich Gamma 已提交
134 135 136 137 138 139
		if (!model) {
			if (data.resource) {
				if (this.openEditorDelegate) {
					this.openEditorDelegate(data.resource.toString());
					return null;
				} else {
A
Alex Dima 已提交
140
					let schema = data.resource.scheme;
A
Alex Dima 已提交
141
					if (schema === Schemas.http || schema === Schemas.https) {
E
Erich Gamma 已提交
142
						// This is a fully qualified http or https URL
143
						dom.windowOpenNoOpener(data.resource.toString());
E
Erich Gamma 已提交
144 145 146 147 148 149 150
						return this.editor;
					}
				}
			}
			return null;
		}

A
Alex Dima 已提交
151
		let selection = <IRange>data.options.selection;
E
Erich Gamma 已提交
152 153 154
		if (selection) {
			if (typeof selection.endLineNumber === 'number' && typeof selection.endColumn === 'number') {
				editor.setSelection(selection);
155
				editor.revealRangeInCenter(selection, editorCommon.ScrollType.Immediate);
E
Erich Gamma 已提交
156
			} else {
A
Alex Dima 已提交
157
				let pos = {
E
Erich Gamma 已提交
158 159 160 161
					lineNumber: selection.startLineNumber,
					column: selection.startColumn
				};
				editor.setPosition(pos);
162
				editor.revealPositionInCenter(pos, editorCommon.ScrollType.Immediate);
E
Erich Gamma 已提交
163 164 165 166 167 168
			}
		}

		return this.editor;
	}

A
Alex Dima 已提交
169
	private findModel(editor: ICodeEditor, data: IResourceInput): ITextModel {
A
Alex Dima 已提交
170
		let model = editor.getModel();
J
Johannes Rieken 已提交
171
		if (model.uri.toString() !== data.resource.toString()) {
E
Erich Gamma 已提交
172 173 174 175 176 177 178
			return null;
		}

		return model;
	}
}

179
export class SimpleEditorModelResolverService implements ITextModelService {
180 181 182 183 184 185 186 187
	public _serviceBrand: any;

	private editor: SimpleEditor;

	public setEditor(editor: editorCommon.IEditor): void {
		this.editor = new SimpleEditor(editor);
	}

J
Joao Moreno 已提交
188
	public createModelReference(resource: URI): TPromise<IReference<ITextEditorModel>> {
A
Alex Dima 已提交
189
		let model: ITextModel;
190 191 192 193 194 195 196

		model = this.editor.withTypedEditor(
			(editor) => this.findModel(editor, resource),
			(diffEditor) => this.findModel(diffEditor.getOriginalEditor(), resource) || this.findModel(diffEditor.getModifiedEditor(), resource)
		);

		if (!model) {
J
Joao Moreno 已提交
197
			return TPromise.as(new ImmortalReference(null));
198 199
		}

J
Joao Moreno 已提交
200
		return TPromise.as(new ImmortalReference(new SimpleModel(model)));
201 202 203 204 205 206 207 208
	}

	public registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
		return {
			dispose: function () { /* no op */ }
		};
	}

A
Alex Dima 已提交
209
	private findModel(editor: ICodeEditor, resource: URI): ITextModel {
210 211 212 213 214 215 216 217 218
		let model = editor.getModel();
		if (model.uri.toString() !== resource.toString()) {
			return null;
		}

		return model;
	}
}

219 220 221
export class SimpleProgressService implements IProgressService {
	_serviceBrand: any;

J
Johannes Rieken 已提交
222 223 224 225
	private static NULL_PROGRESS_RUNNER: IProgressRunner = {
		done: () => { },
		total: () => { },
		worked: () => { }
226 227 228 229 230 231 232 233 234 235 236 237 238
	};

	show(infinite: boolean, delay?: number): IProgressRunner;
	show(total: number, delay?: number): IProgressRunner;
	show(): IProgressRunner {
		return SimpleProgressService.NULL_PROGRESS_RUNNER;
	}

	showWhile(promise: TPromise<any>, delay?: number): TPromise<void> {
		return null;
	}
}

239
export class SimpleDialogService implements IDialogService {
240 241

	public _serviceBrand: any;
E
Erich Gamma 已提交
242

243 244 245 246 247 248 249 250 251 252
	public confirm(confirmation: IConfirmation): TPromise<IConfirmationResult> {
		return this.doConfirm(confirmation).then(confirmed => {
			return {
				confirmed,
				checkboxChecked: false // unsupported
			} as IConfirmationResult;
		});
	}

	private doConfirm(confirmation: IConfirmation): TPromise<boolean> {
A
Alex Dima 已提交
253
		let messageText = confirmation.message;
E
Erich Gamma 已提交
254 255 256 257
		if (confirmation.detail) {
			messageText = messageText + '\n\n' + confirmation.detail;
		}

258
		return TPromise.wrap(window.confirm(messageText));
E
Erich Gamma 已提交
259
	}
260

261
	public show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): TPromise<number> {
262 263
		return TPromise.as(0);
	}
A
Alex Dima 已提交
264 265
}

266 267 268 269
export class SimpleNotificationService implements INotificationService {

	public _serviceBrand: any;

270
	private static readonly NO_OP: INotificationHandle = new NoOpNotification();
271

B
Benjamin Pasero 已提交
272 273 274 275 276 277 278 279 280
	public info(message: string): INotificationHandle {
		return this.notify({ severity: Severity.Info, message });
	}

	public warn(message: string): INotificationHandle {
		return this.notify({ severity: Severity.Warning, message });
	}

	public error(error: string | Error): INotificationHandle {
281 282 283
		return this.notify({ severity: Severity.Error, message: error });
	}

284 285
	public notify(notification: INotification): INotificationHandle {
		switch (notification.severity) {
286
			case Severity.Error:
287
				console.error(notification.message);
288 289
				break;
			case Severity.Warning:
290
				console.warn(notification.message);
291 292
				break;
			default:
293
				console.log(notification.message);
294 295 296
				break;
		}

297
		return SimpleNotificationService.NO_OP;
298
	}
299 300 301 302

	public prompt(severity: Severity, message: string, choices: PromptOption[]): TPromise<number> {
		return TPromise.as(0);
	}
303 304
}

A
Alex Dima 已提交
305 306
export class StandaloneCommandService implements ICommandService {
	_serviceBrand: any;
307

A
Alex Dima 已提交
308
	private readonly _instantiationService: IInstantiationService;
309 310
	private _dynamicCommands: { [id: string]: ICommand; };

M
Matt Bierner 已提交
311
	private readonly _onWillExecuteCommand: Emitter<ICommandEvent> = new Emitter<ICommandEvent>();
312 313
	public readonly onWillExecuteCommand: Event<ICommandEvent> = this._onWillExecuteCommand.event;

A
Alex Dima 已提交
314 315
	constructor(instantiationService: IInstantiationService) {
		this._instantiationService = instantiationService;
316 317 318
		this._dynamicCommands = Object.create(null);
	}

J
Johannes Rieken 已提交
319 320
	public addCommand(command: ICommand): IDisposable {
		const { id } = command;
321
		this._dynamicCommands[id] = command;
322 323 324 325 326
		return {
			dispose: () => {
				delete this._dynamicCommands[id];
			}
		};
327 328
	}

A
Alex Dima 已提交
329 330 331
	public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
		const command = (CommandsRegistry.getCommand(id) || this._dynamicCommands[id]);
		if (!command) {
332
			return TPromise.wrapError<T>(new Error(`command '${id}' not found`));
A
Alex Dima 已提交
333 334 335
		}

		try {
336
			this._onWillExecuteCommand.fire({ commandId: id });
A
Alex Dima 已提交
337 338 339
			const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
			return TPromise.as(result);
		} catch (err) {
340
			return TPromise.wrapError<T>(err);
A
Alex Dima 已提交
341
		}
342 343 344
	}
}

345 346
export class StandaloneKeybindingService extends AbstractKeybindingService {
	private _cachedResolver: KeybindingResolver;
E
Erich Gamma 已提交
347 348
	private _dynamicKeybindings: IKeybindingItem[];

A
Alex Dima 已提交
349
	constructor(
350
		contextKeyService: IContextKeyService,
A
Alex Dima 已提交
351
		commandService: ICommandService,
352
		telemetryService: ITelemetryService,
353
		notificationService: INotificationService,
A
Alex Dima 已提交
354 355
		domNode: HTMLElement
	) {
356
		super(contextKeyService, commandService, telemetryService, notificationService);
357

358
		this._cachedResolver = null;
E
Erich Gamma 已提交
359
		this._dynamicKeybindings = [];
360

361 362
		this.toDispose.push(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
			let keyEvent = new StandardKeyboardEvent(e);
363
			let shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
364 365 366 367
			if (shouldPreventDefault) {
				keyEvent.preventDefault();
			}
		}));
E
Erich Gamma 已提交
368 369
	}

370
	public addDynamicKeybinding(commandId: string, keybinding: number, handler: ICommandHandler, when: ContextKeyExpr): IDisposable {
371 372
		let toDispose: IDisposable[] = [];

E
Erich Gamma 已提交
373
		this._dynamicKeybindings.push({
A
Renames  
Alex Dima 已提交
374
			keybinding: createKeybinding(keybinding, OS),
E
Erich Gamma 已提交
375
			command: commandId,
376
			when: when,
E
Erich Gamma 已提交
377 378 379
			weight1: 1000,
			weight2: 0
		});
380

381 382 383 384 385 386 387 388 389 390 391 392 393
		toDispose.push({
			dispose: () => {
				for (let i = 0; i < this._dynamicKeybindings.length; i++) {
					let kb = this._dynamicKeybindings[i];
					if (kb.command === commandId) {
						this._dynamicKeybindings.splice(i, 1);
						this.updateResolver({ source: KeybindingSource.Default });
						return;
					}
				}
			}
		});

394 395
		let commandService = this._commandService;
		if (commandService instanceof StandaloneCommandService) {
J
Johannes Rieken 已提交
396 397
			toDispose.push(commandService.addCommand({
				id: commandId,
398
				handler: handler
399
			}));
400 401 402
		} else {
			throw new Error('Unknown command service!');
		}
C
Christof Marti 已提交
403
		this.updateResolver({ source: KeybindingSource.Default });
404

405
		return combinedDisposable(toDispose);
E
Erich Gamma 已提交
406 407
	}

408 409 410 411 412 413 414
	private updateResolver(event: IKeybindingEvent): void {
		this._cachedResolver = null;
		this._onDidUpdateKeybindings.fire(event);
	}

	protected _getResolver(): KeybindingResolver {
		if (!this._cachedResolver) {
415 416
			const defaults = this._toNormalizedKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
			const overrides = this._toNormalizedKeybindingItems(this._dynamicKeybindings, false);
417
			this._cachedResolver = new KeybindingResolver(defaults, overrides);
418 419 420 421
		}
		return this._cachedResolver;
	}

422 423
	private _toNormalizedKeybindingItems(items: IKeybindingItem[], isDefault: boolean): ResolvedKeybindingItem[] {
		let result: ResolvedKeybindingItem[] = [], resultLen = 0;
424 425 426
		for (let i = 0, len = items.length; i < len; i++) {
			const item = items[i];
			const when = (item.when ? item.when.normalize() : null);
A
Alex Dima 已提交
427
			const keybinding = item.keybinding;
428

429 430 431 432 433 434 435 436 437
			if (!keybinding) {
				// This might be a removal keybinding item in user settings => accept it
				result[resultLen++] = new ResolvedKeybindingItem(null, item.command, item.commandArgs, when, isDefault);
			} else {
				const resolvedKeybindings = this.resolveKeybinding(keybinding);
				for (let j = 0; j < resolvedKeybindings.length; j++) {
					result[resultLen++] = new ResolvedKeybindingItem(resolvedKeybindings[j], item.command, item.commandArgs, when, isDefault);
				}
			}
438 439 440 441 442
		}

		return result;
	}

443 444
	public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
		return [new USLayoutResolvedKeybinding(keybinding, OS)];
A
Alex Dima 已提交
445 446
	}

447 448 449 450 451 452 453 454
	public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
		let keybinding = new SimpleKeybinding(
			keyboardEvent.ctrlKey,
			keyboardEvent.shiftKey,
			keyboardEvent.altKey,
			keyboardEvent.metaKey,
			keyboardEvent.keyCode
		);
455
		return new USLayoutResolvedKeybinding(keybinding, OS);
456
	}
457 458 459 460

	public resolveUserBinding(userBinding: string): ResolvedKeybinding[] {
		return [];
	}
E
Erich Gamma 已提交
461 462
}

463 464 465 466 467 468 469
function isConfigurationOverrides(thing: any): thing is IConfigurationOverrides {
	return thing
		&& typeof thing === 'object'
		&& (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
		&& (!thing.resource || thing.resource instanceof URI);
}

470
export class SimpleConfigurationService implements IConfigurationService {
471

472 473
	_serviceBrand: any;

474
	private _onDidChangeConfiguration = new Emitter<IConfigurationChangeEvent>();
475
	public readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent> = this._onDidChangeConfiguration.event;
476

477
	private _configuration: Configuration;
478

479
	constructor() {
480
		this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
481 482
	}

483
	private configuration(): Configuration {
484
		return this._configuration;
485 486
	}

487 488 489 490 491 492 493 494
	getValue<T>(): T;
	getValue<T>(section: string): T;
	getValue<T>(overrides: IConfigurationOverrides): T;
	getValue<T>(section: string, overrides: IConfigurationOverrides): T;
	getValue(arg1?: any, arg2?: any): any {
		const section = typeof arg1 === 'string' ? arg1 : void 0;
		const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
		return this.configuration().getValue(section, overrides, null);
495 496
	}

497 498
	public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise<void> {
		return TPromise.as(null);
B
Benjamin Pasero 已提交
499
	}
B
Benjamin Pasero 已提交
500

S
Sandeep Somavarapu 已提交
501
	public inspect<C>(key: string, options: IConfigurationOverrides = {}): {
502 503 504 505 506 507
		default: C,
		user: C,
		workspace: C,
		workspaceFolder: C
		value: C,
	} {
508
		return this.configuration().inspect<C>(key, options, null);
B
Benjamin Pasero 已提交
509
	}
510

511
	public keys() {
S
Sandeep Somavarapu 已提交
512
		return this.configuration().keys(null);
513 514
	}

515 516
	public reloadConfiguration(): TPromise<void> {
		return TPromise.as(null);
517
	}
S
Sandeep Somavarapu 已提交
518 519 520 521

	public getConfigurationData() {
		return null;
	}
522
}
A
Alex Dima 已提交
523

524 525 526 527
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

528 529
	public readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent>;
	private readonly _onDidChangeConfigurationEmitter = new Emitter();
530 531

	constructor(private configurationService: SimpleConfigurationService) {
532 533
		this.configurationService.onDidChangeConfiguration((e) => {
			this._onDidChangeConfigurationEmitter.fire(e);
534
		});
535 536
	}

537 538 539 540 541 542
	getValue<T>(resource: URI, section?: string): T;
	getValue<T>(resource: URI, position?: IPosition, section?: string): T;
	getValue<T>(resource: any, arg2?: any, arg3?: any) {
		const position: IPosition = Pos.isIPosition(arg2) ? arg2 : null;
		const section: string = position ? (typeof arg3 === 'string' ? arg3 : void 0) : (typeof arg2 === 'string' ? arg2 : void 0);
		return this.configurationService.getValue<T>(section);
543 544 545
	}
}

A
Alex Dima 已提交
546 547 548 549 550 551 552 553 554 555 556 557 558 559
export class SimpleMenuService implements IMenuService {

	_serviceBrand: any;

	private readonly _commandService: ICommandService;

	constructor(commandService: ICommandService) {
		this._commandService = commandService;
	}

	public createMenu(id: MenuId, contextKeyService: IContextKeyService): IMenu {
		return new Menu(id, TPromise.as(true), this._commandService, contextKeyService);
	}
}
560 561 562 563 564 565 566

export class StandaloneTelemetryService implements ITelemetryService {
	_serviceBrand: void;

	public isOptedIn = false;

	public publicLog(eventName: string, data?: any): TPromise<void> {
567
		return TPromise.wrap<void>(null);
568 569 570 571 572 573
	}

	public getTelemetryInfo(): TPromise<ITelemetryInfo> {
		return null;
	}
}
574 575 576 577 578

export class SimpleWorkspaceContextService implements IWorkspaceContextService {

	public _serviceBrand: any;

579 580
	private static SCHEME: 'inmemory';

S
Sandeep Somavarapu 已提交
581 582 583
	private readonly _onDidChangeWorkspaceName: Emitter<void> = new Emitter<void>();
	public readonly onDidChangeWorkspaceName: Event<void> = this._onDidChangeWorkspaceName.event;

584 585
	private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent> = new Emitter<IWorkspaceFoldersChangeEvent>();
	public readonly onDidChangeWorkspaceFolders: Event<IWorkspaceFoldersChangeEvent> = this._onDidChangeWorkspaceFolders.event;
586 587 588

	private readonly _onDidChangeWorkbenchState: Emitter<WorkbenchState> = new Emitter<WorkbenchState>();
	public readonly onDidChangeWorkbenchState: Event<WorkbenchState> = this._onDidChangeWorkbenchState.event;
589

590
	private readonly workspace: IWorkspace;
591

592
	constructor() {
593
		const resource = URI.from({ scheme: SimpleWorkspaceContextService.SCHEME, authority: 'model', path: '/' });
594
		this.workspace = { id: '4064f6ec-cb38-4ad0-af64-ee6467e63c82', folders: [new WorkspaceFolder({ uri: resource, name: '', index: 0 })], name: resource.fsPath };
595 596
	}

B
Benjamin Pasero 已提交
597
	public getWorkspace(): IWorkspace {
598
		return this.workspace;
599 600
	}

601
	public getWorkbenchState(): WorkbenchState {
602 603
		if (this.workspace) {
			if (this.workspace.configuration) {
604
				return WorkbenchState.WORKSPACE;
605
			}
606
			return WorkbenchState.FOLDER;
607
		}
608
		return WorkbenchState.EMPTY;
609 610
	}

S
Sandeep Somavarapu 已提交
611
	public getWorkspaceFolder(resource: URI): IWorkspaceFolder {
S
Sandeep Somavarapu 已提交
612
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME ? this.workspace.folders[0] : void 0;
613 614
	}

615
	public isInsideWorkspace(resource: URI): boolean {
616
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME;
617 618
	}

619 620 621
	public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
		return true;
	}
622
}