simpleServices.ts 19.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 { IConfirmation, IMessageService, IConfirmationResult } from 'vs/platform/message/common/message';
21
import { IWorkspaceContextService, IWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
A
Alex Dima 已提交
22
import * as editorCommon from 'vs/editor/common/editorCommon';
J
Johannes Rieken 已提交
23 24 25
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { Selection } from 'vs/editor/common/core/selection';
import Event, { Emitter } from 'vs/base/common/event';
26
import { Configuration, ConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
J
Johannes Rieken 已提交
27 28
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
29
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
30
import { ITextModelService, ITextModelContentProvider, ITextEditorModel } from 'vs/editor/common/services/resolverService';
31
import { IDisposable, IReference, ImmortalReference, combinedDisposable } from 'vs/base/common/lifecycle';
32 33
import * as dom from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
A
Renames  
Alex Dima 已提交
34
import { KeybindingsRegistry, IKeybindingItem } from 'vs/platform/keybinding/common/keybindingsRegistry';
35
import { MenuId, IMenu, IMenuService } from 'vs/platform/actions/common/actions';
A
Alex Dima 已提交
36
import { Menu } from 'vs/platform/actions/common/menu';
37
import { ITelemetryService, ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
38
import { ResolvedKeybinding, Keybinding, createKeybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
39
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
A
Alex Dima 已提交
40
import { OS } from 'vs/base/common/platform';
41
import { IRange } from 'vs/editor/common/core/range';
E
Erich Gamma 已提交
42 43 44

export class SimpleEditor implements IEditor {

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

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

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

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

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

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

J
Johannes Rieken 已提交
74
	private model: editorCommon.IModel;
75
	private _onDispose: Emitter<void>;
E
Erich Gamma 已提交
76

J
Johannes Rieken 已提交
77
	constructor(model: editorCommon.IModel) {
E
Erich Gamma 已提交
78
		this.model = model;
79 80 81 82 83
		this._onDispose = new Emitter<void>();
	}

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

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

J
Johannes Rieken 已提交
90
	public get textEditorModel(): editorCommon.IModel {
E
Erich Gamma 已提交
91 92
		return this.model;
	}
93 94 95 96

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

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

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

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

	constructor() {
		this.openEditorDelegate = null;
	}

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

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

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

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

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

		return this.editor;
	}

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

		return model;
	}
}

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

	private editor: SimpleEditor;

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

J
Joao Moreno 已提交
187
	public createModelReference(resource: URI): TPromise<IReference<ITextEditorModel>> {
188 189 190 191 192 193 194 195
		let model: editorCommon.IModel;

		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 已提交
196
			return TPromise.as(new ImmortalReference(null));
197 198
		}

J
Joao Moreno 已提交
199
		return TPromise.as(new ImmortalReference(new SimpleModel(model)));
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
	}

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

	private findModel(editor: editorCommon.ICommonCodeEditor, resource: URI): editorCommon.IModel {
		let model = editor.getModel();
		if (model.uri.toString() !== resource.toString()) {
			return null;
		}

		return model;
	}
}

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

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

	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;
	}
}

E
Erich Gamma 已提交
238
export class SimpleMessageService implements IMessageService {
239

240
	public _serviceBrand: any;
E
Erich Gamma 已提交
241

J
Johannes Rieken 已提交
242
	private static Empty = function () { /* nothing */ };
E
Erich Gamma 已提交
243

J
Johannes Rieken 已提交
244
	public show(sev: Severity, message: any): () => void {
E
Erich Gamma 已提交
245

J
Johannes Rieken 已提交
246
		switch (sev) {
E
Erich Gamma 已提交
247
			case Severity.Error:
248
				console.error(message);
E
Erich Gamma 已提交
249 250 251 252 253 254 255 256 257 258 259 260
				break;
			case Severity.Warning:
				console.warn(message);
				break;
			default:
				console.log(message);
				break;
		}

		return SimpleMessageService.Empty;
	}

J
Johannes Rieken 已提交
261
	public hideAll(): void {
E
Erich Gamma 已提交
262 263 264
		// No-op
	}

265
	public confirmSync(confirmation: IConfirmation): boolean {
A
Alex Dima 已提交
266
		let messageText = confirmation.message;
E
Erich Gamma 已提交
267 268 269 270 271 272
		if (confirmation.detail) {
			messageText = messageText + '\n\n' + confirmation.detail;
		}

		return window.confirm(messageText);
	}
273 274 275 276

	public confirm(confirmation: IConfirmation): TPromise<IConfirmationResult> {
		return TPromise.as({ confirmed: this.confirmSync(confirmation) } as IConfirmationResult);
	}
A
Alex Dima 已提交
277 278
}

A
Alex Dima 已提交
279 280
export class StandaloneCommandService implements ICommandService {
	_serviceBrand: any;
281

A
Alex Dima 已提交
282
	private readonly _instantiationService: IInstantiationService;
283 284
	private _dynamicCommands: { [id: string]: ICommand; };

285 286 287
	private _onWillExecuteCommand: Emitter<ICommandEvent> = new Emitter<ICommandEvent>();
	public readonly onWillExecuteCommand: Event<ICommandEvent> = this._onWillExecuteCommand.event;

A
Alex Dima 已提交
288 289
	constructor(instantiationService: IInstantiationService) {
		this._instantiationService = instantiationService;
290 291 292
		this._dynamicCommands = Object.create(null);
	}

J
Johannes Rieken 已提交
293 294
	public addCommand(command: ICommand): IDisposable {
		const { id } = command;
295
		this._dynamicCommands[id] = command;
296 297 298 299 300
		return {
			dispose: () => {
				delete this._dynamicCommands[id];
			}
		};
301 302
	}

A
Alex Dima 已提交
303 304 305
	public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
		const command = (CommandsRegistry.getCommand(id) || this._dynamicCommands[id]);
		if (!command) {
306
			return TPromise.wrapError<T>(new Error(`command '${id}' not found`));
A
Alex Dima 已提交
307 308 309
		}

		try {
310
			this._onWillExecuteCommand.fire({ commandId: id });
A
Alex Dima 已提交
311 312 313
			const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
			return TPromise.as(result);
		} catch (err) {
314
			return TPromise.wrapError<T>(err);
A
Alex Dima 已提交
315
		}
316 317 318
	}
}

319 320
export class StandaloneKeybindingService extends AbstractKeybindingService {
	private _cachedResolver: KeybindingResolver;
E
Erich Gamma 已提交
321 322
	private _dynamicKeybindings: IKeybindingItem[];

A
Alex Dima 已提交
323
	constructor(
324
		contextKeyService: IContextKeyService,
A
Alex Dima 已提交
325
		commandService: ICommandService,
326
		telemetryService: ITelemetryService,
A
Alex Dima 已提交
327 328 329
		messageService: IMessageService,
		domNode: HTMLElement
	) {
330
		super(contextKeyService, commandService, telemetryService, messageService);
331

332
		this._cachedResolver = null;
E
Erich Gamma 已提交
333
		this._dynamicKeybindings = [];
334

335 336
		this.toDispose.push(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
			let keyEvent = new StandardKeyboardEvent(e);
337
			let shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
338 339 340 341
			if (shouldPreventDefault) {
				keyEvent.preventDefault();
			}
		}));
E
Erich Gamma 已提交
342 343
	}

344
	public addDynamicKeybinding(commandId: string, keybinding: number, handler: ICommandHandler, when: ContextKeyExpr): IDisposable {
345 346
		let toDispose: IDisposable[] = [];

E
Erich Gamma 已提交
347
		this._dynamicKeybindings.push({
A
Renames  
Alex Dima 已提交
348
			keybinding: createKeybinding(keybinding, OS),
E
Erich Gamma 已提交
349
			command: commandId,
350
			when: when,
E
Erich Gamma 已提交
351 352 353
			weight1: 1000,
			weight2: 0
		});
354

355 356 357 358 359 360 361 362 363 364 365 366 367
		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;
					}
				}
			}
		});

368 369
		let commandService = this._commandService;
		if (commandService instanceof StandaloneCommandService) {
J
Johannes Rieken 已提交
370 371
			toDispose.push(commandService.addCommand({
				id: commandId,
372
				handler: handler
373
			}));
374 375 376
		} else {
			throw new Error('Unknown command service!');
		}
C
Christof Marti 已提交
377
		this.updateResolver({ source: KeybindingSource.Default });
378

379
		return combinedDisposable(toDispose);
E
Erich Gamma 已提交
380 381
	}

382 383 384 385 386 387 388
	private updateResolver(event: IKeybindingEvent): void {
		this._cachedResolver = null;
		this._onDidUpdateKeybindings.fire(event);
	}

	protected _getResolver(): KeybindingResolver {
		if (!this._cachedResolver) {
389 390
			const defaults = this._toNormalizedKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
			const overrides = this._toNormalizedKeybindingItems(this._dynamicKeybindings, false);
391
			this._cachedResolver = new KeybindingResolver(defaults, overrides);
392 393 394 395
		}
		return this._cachedResolver;
	}

396 397
	private _toNormalizedKeybindingItems(items: IKeybindingItem[], isDefault: boolean): ResolvedKeybindingItem[] {
		let result: ResolvedKeybindingItem[] = [], resultLen = 0;
398 399 400
		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 已提交
401
			const keybinding = item.keybinding;
402

403 404 405 406 407 408 409 410 411
			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);
				}
			}
412 413 414 415 416
		}

		return result;
	}

417 418
	public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
		return [new USLayoutResolvedKeybinding(keybinding, OS)];
A
Alex Dima 已提交
419 420
	}

421 422 423 424 425 426 427 428
	public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
		let keybinding = new SimpleKeybinding(
			keyboardEvent.ctrlKey,
			keyboardEvent.shiftKey,
			keyboardEvent.altKey,
			keyboardEvent.metaKey,
			keyboardEvent.keyCode
		);
429
		return new USLayoutResolvedKeybinding(keybinding, OS);
430
	}
431 432 433 434

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

437 438 439 440 441 442 443
function isConfigurationOverrides(thing: any): thing is IConfigurationOverrides {
	return thing
		&& typeof thing === 'object'
		&& (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
		&& (!thing.resource || thing.resource instanceof URI);
}

444
export class SimpleConfigurationService implements IConfigurationService {
445

446 447
	_serviceBrand: any;

448 449
	private _onDidChangeConfiguration = new Emitter<IConfigurationChangeEvent>();
	public onDidChangeConfiguration: Event<IConfigurationChangeEvent> = this._onDidChangeConfiguration.event;
450

451
	private _configuration: Configuration;
452

453
	constructor() {
454
		this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
455 456
	}

457
	private configuration(): Configuration {
458
		return this._configuration;
459 460
	}

461 462 463 464 465 466
	getConfiguration<T>(): T
	getConfiguration<T>(section: string): T
	getConfiguration<T>(overrides: IConfigurationOverrides): T
	getConfiguration<T>(section: string, overrides: IConfigurationOverrides): T
	getConfiguration(arg1?: any, arg2?: any): any {
		const section = typeof arg1 === 'string' ? arg1 : void 0;
S
Sandeep Somavarapu 已提交
467 468
		const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
		return this.configuration().getSection(section, overrides, null);
469
	}
B
Benjamin Pasero 已提交
470

S
Sandeep Somavarapu 已提交
471 472
	public getValue<C>(key: string, options: IConfigurationOverrides = {}): C {
		return this.configuration().getValue(key, options, null);
473 474
	}

475 476
	public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise<void> {
		return TPromise.as(null);
B
Benjamin Pasero 已提交
477
	}
B
Benjamin Pasero 已提交
478

S
Sandeep Somavarapu 已提交
479
	public inspect<C>(key: string, options: IConfigurationOverrides = {}): {
480 481 482 483 484 485
		default: C,
		user: C,
		workspace: C,
		workspaceFolder: C
		value: C,
	} {
S
Sandeep Somavarapu 已提交
486
		return this.configuration().lookup<C>(key, options, null);
B
Benjamin Pasero 已提交
487
	}
488

489
	public keys() {
S
Sandeep Somavarapu 已提交
490
		return this.configuration().keys(null);
491 492
	}

493 494
	public reloadConfiguration(): TPromise<void> {
		return TPromise.as(null);
495
	}
S
Sandeep Somavarapu 已提交
496 497 498 499

	public getConfigurationData() {
		return null;
	}
500
}
A
Alex Dima 已提交
501

502 503 504 505
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

506 507
	public readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent>;
	private readonly _onDidChangeConfigurationEmitter = new Emitter();
508 509

	constructor(private configurationService: SimpleConfigurationService) {
510 511
		this.configurationService.onDidChangeConfiguration((e) => {
			this._onDidChangeConfigurationEmitter.fire(e);
512
		});
513 514 515 516 517 518 519 520
	}

	public getConfiguration<T>(): T {
		return this.configurationService.getConfiguration<T>();
	}

}

A
Alex Dima 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534
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);
	}
}
535 536 537 538 539 540 541 542 543 544 545 546 547 548

export class StandaloneTelemetryService implements ITelemetryService {
	_serviceBrand: void;

	public isOptedIn = false;

	public publicLog(eventName: string, data?: any): TPromise<void> {
		return TPromise.as<void>(null);
	}

	public getTelemetryInfo(): TPromise<ITelemetryInfo> {
		return null;
	}
}
549 550 551 552 553

export class SimpleWorkspaceContextService implements IWorkspaceContextService {

	public _serviceBrand: any;

554 555
	private static SCHEME: 'inmemory';

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

559 560
	private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent> = new Emitter<IWorkspaceFoldersChangeEvent>();
	public readonly onDidChangeWorkspaceFolders: Event<IWorkspaceFoldersChangeEvent> = this._onDidChangeWorkspaceFolders.event;
561 562 563

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

565
	private readonly workspace: IWorkspace;
566

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

B
Benjamin Pasero 已提交
572
	public getWorkspace(): IWorkspace {
573
		return this.workspace;
574 575
	}

576
	public getWorkbenchState(): WorkbenchState {
577 578
		if (this.workspace) {
			if (this.workspace.configuration) {
579
				return WorkbenchState.WORKSPACE;
580
			}
581
			return WorkbenchState.FOLDER;
582
		}
583
		return WorkbenchState.EMPTY;
584 585
	}

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

590
	public isInsideWorkspace(resource: URI): boolean {
591
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME;
592 593
	}

S
Sandeep Somavarapu 已提交
594
	public toResource(workspaceRelativePath: string, workspaceFolder: IWorkspaceFolder): URI {
595
		return URI.file(workspaceRelativePath);
596
	}
597 598 599 600

	public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
		return true;
	}
601
}