simpleServices.ts 17.9 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';
J
Joao Moreno 已提交
12
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, Position } from 'vs/platform/editor/common/editor';
13
import { ICommandService, ICommand, ICommandEvent, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
14 15
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
16
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
17
import { IKeybindingEvent, KeybindingSource, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
18
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
J
Johannes Rieken 已提交
19
import { IConfirmation, IMessageService } from 'vs/platform/message/common/message';
20
import { IWorkspaceContextService, ILegacyWorkspace, IWorkspace } from 'vs/platform/workspace/common/workspace';
A
Alex Dima 已提交
21
import * as editorCommon from 'vs/editor/common/editorCommon';
J
Johannes Rieken 已提交
22 23 24
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { Selection } from 'vs/editor/common/core/selection';
import Event, { Emitter } from 'vs/base/common/event';
25
import { DefaultConfigurationModel } from 'vs/platform/configuration/common/model';
J
Johannes Rieken 已提交
26 27
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
28
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
29
import { ITextModelService, ITextModelContentProvider, ITextEditorModel } from 'vs/editor/common/services/resolverService';
30
import { IDisposable, IReference, ImmortalReference, combinedDisposable } from 'vs/base/common/lifecycle';
31 32
import * as dom from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
A
Renames  
Alex Dima 已提交
33
import { KeybindingsRegistry, IKeybindingItem } from 'vs/platform/keybinding/common/keybindingsRegistry';
34
import { MenuId, IMenu, IMenuService } from 'vs/platform/actions/common/actions';
A
Alex Dima 已提交
35
import { Menu } from 'vs/platform/actions/common/menu';
36
import { ITelemetryService, ITelemetryExperiments, ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
37
import { ResolvedKeybinding, Keybinding, createKeybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
38
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
A
Alex Dima 已提交
39
import { OS } from 'vs/base/common/platform';
40
import { IRange } from 'vs/editor/common/core/range';
E
Erich Gamma 已提交
41 42 43

export class SimpleEditor implements IEditor {

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

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

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

J
Johannes Rieken 已提交
54 55 56 57 58
	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 已提交
59

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

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

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

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

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

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

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

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

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

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

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

	constructor() {
		this.openEditorDelegate = null;
	}

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

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

J
Johannes Rieken 已提交
120
	public openEditor(typedData: IResourceInput, sideBySide?: boolean): TPromise<IEditor> {
E
Erich Gamma 已提交
121 122 123 124 125 126 127 128 129
		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 已提交
130
	private doOpenEditor(editor: editorCommon.ICommonCodeEditor, data: IResourceInput): IEditor {
A
Alex Dima 已提交
131
		let model = this.findModel(editor, data);
E
Erich Gamma 已提交
132 133 134 135 136 137
		if (!model) {
			if (data.resource) {
				if (this.openEditorDelegate) {
					this.openEditorDelegate(data.resource.toString());
					return null;
				} else {
A
Alex Dima 已提交
138
					let schema = data.resource.scheme;
A
Alex Dima 已提交
139
					if (schema === Schemas.http || schema === Schemas.https) {
E
Erich Gamma 已提交
140 141 142 143 144 145 146 147 148
						// This is a fully qualified http or https URL
						window.open(data.resource.toString());
						return this.editor;
					}
				}
			}
			return null;
		}

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

		return this.editor;
	}

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

		return model;
	}
}

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

	private editor: SimpleEditor;

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

J
Joao Moreno 已提交
186
	public createModelReference(resource: URI): TPromise<IReference<ITextEditorModel>> {
187 188 189 190 191 192 193 194
		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 已提交
195
			return TPromise.as(new ImmortalReference(null));
196 197
		}

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

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

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

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

	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 已提交
237
export class SimpleMessageService implements IMessageService {
238
	public _serviceBrand: any;
E
Erich Gamma 已提交
239

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

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

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

		return SimpleMessageService.Empty;
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		return result;
	}

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

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

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

428
export class SimpleConfigurationService implements IConfigurationService {
429

430 431
	_serviceBrand: any;

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

435
	private _configuration: Configuration<any>;
436

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

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

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

449 450 451 452 453 454
	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 已提交
455
	}
B
Benjamin Pasero 已提交
456 457

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

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

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

470 471 472 473
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

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

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

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

}

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

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

	public getExperiments(): ITelemetryExperiments {
		return null;
	}
}
521 522 523 524 525

export class SimpleWorkspaceContextService implements IWorkspaceContextService {

	public _serviceBrand: any;

526 527
	private static SCHEME: 'inmemory';

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

531
	private readonly legacyWorkspace: ILegacyWorkspace;
532
	private readonly workspace: IWorkspace;
533

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

539 540
	public getWorkspace(): ILegacyWorkspace {
		return this.legacyWorkspace;
541 542
	}

543
	public getWorkspace2(): IWorkspace {
544
		return this.workspace;
545 546
	}

547
	public getRoot(resource: URI): URI {
548
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME ? this.workspace.roots[0] : void 0;
549 550
	}

551
	public hasWorkspace(): boolean {
552
		return true;
553 554 555
	}

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

	public toWorkspaceRelativePath(resource: URI, toOSPath?: boolean): string {
560
		return resource.fsPath;
561 562 563
	}

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