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

A
Alex Dima 已提交
6 7 8 9 10 11 12
import { localize } from 'vs/nls';
import * as dom from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { Emitter, Event } from 'vs/base/common/event';
import { Keybinding, ResolvedKeybinding, SimpleKeybinding, createKeybinding } from 'vs/base/common/keyCodes';
import { IDisposable, IReference, ImmortalReference, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { OS, isLinux, isMacintosh } from 'vs/base/common/platform';
E
Erich Gamma 已提交
13
import Severity from 'vs/base/common/severity';
14
import { URI } from 'vs/base/common/uri';
J
Johannes Rieken 已提交
15
import { TPromise } from 'vs/base/common/winjs.base';
16
import { ICodeEditor, IDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
A
Alex Dima 已提交
17 18 19 20
import { IBulkEditOptions, IBulkEditResult, IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { isDiffEditorConfigurationKey, isEditorConfigurationKey } from 'vs/editor/common/config/commonEditorConfig';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { IPosition, Position as Pos } from 'vs/editor/common/core/position';
21
import { Range } from 'vs/editor/common/core/range';
A
Alex Dima 已提交
22
import * as editorCommon from 'vs/editor/common/editorCommon';
A
Alex Dima 已提交
23
import { ITextModel } from 'vs/editor/common/model';
A
Alex Dima 已提交
24
import { TextEdit, WorkspaceEdit, isResourceTextEdit } from 'vs/editor/common/modes';
25
import { IModelService } from 'vs/editor/common/services/modelService';
A
Alex Dima 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39
import { ITextEditorModel, ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
import { CommandsRegistry, ICommand, ICommandEvent, ICommandHandler, ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationChangeEvent, IConfigurationData, IConfigurationOverrides, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Configuration, ConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IConfirmation, IConfirmationResult, IDialogOptions, IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { IKeybindingEvent, IKeyboardEvent, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
import { IKeybindingItem, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
40
import { ILabelService, LabelRules, RegisterFormatterEvent } from 'vs/platform/label/common/label';
A
Alex Dima 已提交
41 42 43 44 45
import { INotification, INotificationHandle, INotificationService, IPromptChoice, IPromptOptions, NoOpNotification } from 'vs/platform/notification/common/notification';
import { IProgressRunner, IProgressService } from 'vs/platform/progress/common/progress';
import { ITelemetryInfo, ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspace, IWorkspaceContextService, IWorkspaceFolder, IWorkspaceFoldersChangeEvent, WorkbenchState, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
E
Erich Gamma 已提交
46

J
Johannes Rieken 已提交
47
export class SimpleModel implements ITextEditorModel {
E
Erich Gamma 已提交
48

A
Alex Dima 已提交
49
	private model: ITextModel;
M
Matt Bierner 已提交
50
	private readonly _onDispose: Emitter<void>;
E
Erich Gamma 已提交
51

A
Alex Dima 已提交
52
	constructor(model: ITextModel) {
E
Erich Gamma 已提交
53
		this.model = model;
54 55 56 57 58
		this._onDispose = new Emitter<void>();
	}

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

61 62 63 64
	public load(): TPromise<SimpleModel> {
		return TPromise.as(this);
	}

A
Alex Dima 已提交
65
	public get textEditorModel(): ITextModel {
E
Erich Gamma 已提交
66 67
		return this.model;
	}
68

69 70 71 72
	public isReadonly(): boolean {
		return false;
	}

73 74 75
	public dispose(): void {
		this._onDispose.fire();
	}
E
Erich Gamma 已提交
76 77 78
}

export interface IOpenEditorDelegate {
J
Johannes Rieken 已提交
79
	(url: string): boolean;
E
Erich Gamma 已提交
80 81
}

B
Benjamin Pasero 已提交
82 83 84 85 86 87 88 89 90 91
function withTypedEditor<T>(widget: editorCommon.IEditor, codeEditorCallback: (editor: ICodeEditor) => T, diffEditorCallback: (editor: IDiffEditor) => T): T {
	if (isCodeEditor(widget)) {
		// Single Editor
		return codeEditorCallback(<ICodeEditor>widget);
	} else {
		// Diff Editor
		return diffEditorCallback(<IDiffEditor>widget);
	}
}

92
export class SimpleEditorModelResolverService implements ITextModelService {
93 94
	public _serviceBrand: any;

B
Benjamin Pasero 已提交
95
	private editor: editorCommon.IEditor;
96 97

	public setEditor(editor: editorCommon.IEditor): void {
B
Benjamin Pasero 已提交
98
		this.editor = editor;
99 100
	}

J
Joao Moreno 已提交
101
	public createModelReference(resource: URI): TPromise<IReference<ITextEditorModel>> {
A
Alex Dima 已提交
102
		let model: ITextModel;
103

B
Benjamin Pasero 已提交
104
		model = withTypedEditor(this.editor,
105 106 107 108 109
			(editor) => this.findModel(editor, resource),
			(diffEditor) => this.findModel(diffEditor.getOriginalEditor(), resource) || this.findModel(diffEditor.getModifiedEditor(), resource)
		);

		if (!model) {
J
Joao Moreno 已提交
110
			return TPromise.as(new ImmortalReference(null));
111 112
		}

J
Joao Moreno 已提交
113
		return TPromise.as(new ImmortalReference(new SimpleModel(model)));
114 115 116 117 118 119 120 121
	}

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

A
Alex Dima 已提交
122
	private findModel(editor: ICodeEditor, resource: URI): ITextModel | null {
123
		let model = editor.getModel();
A
Alex Dima 已提交
124
		if (model && model.uri.toString() !== resource.toString()) {
125 126 127 128 129 130 131
			return null;
		}

		return model;
	}
}

132 133 134
export class SimpleProgressService implements IProgressService {
	_serviceBrand: any;

J
Johannes Rieken 已提交
135 136 137 138
	private static NULL_PROGRESS_RUNNER: IProgressRunner = {
		done: () => { },
		total: () => { },
		worked: () => { }
139 140 141 142 143 144 145 146
	};

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

A
Alex Dima 已提交
147
	showWhile(promise: Thenable<any>, delay?: number): Thenable<void> {
148 149 150 151
		return null;
	}
}

152
export class SimpleDialogService implements IDialogService {
153 154

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

A
Alex Dima 已提交
156
	public confirm(confirmation: IConfirmation): Thenable<IConfirmationResult> {
157 158 159 160 161 162 163 164
		return this.doConfirm(confirmation).then(confirmed => {
			return {
				confirmed,
				checkboxChecked: false // unsupported
			} as IConfirmationResult;
		});
	}

A
Alex Dima 已提交
165
	private doConfirm(confirmation: IConfirmation): Thenable<boolean> {
A
Alex Dima 已提交
166
		let messageText = confirmation.message;
E
Erich Gamma 已提交
167 168 169 170
		if (confirmation.detail) {
			messageText = messageText + '\n\n' + confirmation.detail;
		}

A
Alex Dima 已提交
171
		return Promise.resolve(window.confirm(messageText));
E
Erich Gamma 已提交
172
	}
173

A
Alex Dima 已提交
174 175
	public show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Thenable<number> {
		return Promise.resolve(0);
176
	}
A
Alex Dima 已提交
177 178
}

179 180 181 182
export class SimpleNotificationService implements INotificationService {

	public _serviceBrand: any;

183
	private static readonly NO_OP: INotificationHandle = new NoOpNotification();
184

B
Benjamin Pasero 已提交
185 186 187 188 189 190 191 192 193
	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 {
194 195 196
		return this.notify({ severity: Severity.Error, message: error });
	}

197 198
	public notify(notification: INotification): INotificationHandle {
		switch (notification.severity) {
199
			case Severity.Error:
200
				console.error(notification.message);
201 202
				break;
			case Severity.Warning:
203
				console.warn(notification.message);
204 205
				break;
			default:
206
				console.log(notification.message);
207 208 209
				break;
		}

210
		return SimpleNotificationService.NO_OP;
211
	}
212

B
Benjamin Pasero 已提交
213
	public prompt(severity: Severity, message: string, choices: IPromptChoice[], options?: IPromptOptions): INotificationHandle {
214
		return SimpleNotificationService.NO_OP;
215
	}
216 217
}

A
Alex Dima 已提交
218 219
export class StandaloneCommandService implements ICommandService {
	_serviceBrand: any;
220

A
Alex Dima 已提交
221
	private readonly _instantiationService: IInstantiationService;
222 223
	private _dynamicCommands: { [id: string]: ICommand; };

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

A
Alex Dima 已提交
227 228
	constructor(instantiationService: IInstantiationService) {
		this._instantiationService = instantiationService;
229 230 231
		this._dynamicCommands = Object.create(null);
	}

J
Johannes Rieken 已提交
232 233
	public addCommand(command: ICommand): IDisposable {
		const { id } = command;
234
		this._dynamicCommands[id] = command;
235 236 237
		return toDisposable(() => {
			delete this._dynamicCommands[id];
		});
238 239
	}

240
	public executeCommand<T>(id: string, ...args: any[]): Promise<T> {
A
Alex Dima 已提交
241 242
		const command = (CommandsRegistry.getCommand(id) || this._dynamicCommands[id]);
		if (!command) {
243
			return Promise.reject(new Error(`command '${id}' not found`));
A
Alex Dima 已提交
244 245 246
		}

		try {
247
			this._onWillExecuteCommand.fire({ commandId: id });
A
Alex Dima 已提交
248
			const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
249
			return Promise.resolve(result);
A
Alex Dima 已提交
250
		} catch (err) {
251
			return Promise.reject(err);
A
Alex Dima 已提交
252
		}
253 254 255
	}
}

256
export class StandaloneKeybindingService extends AbstractKeybindingService {
A
Alex Dima 已提交
257
	private _cachedResolver: KeybindingResolver | null;
E
Erich Gamma 已提交
258 259
	private _dynamicKeybindings: IKeybindingItem[];

A
Alex Dima 已提交
260
	constructor(
261
		contextKeyService: IContextKeyService,
A
Alex Dima 已提交
262
		commandService: ICommandService,
263
		telemetryService: ITelemetryService,
264
		notificationService: INotificationService,
A
Alex Dima 已提交
265 266
		domNode: HTMLElement
	) {
267
		super(contextKeyService, commandService, telemetryService, notificationService);
268

269
		this._cachedResolver = null;
E
Erich Gamma 已提交
270
		this._dynamicKeybindings = [];
271

272
		this._register(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
273
			let keyEvent = new StandardKeyboardEvent(e);
274
			let shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
275 276 277 278
			if (shouldPreventDefault) {
				keyEvent.preventDefault();
			}
		}));
E
Erich Gamma 已提交
279 280
	}

A
Alex Dima 已提交
281
	public addDynamicKeybinding(commandId: string, keybinding: number, handler: ICommandHandler, when: ContextKeyExpr | null): IDisposable {
282 283
		let toDispose: IDisposable[] = [];

E
Erich Gamma 已提交
284
		this._dynamicKeybindings.push({
A
Renames  
Alex Dima 已提交
285
			keybinding: createKeybinding(keybinding, OS),
E
Erich Gamma 已提交
286
			command: commandId,
287
			when: when,
E
Erich Gamma 已提交
288 289 290
			weight1: 1000,
			weight2: 0
		});
291

292 293 294 295 296 297 298
		toDispose.push(toDisposable(() => {
			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;
299 300
				}
			}
301
		}));
302

303 304
		let commandService = this._commandService;
		if (commandService instanceof StandaloneCommandService) {
J
Johannes Rieken 已提交
305 306
			toDispose.push(commandService.addCommand({
				id: commandId,
307
				handler: handler
308
			}));
309 310 311
		} else {
			throw new Error('Unknown command service!');
		}
C
Christof Marti 已提交
312
		this.updateResolver({ source: KeybindingSource.Default });
313

314
		return combinedDisposable(toDispose);
E
Erich Gamma 已提交
315 316
	}

317 318 319 320 321 322 323
	private updateResolver(event: IKeybindingEvent): void {
		this._cachedResolver = null;
		this._onDidUpdateKeybindings.fire(event);
	}

	protected _getResolver(): KeybindingResolver {
		if (!this._cachedResolver) {
324 325
			const defaults = this._toNormalizedKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
			const overrides = this._toNormalizedKeybindingItems(this._dynamicKeybindings, false);
326
			this._cachedResolver = new KeybindingResolver(defaults, overrides);
327 328 329 330
		}
		return this._cachedResolver;
	}

331 332 333 334
	protected _documentHasFocus(): boolean {
		return document.hasFocus();
	}

335 336
	private _toNormalizedKeybindingItems(items: IKeybindingItem[], isDefault: boolean): ResolvedKeybindingItem[] {
		let result: ResolvedKeybindingItem[] = [], resultLen = 0;
337 338 339
		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 已提交
340
			const keybinding = item.keybinding;
341

342 343 344 345 346 347 348 349 350
			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);
				}
			}
351 352 353 354 355
		}

		return result;
	}

356 357
	public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
		return [new USLayoutResolvedKeybinding(keybinding, OS)];
A
Alex Dima 已提交
358 359
	}

360 361 362 363 364 365 366 367
	public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
		let keybinding = new SimpleKeybinding(
			keyboardEvent.ctrlKey,
			keyboardEvent.shiftKey,
			keyboardEvent.altKey,
			keyboardEvent.metaKey,
			keyboardEvent.keyCode
		);
368
		return new USLayoutResolvedKeybinding(keybinding, OS);
369
	}
370 371 372 373

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

376 377 378 379 380 381 382
function isConfigurationOverrides(thing: any): thing is IConfigurationOverrides {
	return thing
		&& typeof thing === 'object'
		&& (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
		&& (!thing.resource || thing.resource instanceof URI);
}

383
export class SimpleConfigurationService implements IConfigurationService {
384

385 386
	_serviceBrand: any;

387
	private _onDidChangeConfiguration = new Emitter<IConfigurationChangeEvent>();
388
	public readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent> = this._onDidChangeConfiguration.event;
389

390
	private _configuration: Configuration;
391

392
	constructor() {
393
		this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
394 395
	}

396
	private configuration(): Configuration {
397
		return this._configuration;
398 399
	}

400 401 402 403 404 405 406 407
	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);
408 409
	}

S
Sandeep Somavarapu 已提交
410
	public updateValue(key: string, value: any, arg3?: any, arg4?: any): Promise<void> {
411
		this.configuration().updateValue(key, value);
A
Alex Dima 已提交
412
		return Promise.resolve();
B
Benjamin Pasero 已提交
413
	}
B
Benjamin Pasero 已提交
414

S
Sandeep Somavarapu 已提交
415
	public inspect<C>(key: string, options: IConfigurationOverrides = {}): {
416 417
		default: C,
		user: C,
M
Matt Bierner 已提交
418 419
		workspace?: C,
		workspaceFolder?: C
420 421
		value: C,
	} {
422
		return this.configuration().inspect<C>(key, options, null);
B
Benjamin Pasero 已提交
423
	}
424

425
	public keys() {
S
Sandeep Somavarapu 已提交
426
		return this.configuration().keys(null);
427 428
	}

S
Sandeep Somavarapu 已提交
429 430
	public reloadConfiguration(): Promise<void> {
		return Promise.resolve(null);
431
	}
S
Sandeep Somavarapu 已提交
432

A
Alex Dima 已提交
433
	public getConfigurationData(): IConfigurationData {
S
Sandeep Somavarapu 已提交
434 435
		return null;
	}
436
}
A
Alex Dima 已提交
437

438 439 440 441
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

442 443
	public readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent>;
	private readonly _onDidChangeConfigurationEmitter = new Emitter();
444 445

	constructor(private configurationService: SimpleConfigurationService) {
446 447
		this.configurationService.onDidChangeConfiguration((e) => {
			this._onDidChangeConfigurationEmitter.fire(e);
448
		});
449 450
	}

451 452 453 454 455 456
	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);
457 458 459
	}
}

S
Sandeep Somavarapu 已提交
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
export class SimpleResourcePropertiesService implements ITextResourcePropertiesService {

	_serviceBrand: any;

	constructor(
		@IConfigurationService private configurationService: IConfigurationService,
	) {
	}

	getEOL(resource: URI): string {
		const filesConfiguration = this.configurationService.getValue<{ eol: string }>('files');
		if (filesConfiguration && filesConfiguration.eol) {
			if (filesConfiguration.eol !== 'auto') {
				return filesConfiguration.eol;
			}
		}
		return (isLinux || isMacintosh) ? '\n' : '\r\n';
	}
}

480 481 482 483 484 485
export class StandaloneTelemetryService implements ITelemetryService {
	_serviceBrand: void;

	public isOptedIn = false;

	public publicLog(eventName: string, data?: any): TPromise<void> {
486
		return TPromise.wrap<void>(null);
487 488 489 490 491 492
	}

	public getTelemetryInfo(): TPromise<ITelemetryInfo> {
		return null;
	}
}
493 494 495 496 497

export class SimpleWorkspaceContextService implements IWorkspaceContextService {

	public _serviceBrand: any;

498
	private static SCHEME = 'inmemory';
499

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

503 504
	private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent> = new Emitter<IWorkspaceFoldersChangeEvent>();
	public readonly onDidChangeWorkspaceFolders: Event<IWorkspaceFoldersChangeEvent> = this._onDidChangeWorkspaceFolders.event;
505 506 507

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

509
	private readonly workspace: IWorkspace;
510

511
	constructor() {
512
		const resource = URI.from({ scheme: SimpleWorkspaceContextService.SCHEME, authority: 'model', path: '/' });
I
isidor 已提交
513
		this.workspace = { id: '4064f6ec-cb38-4ad0-af64-ee6467e63c82', folders: [new WorkspaceFolder({ uri: resource, name: '', index: 0 })] };
514 515
	}

B
Benjamin Pasero 已提交
516
	public getWorkspace(): IWorkspace {
517
		return this.workspace;
518 519
	}

520
	public getWorkbenchState(): WorkbenchState {
521 522
		if (this.workspace) {
			if (this.workspace.configuration) {
523
				return WorkbenchState.WORKSPACE;
524
			}
525
			return WorkbenchState.FOLDER;
526
		}
527
		return WorkbenchState.EMPTY;
528 529
	}

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

534
	public isInsideWorkspace(resource: URI): boolean {
535
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME;
536 537
	}

538
	public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
539 540
		return true;
	}
541
}
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

export function applyConfigurationValues(configurationService: IConfigurationService, source: any, isDiffEditor: boolean): void {
	if (!source) {
		return;
	}
	if (!(configurationService instanceof SimpleConfigurationService)) {
		return;
	}
	Object.keys(source).forEach((key) => {
		if (isEditorConfigurationKey(key)) {
			configurationService.updateValue(`editor.${key}`, source[key]);
		}
		if (isDiffEditor && isDiffEditorConfigurationKey(key)) {
			configurationService.updateValue(`diffEditor.${key}`, source[key]);
		}
	});
}
559 560 561 562 563 564 565 566

export class SimpleBulkEditService implements IBulkEditService {
	_serviceBrand: any;

	constructor(private readonly _modelService: IModelService) {
		//
	}

567
	apply(workspaceEdit: WorkspaceEdit, options: IBulkEditOptions): Promise<IBulkEditResult> {
568 569 570 571 572

		let edits = new Map<ITextModel, TextEdit[]>();

		for (let edit of workspaceEdit.edits) {
			if (!isResourceTextEdit(edit)) {
573
				return Promise.reject(new Error('bad edit - only text edits are supported'));
574 575 576
			}
			let model = this._modelService.getModel(edit.resource);
			if (!model) {
577
				return Promise.reject(new Error('bad edit - model not found'));
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
			}
			let array = edits.get(model);
			if (!array) {
				array = [];
			}
			edits.set(model, array.concat(edit.edits));
		}

		let totalEdits = 0;
		let totalFiles = 0;
		edits.forEach((edits, model) => {
			model.applyEdits(edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text)));
			totalFiles += 1;
			totalEdits += edits.length;
		});

594
		return Promise.resolve({
595 596 597 598 599
			selection: undefined,
			ariaSummary: localize('summary', 'Made {0} edits in {1} files', totalEdits, totalFiles)
		});
	}
}
A
Alex Dima 已提交
600

I
isidor 已提交
601
export class SimpleUriLabelService implements ILabelService {
A
Alex Dima 已提交
602 603
	_serviceBrand: any;

604 605
	private readonly _onDidRegisterFormatter: Emitter<RegisterFormatterEvent> = new Emitter<RegisterFormatterEvent>();
	public readonly onDidRegisterFormatter: Event<RegisterFormatterEvent> = this._onDidRegisterFormatter.event;
A
Alex Dima 已提交
606

607
	public getUriLabel(resource: URI, options?: { relative?: boolean, forceNoTildify?: boolean }): string {
A
Alex Dima 已提交
608 609 610 611 612 613
		if (resource.scheme === 'file') {
			return resource.fsPath;
		}
		return resource.path;
	}

I
isidor 已提交
614 615
	public getWorkspaceLabel(workspace: IWorkspaceIdentifier | URI | IWorkspace, options?: { verbose: boolean; }): string {
		return '';
616 617
	}

618
	public registerFormatter(selector: string, formatter: LabelRules): IDisposable {
A
Alex Dima 已提交
619 620 621
		throw new Error('Not implemented');
	}
}