simpleServices.ts 18.1 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, IConfigurationServiceEvent, IConfigurationValue, IConfigurationKeys, IConfigurationValues, Configuration, IConfigurationData, ConfigurationModel, 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';
J
Johannes Rieken 已提交
20
import { IConfirmation, IMessageService } from 'vs/platform/message/common/message';
21
import { IWorkspaceContextService, IWorkspace, WorkbenchState } 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 { DefaultConfigurationModel } from 'vs/platform/configuration/common/model';
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 142 143 144 145 146 147 148 149
						// This is a fully qualified http or https URL
						window.open(data.resource.toString());
						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
	public _serviceBrand: any;
E
Erich Gamma 已提交
240

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

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

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

		return SimpleMessageService.Empty;
	}

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

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

		return window.confirm(messageText);
	}
A
Alex Dima 已提交
272 273
}

A
Alex Dima 已提交
274 275
export class StandaloneCommandService implements ICommandService {
	_serviceBrand: any;
276

A
Alex Dima 已提交
277
	private readonly _instantiationService: IInstantiationService;
278 279
	private _dynamicCommands: { [id: string]: ICommand; };

280 281 282
	private _onWillExecuteCommand: Emitter<ICommandEvent> = new Emitter<ICommandEvent>();
	public readonly onWillExecuteCommand: Event<ICommandEvent> = this._onWillExecuteCommand.event;

A
Alex Dima 已提交
283 284
	constructor(instantiationService: IInstantiationService) {
		this._instantiationService = instantiationService;
285 286 287
		this._dynamicCommands = Object.create(null);
	}

288
	public addCommand(id: string, command: ICommand): IDisposable {
289
		this._dynamicCommands[id] = command;
290 291 292 293 294
		return {
			dispose: () => {
				delete this._dynamicCommands[id];
			}
		};
295 296
	}

A
Alex Dima 已提交
297 298 299
	public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
		const command = (CommandsRegistry.getCommand(id) || this._dynamicCommands[id]);
		if (!command) {
300
			return TPromise.wrapError<T>(new Error(`command '${id}' not found`));
A
Alex Dima 已提交
301 302 303
		}

		try {
304
			this._onWillExecuteCommand.fire({ commandId: id });
A
Alex Dima 已提交
305 306 307
			const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
			return TPromise.as(result);
		} catch (err) {
308
			return TPromise.wrapError<T>(err);
A
Alex Dima 已提交
309
		}
310 311 312
	}
}

313 314
export class StandaloneKeybindingService extends AbstractKeybindingService {
	private _cachedResolver: KeybindingResolver;
E
Erich Gamma 已提交
315 316
	private _dynamicKeybindings: IKeybindingItem[];

A
Alex Dima 已提交
317
	constructor(
318
		contextKeyService: IContextKeyService,
A
Alex Dima 已提交
319 320 321 322
		commandService: ICommandService,
		messageService: IMessageService,
		domNode: HTMLElement
	) {
323
		super(contextKeyService, commandService, messageService);
324

325
		this._cachedResolver = null;
E
Erich Gamma 已提交
326
		this._dynamicKeybindings = [];
327

328 329
		this.toDispose.push(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
			let keyEvent = new StandardKeyboardEvent(e);
330
			let shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
331 332 333 334
			if (shouldPreventDefault) {
				keyEvent.preventDefault();
			}
		}));
E
Erich Gamma 已提交
335 336
	}

337
	public addDynamicKeybinding(commandId: string, keybinding: number, handler: ICommandHandler, when: ContextKeyExpr): IDisposable {
338 339
		let toDispose: IDisposable[] = [];

E
Erich Gamma 已提交
340
		this._dynamicKeybindings.push({
A
Renames  
Alex Dima 已提交
341
			keybinding: createKeybinding(keybinding, OS),
E
Erich Gamma 已提交
342
			command: commandId,
343
			when: when,
E
Erich Gamma 已提交
344 345 346
			weight1: 1000,
			weight2: 0
		});
347

348 349 350 351 352 353 354 355 356 357 358 359 360
		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;
					}
				}
			}
		});

361 362
		let commandService = this._commandService;
		if (commandService instanceof StandaloneCommandService) {
363
			toDispose.push(commandService.addCommand(commandId, {
364
				handler: handler
365
			}));
366 367 368
		} else {
			throw new Error('Unknown command service!');
		}
C
Christof Marti 已提交
369
		this.updateResolver({ source: KeybindingSource.Default });
370

371
		return combinedDisposable(toDispose);
E
Erich Gamma 已提交
372 373
	}

374 375 376 377 378 379 380
	private updateResolver(event: IKeybindingEvent): void {
		this._cachedResolver = null;
		this._onDidUpdateKeybindings.fire(event);
	}

	protected _getResolver(): KeybindingResolver {
		if (!this._cachedResolver) {
381 382
			const defaults = this._toNormalizedKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
			const overrides = this._toNormalizedKeybindingItems(this._dynamicKeybindings, false);
383
			this._cachedResolver = new KeybindingResolver(defaults, overrides);
384 385 386 387
		}
		return this._cachedResolver;
	}

388 389
	private _toNormalizedKeybindingItems(items: IKeybindingItem[], isDefault: boolean): ResolvedKeybindingItem[] {
		let result: ResolvedKeybindingItem[] = [], resultLen = 0;
390 391 392
		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 已提交
393
			const keybinding = item.keybinding;
394

395 396 397 398 399 400 401 402 403
			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);
				}
			}
404 405 406 407 408
		}

		return result;
	}

409 410
	public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
		return [new USLayoutResolvedKeybinding(keybinding, OS)];
A
Alex Dima 已提交
411 412
	}

413 414 415 416 417 418 419 420
	public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
		let keybinding = new SimpleKeybinding(
			keyboardEvent.ctrlKey,
			keyboardEvent.shiftKey,
			keyboardEvent.altKey,
			keyboardEvent.metaKey,
			keyboardEvent.keyCode
		);
421
		return new USLayoutResolvedKeybinding(keybinding, OS);
422
	}
423 424 425 426

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

429
export class SimpleConfigurationService implements IConfigurationService {
430

431 432
	_serviceBrand: any;

433 434
	private _onDidUpdateConfiguration = new Emitter<IConfigurationServiceEvent>();
	public onDidUpdateConfiguration: Event<IConfigurationServiceEvent> = this._onDidUpdateConfiguration.event;
435

436
	private _configuration: Configuration<any>;
437

438
	constructor() {
439
		this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
440 441
	}

442 443
	private configuration(): Configuration<any> {
		return this._configuration;
444 445
	}

446
	public reloadConfiguration<T>(section?: string): TPromise<T> {
447
		return TPromise.as<T>(this.getConfiguration<T>(section));
448
	}
B
Benjamin Pasero 已提交
449

450 451 452 453 454 455
	public getConfiguration<C>(section?: string, options?: IConfigurationOverrides): C {
		return this.configuration().getValue<C>(section, options);
	}

	public lookup<C>(key: string, options?: IConfigurationOverrides): IConfigurationValue<C> {
		return this.configuration().lookup<C>(key, options);
B
Benjamin Pasero 已提交
456
	}
B
Benjamin Pasero 已提交
457 458

	public keys(): IConfigurationKeys {
459
		return this.configuration().keys();
B
Benjamin Pasero 已提交
460
	}
461

462 463 464 465 466 467
	public values<V>(): IConfigurationValues {
		return this._configuration.values();
	}

	public getConfigurationData(): IConfigurationData<any> {
		return this.configuration().toData();
468
	}
469
}
A
Alex Dima 已提交
470

471 472 473 474
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

475 476
	public readonly onDidUpdateConfiguration: Event<void>;
	private readonly _onDidUpdateConfigurationEmitter = new Emitter();
477 478

	constructor(private configurationService: SimpleConfigurationService) {
479 480 481
		this.configurationService.onDidUpdateConfiguration(() => {
			this._onDidUpdateConfigurationEmitter.fire();
		});
482 483 484 485 486 487 488 489
	}

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

}

A
Alex Dima 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502 503
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);
	}
}
504 505 506 507 508 509 510 511 512 513 514 515 516 517

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;
	}
}
518 519 520 521 522

export class SimpleWorkspaceContextService implements IWorkspaceContextService {

	public _serviceBrand: any;

523 524
	private static SCHEME: 'inmemory';

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

528 529
	private readonly _onDidChangeWorkspaceRoots: Emitter<void> = new Emitter<void>();
	public readonly onDidChangeWorkspaceRoots: Event<void> = this._onDidChangeWorkspaceRoots.event;
530

531
	private readonly workspace: IWorkspace;
532

533
	constructor() {
534 535
		const resource = URI.from({ scheme: SimpleWorkspaceContextService.SCHEME, authority: 'model', path: '/' });
		this.workspace = { id: '4064f6ec-cb38-4ad0-af64-ee6467e63c82', roots: [resource], name: resource.fsPath };
536 537
	}

B
Benjamin Pasero 已提交
538
	public getWorkspace(): IWorkspace {
539
		return this.workspace;
540 541
	}

542
	public getWorkbenchState(): WorkbenchState {
543 544
		if (this.workspace) {
			if (this.workspace.configuration) {
545
				return WorkbenchState.WORKSPACE;
546
			}
547
			return WorkbenchState.FOLDER;
548
		}
549
		return WorkbenchState.EMPTY;
550 551
	}

552
	public getRoot(resource: URI): URI {
553
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME ? this.workspace.roots[0] : void 0;
554 555
	}

556
	public isInsideWorkspace(resource: URI): boolean {
557
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME;
558 559 560
	}

	public toResource(workspaceRelativePath: string): URI {
561
		return URI.file(workspaceRelativePath);
562
	}
563 564 565 566

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