simpleServices.ts 21.0 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.
 *--------------------------------------------------------------------------------------------*/

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

J
Johannes Rieken 已提交
49
export class SimpleModel implements ITextEditorModel {
E
Erich Gamma 已提交
50

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

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

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

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

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

71 72 73 74
	public isReadonly(): boolean {
		return false;
	}

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

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

B
Benjamin Pasero 已提交
84 85 86 87 88 89 90 91 92 93
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);
	}
}

94
export class SimpleEditorModelResolverService implements ITextModelService {
95 96
	public _serviceBrand: any;

B
Benjamin Pasero 已提交
97
	private editor: editorCommon.IEditor;
98 99

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

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

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

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

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

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

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

		return model;
	}
}

134 135 136
export class SimpleProgressService implements IProgressService {
	_serviceBrand: any;

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

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

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

154
export class SimpleDialogService implements IDialogService {
155 156

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

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

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

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

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

181 182 183 184
export class SimpleNotificationService implements INotificationService {

	public _serviceBrand: any;

185
	private static readonly NO_OP: INotificationHandle = new NoOpNotification();
186

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

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

212
		return SimpleNotificationService.NO_OP;
213
	}
214

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

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

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

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

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

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

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

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

258 259
export class StandaloneKeybindingService extends AbstractKeybindingService {
	private _cachedResolver: KeybindingResolver;
E
Erich Gamma 已提交
260 261
	private _dynamicKeybindings: IKeybindingItem[];

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

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

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

283
	public addDynamicKeybinding(commandId: string, keybinding: number, handler: ICommandHandler, when: ContextKeyExpr): IDisposable {
284 285
		let toDispose: IDisposable[] = [];

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

294 295 296 297 298 299 300
		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;
301 302
				}
			}
303
		}));
304

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

316
		return combinedDisposable(toDispose);
E
Erich Gamma 已提交
317 318
	}

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

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

333 334 335 336
	protected _documentHasFocus(): boolean {
		return document.hasFocus();
	}

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

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

		return result;
	}

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

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

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

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

385
export class SimpleConfigurationService implements IConfigurationService {
386

387 388
	_serviceBrand: any;

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

392
	private _configuration: Configuration;
393

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

398
	private configuration(): Configuration {
399
		return this._configuration;
400 401
	}

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

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

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

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

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

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

440 441 442 443
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

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

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

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

A
Alex Dima 已提交
462 463 464 465 466 467 468 469 470 471 472
export class SimpleMenuService implements IMenuService {

	_serviceBrand: any;

	private readonly _commandService: ICommandService;

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

	public createMenu(id: MenuId, contextKeyService: IContextKeyService): IMenu {
A
Alex Dima 已提交
473
		return new Menu(id, Promise.resolve(true), this._commandService, contextKeyService);
A
Alex Dima 已提交
474 475
	}
}
476 477 478 479 480 481 482

export class StandaloneTelemetryService implements ITelemetryService {
	_serviceBrand: void;

	public isOptedIn = false;

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

	public getTelemetryInfo(): TPromise<ITelemetryInfo> {
		return null;
	}
}
490 491 492 493 494

export class SimpleWorkspaceContextService implements IWorkspaceContextService {

	public _serviceBrand: any;

495
	private static SCHEME = 'inmemory';
496

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

500 501
	private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent> = new Emitter<IWorkspaceFoldersChangeEvent>();
	public readonly onDidChangeWorkspaceFolders: Event<IWorkspaceFoldersChangeEvent> = this._onDidChangeWorkspaceFolders.event;
502 503 504

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

506
	private readonly workspace: IWorkspace;
507

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

B
Benjamin Pasero 已提交
513
	public getWorkspace(): IWorkspace {
514
		return this.workspace;
515 516
	}

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

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

531
	public isInsideWorkspace(resource: URI): boolean {
532
		return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME;
533 534
	}

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

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]);
		}
	});
}
556 557 558 559 560 561 562 563

export class SimpleBulkEditService implements IBulkEditService {
	_serviceBrand: any;

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

564
	apply(workspaceEdit: WorkspaceEdit, options: IBulkEditOptions): Promise<IBulkEditResult> {
565 566 567 568 569

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

		for (let edit of workspaceEdit.edits) {
			if (!isResourceTextEdit(edit)) {
570
				return Promise.reject(new Error('bad edit - only text edits are supported'));
571 572 573
			}
			let model = this._modelService.getModel(edit.resource);
			if (!model) {
574
				return Promise.reject(new Error('bad edit - model not found'));
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
			}
			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;
		});

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

I
isidor 已提交
598
export class SimpleUriLabelService implements ILabelService {
A
Alex Dima 已提交
599 600
	_serviceBrand: any;

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

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

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

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