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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		return model;
	}
}

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

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

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

155
export class SimpleDialogService implements IDialogService {
156 157

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

159 160 161 162 163 164 165 166 167 168
	public confirm(confirmation: IConfirmation): TPromise<IConfirmationResult> {
		return this.doConfirm(confirmation).then(confirmed => {
			return {
				confirmed,
				checkboxChecked: false // unsupported
			} as IConfirmationResult;
		});
	}

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

174
		return TPromise.wrap(window.confirm(messageText));
E
Erich Gamma 已提交
175
	}
176

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

182 183 184 185
export class SimpleNotificationService implements INotificationService {

	public _serviceBrand: any;

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

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

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

213
		return SimpleNotificationService.NO_OP;
214
	}
215

216 217
	public prompt(severity: Severity, message: string, choices: IPromptChoice[], onCancel?: () => void): INotificationHandle {
		return SimpleNotificationService.NO_OP;
218
	}
219 220
}

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

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

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

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

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

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

		try {
250
			this._onWillExecuteCommand.fire({ commandId: id });
A
Alex Dima 已提交
251 252 253
			const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
			return TPromise.as(result);
		} catch (err) {
254
			return TPromise.wrapError<T>(err);
A
Alex Dima 已提交
255
		}
256 257 258
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		return result;
	}

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

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

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

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

386
export class SimpleConfigurationService implements IConfigurationService {
387

388 389
	_serviceBrand: any;

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

393
	private _configuration: Configuration;
394

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

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

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

413
	public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise<void> {
414
		this.configuration().updateValue(key, value);
415
		return TPromise.as(null);
B
Benjamin Pasero 已提交
416
	}
B
Benjamin Pasero 已提交
417

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

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

432 433
	public reloadConfiguration(): TPromise<void> {
		return TPromise.as(null);
434
	}
S
Sandeep Somavarapu 已提交
435

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

441 442 443 444
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

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

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

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

A
Alex Dima 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476
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);
	}
}
477 478 479 480 481 482 483

export class StandaloneTelemetryService implements ITelemetryService {
	_serviceBrand: void;

	public isOptedIn = false;

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

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

export class SimpleWorkspaceContextService implements IWorkspaceContextService {

	public _serviceBrand: any;

496 497
	private static SCHEME: 'inmemory';

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

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

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

507
	private readonly workspace: IWorkspace;
508

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

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

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

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

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

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

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

export class SimpleBulkEditService implements IBulkEditService {
	_serviceBrand: any;

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

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

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

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

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

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

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

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

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

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