-
Notifications
You must be signed in to change notification settings - Fork 31.8k
/
Copy pathsimpleServices.ts
726 lines (585 loc) · 24.4 KB
/
simpleServices.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as strings from 'vs/base/common/strings';
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, toDisposable, DisposableStore, Disposable } from 'vs/base/common/lifecycle';
import { OS, isLinux, isMacintosh } from 'vs/base/common/platform';
import Severity from 'vs/base/common/severity';
import { URI } from 'vs/base/common/uri';
import { ICodeEditor, IDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
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';
import { Range } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { ITextModel, ITextSnapshot } from 'vs/editor/common/model';
import { TextEdit, WorkspaceEdit, isResourceTextEdit } from 'vs/editor/common/modes';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IResolvedTextEditorModel, ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
import { ITextResourceConfigurationService, ITextResourcePropertiesService, ITextResourceConfigurationChangeEvent } from 'vs/editor/common/services/textResourceConfigurationService';
import { CommandsRegistry, ICommand, ICommandEvent, ICommandHandler, ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationChangeEvent, IConfigurationData, IConfigurationOverrides, IConfigurationService, IConfigurationModel, IConfigurationValue, ConfigurationTarget } 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, IShowResult } 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, KeybindingsSchemaContribution } 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';
import { ILabelService, ResourceLabelFormatter } from 'vs/platform/label/common/label';
import { INotification, INotificationHandle, INotificationService, IPromptChoice, IPromptOptions, NoOpNotification, IStatusMessageOptions, NotificationsFilter } from 'vs/platform/notification/common/notification';
import { IProgressRunner, IEditorProgressService } 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';
import { ILayoutService, IDimension } from 'vs/platform/layout/browser/layoutService';
import { SimpleServicesNLS } from 'vs/editor/common/standaloneStrings';
import { ClassifiedEvent, StrictPropertyCheck, GDPRClassification } from 'vs/platform/telemetry/common/gdprTypings';
import { basename } from 'vs/base/common/resources';
export class SimpleModel implements IResolvedTextEditorModel {
private readonly model: ITextModel;
private readonly _onDispose: Emitter<void>;
constructor(model: ITextModel) {
this.model = model;
this._onDispose = new Emitter<void>();
}
public get onDispose(): Event<void> {
return this._onDispose.event;
}
public load(): Promise<SimpleModel> {
return Promise.resolve(this);
}
public get textEditorModel(): ITextModel {
return this.model;
}
public createSnapshot(): ITextSnapshot {
return this.model.createSnapshot();
}
public isReadonly(): boolean {
return false;
}
public dispose(): void {
this._onDispose.fire();
}
}
export interface IOpenEditorDelegate {
(url: string): boolean;
}
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);
}
}
export class SimpleEditorModelResolverService implements ITextModelService {
public _serviceBrand: undefined;
private readonly modelService: IModelService | undefined;
private editor?: editorCommon.IEditor;
constructor(modelService: IModelService | undefined) {
this.modelService = modelService;
}
public setEditor(editor: editorCommon.IEditor): void {
this.editor = editor;
}
public createModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
let model: ITextModel | null = null;
if (this.editor) {
model = withTypedEditor(this.editor,
(editor) => this.findModel(editor, resource),
(diffEditor) => this.findModel(diffEditor.getOriginalEditor(), resource) || this.findModel(diffEditor.getModifiedEditor(), resource)
);
}
if (!model) {
return Promise.reject(new Error(`Model not found`));
}
return Promise.resolve(new ImmortalReference(new SimpleModel(model)));
}
public registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
return {
dispose: function () { /* no op */ }
};
}
public hasTextModelContentProvider(scheme: string): boolean {
return false;
}
private findModel(editor: ICodeEditor, resource: URI): ITextModel | null {
let model = this.modelService ? this.modelService.getModel(resource) : editor.getModel();
if (model && model.uri.toString() !== resource.toString()) {
return null;
}
return model;
}
}
export class SimpleEditorProgressService implements IEditorProgressService {
_serviceBrand: undefined;
private static NULL_PROGRESS_RUNNER: IProgressRunner = {
done: () => { },
total: () => { },
worked: () => { }
};
show(infinite: true, delay?: number): IProgressRunner;
show(total: number, delay?: number): IProgressRunner;
show(): IProgressRunner {
return SimpleEditorProgressService.NULL_PROGRESS_RUNNER;
}
showWhile(promise: Promise<any>, delay?: number): Promise<void> {
return Promise.resolve(undefined);
}
}
export class SimpleDialogService implements IDialogService {
public _serviceBrand: undefined;
public confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
return this.doConfirm(confirmation).then(confirmed => {
return {
confirmed,
checkboxChecked: false // unsupported
} as IConfirmationResult;
});
}
private doConfirm(confirmation: IConfirmation): Promise<boolean> {
let messageText = confirmation.message;
if (confirmation.detail) {
messageText = messageText + '\n\n' + confirmation.detail;
}
return Promise.resolve(window.confirm(messageText));
}
public show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<IShowResult> {
return Promise.resolve({ choice: 0 });
}
public about(): Promise<void> {
return Promise.resolve(undefined);
}
}
export class SimpleNotificationService implements INotificationService {
public _serviceBrand: undefined;
private static readonly NO_OP: INotificationHandle = new NoOpNotification();
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 {
return this.notify({ severity: Severity.Error, message: error });
}
public notify(notification: INotification): INotificationHandle {
switch (notification.severity) {
case Severity.Error:
console.error(notification.message);
break;
case Severity.Warning:
console.warn(notification.message);
break;
default:
console.log(notification.message);
break;
}
return SimpleNotificationService.NO_OP;
}
public prompt(severity: Severity, message: string, choices: IPromptChoice[], options?: IPromptOptions): INotificationHandle {
return SimpleNotificationService.NO_OP;
}
public status(message: string | Error, options?: IStatusMessageOptions): IDisposable {
return Disposable.None;
}
public setFilter(filter: NotificationsFilter): void { }
}
export class StandaloneCommandService implements ICommandService {
_serviceBrand: undefined;
private readonly _instantiationService: IInstantiationService;
private readonly _dynamicCommands: { [id: string]: ICommand; };
private readonly _onWillExecuteCommand = new Emitter<ICommandEvent>();
private readonly _onDidExecuteCommand = new Emitter<ICommandEvent>();
public readonly onWillExecuteCommand: Event<ICommandEvent> = this._onWillExecuteCommand.event;
public readonly onDidExecuteCommand: Event<ICommandEvent> = this._onDidExecuteCommand.event;
constructor(instantiationService: IInstantiationService) {
this._instantiationService = instantiationService;
this._dynamicCommands = Object.create(null);
}
public addCommand(command: ICommand): IDisposable {
const { id } = command;
this._dynamicCommands[id] = command;
return toDisposable(() => {
delete this._dynamicCommands[id];
});
}
public executeCommand<T>(id: string, ...args: any[]): Promise<T> {
const command = (CommandsRegistry.getCommand(id) || this._dynamicCommands[id]);
if (!command) {
return Promise.reject(new Error(`command '${id}' not found`));
}
try {
this._onWillExecuteCommand.fire({ commandId: id, args });
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler, ...args]) as T;
this._onDidExecuteCommand.fire({ commandId: id, args });
return Promise.resolve(result);
} catch (err) {
return Promise.reject(err);
}
}
}
export class StandaloneKeybindingService extends AbstractKeybindingService {
private _cachedResolver: KeybindingResolver | null;
private readonly _dynamicKeybindings: IKeybindingItem[];
constructor(
contextKeyService: IContextKeyService,
commandService: ICommandService,
telemetryService: ITelemetryService,
notificationService: INotificationService,
domNode: HTMLElement
) {
super(contextKeyService, commandService, telemetryService, notificationService);
this._cachedResolver = null;
this._dynamicKeybindings = [];
this._register(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
let keyEvent = new StandardKeyboardEvent(e);
let shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
if (shouldPreventDefault) {
keyEvent.preventDefault();
keyEvent.stopPropagation();
}
}));
}
public addDynamicKeybinding(commandId: string, _keybinding: number, handler: ICommandHandler, when: ContextKeyExpr | undefined): IDisposable {
const keybinding = createKeybinding(_keybinding, OS);
const toDispose = new DisposableStore();
if (keybinding) {
this._dynamicKeybindings.push({
keybinding: keybinding,
command: commandId,
when: when,
weight1: 1000,
weight2: 0
});
toDispose.add(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;
}
}
}));
}
let commandService = this._commandService;
if (commandService instanceof StandaloneCommandService) {
toDispose.add(commandService.addCommand({
id: commandId,
handler: handler
}));
} else {
throw new Error('Unknown command service!');
}
this.updateResolver({ source: KeybindingSource.Default });
return toDispose;
}
private updateResolver(event: IKeybindingEvent): void {
this._cachedResolver = null;
this._onDidUpdateKeybindings.fire(event);
}
protected _getResolver(): KeybindingResolver {
if (!this._cachedResolver) {
const defaults = this._toNormalizedKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
const overrides = this._toNormalizedKeybindingItems(this._dynamicKeybindings, false);
this._cachedResolver = new KeybindingResolver(defaults, overrides);
}
return this._cachedResolver;
}
protected _documentHasFocus(): boolean {
return document.hasFocus();
}
private _toNormalizedKeybindingItems(items: IKeybindingItem[], isDefault: boolean): ResolvedKeybindingItem[] {
let result: ResolvedKeybindingItem[] = [], resultLen = 0;
for (const item of items) {
const when = item.when || undefined;
const keybinding = item.keybinding;
if (!keybinding) {
// This might be a removal keybinding item in user settings => accept it
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault);
} else {
const resolvedKeybindings = this.resolveKeybinding(keybinding);
for (const resolvedKeybinding of resolvedKeybindings) {
result[resultLen++] = new ResolvedKeybindingItem(resolvedKeybinding, item.command, item.commandArgs, when, isDefault);
}
}
}
return result;
}
public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
return [new USLayoutResolvedKeybinding(keybinding, OS)];
}
public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
let keybinding = new SimpleKeybinding(
keyboardEvent.ctrlKey,
keyboardEvent.shiftKey,
keyboardEvent.altKey,
keyboardEvent.metaKey,
keyboardEvent.keyCode
).toChord();
return new USLayoutResolvedKeybinding(keybinding, OS);
}
public resolveUserBinding(userBinding: string): ResolvedKeybinding[] {
return [];
}
public _dumpDebugInfo(): string {
return '';
}
public _dumpDebugInfoJSON(): string {
return '';
}
public registerSchemaContribution(contribution: KeybindingsSchemaContribution): void {
// noop
}
}
function isConfigurationOverrides(thing: any): thing is IConfigurationOverrides {
return thing
&& typeof thing === 'object'
&& (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
&& (!thing.resource || thing.resource instanceof URI);
}
export class SimpleConfigurationService implements IConfigurationService {
_serviceBrand: undefined;
private readonly _onDidChangeConfiguration = new Emitter<IConfigurationChangeEvent>();
public readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent> = this._onDidChangeConfiguration.event;
private readonly _configuration: Configuration;
constructor() {
this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
}
private configuration(): Configuration {
return this._configuration;
}
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 : undefined;
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
return this.configuration().getValue(section, overrides, undefined);
}
public updateValue(key: string, value: any, arg3?: any, arg4?: any): Promise<void> {
this.configuration().updateValue(key, value);
return Promise.resolve();
}
public inspect<C>(key: string, options: IConfigurationOverrides = {}): IConfigurationValue<C> {
return this.configuration().inspect<C>(key, options, undefined);
}
public keys() {
return this.configuration().keys(undefined);
}
public reloadConfiguration(): Promise<void> {
return Promise.resolve(undefined);
}
public getConfigurationData(): IConfigurationData | null {
const emptyModel: IConfigurationModel = {
contents: {},
keys: [],
overrides: []
};
return {
defaults: emptyModel,
user: emptyModel,
workspace: emptyModel,
folders: []
};
}
}
export class SimpleResourceConfigurationService implements ITextResourceConfigurationService {
_serviceBrand: undefined;
private readonly _onDidChangeConfiguration = new Emitter<ITextResourceConfigurationChangeEvent>();
public readonly onDidChangeConfiguration = this._onDidChangeConfiguration.event;
constructor(private readonly configurationService: SimpleConfigurationService) {
this.configurationService.onDidChangeConfiguration((e) => {
this._onDidChangeConfiguration.fire({ affectedKeys: e.affectedKeys, affectsConfiguration: (resource: URI, configuration: string) => e.affectsConfiguration(configuration) });
});
}
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 | null = Pos.isIPosition(arg2) ? arg2 : null;
const section: string | undefined = position ? (typeof arg3 === 'string' ? arg3 : undefined) : (typeof arg2 === 'string' ? arg2 : undefined);
if (typeof section === 'undefined') {
return this.configurationService.getValue<T>();
}
return this.configurationService.getValue<T>(section);
}
updateValue(resource: URI, key: string, value: any, configurationTarget?: ConfigurationTarget): Promise<void> {
return this.configurationService.updateValue(key, value, { resource }, configurationTarget);
}
}
export class SimpleResourcePropertiesService implements ITextResourcePropertiesService {
_serviceBrand: undefined;
constructor(
@IConfigurationService private readonly configurationService: IConfigurationService,
) {
}
getEOL(resource: URI, language?: string): string {
const eol = this.configurationService.getValue<string>('files.eol', { overrideIdentifier: language, resource });
if (eol && eol !== 'auto') {
return eol;
}
return (isLinux || isMacintosh) ? '\n' : '\r\n';
}
}
export class StandaloneTelemetryService implements ITelemetryService {
_serviceBrand: undefined;
public isOptedIn = false;
public setEnabled(value: boolean): void {
}
public publicLog(eventName: string, data?: any): Promise<void> {
return Promise.resolve(undefined);
}
publicLog2<E extends ClassifiedEvent<T> = never, T extends GDPRClassification<T> = never>(eventName: string, data?: StrictPropertyCheck<T, E>) {
return this.publicLog(eventName, data as any);
}
public getTelemetryInfo(): Promise<ITelemetryInfo> {
throw new Error(`Not available`);
}
}
export class SimpleWorkspaceContextService implements IWorkspaceContextService {
public _serviceBrand: undefined;
private static readonly SCHEME = 'inmemory';
private readonly _onDidChangeWorkspaceName = new Emitter<void>();
public readonly onDidChangeWorkspaceName: Event<void> = this._onDidChangeWorkspaceName.event;
private readonly _onDidChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersChangeEvent>();
public readonly onDidChangeWorkspaceFolders: Event<IWorkspaceFoldersChangeEvent> = this._onDidChangeWorkspaceFolders.event;
private readonly _onDidChangeWorkbenchState = new Emitter<WorkbenchState>();
public readonly onDidChangeWorkbenchState: Event<WorkbenchState> = this._onDidChangeWorkbenchState.event;
private readonly workspace: IWorkspace;
constructor() {
const resource = URI.from({ scheme: SimpleWorkspaceContextService.SCHEME, authority: 'model', path: '/' });
this.workspace = { id: '4064f6ec-cb38-4ad0-af64-ee6467e63c82', folders: [new WorkspaceFolder({ uri: resource, name: '', index: 0 })] };
}
getCompleteWorkspace(): Promise<IWorkspace> {
return Promise.resolve(this.getWorkspace());
}
public getWorkspace(): IWorkspace {
return this.workspace;
}
public getWorkbenchState(): WorkbenchState {
if (this.workspace) {
if (this.workspace.configuration) {
return WorkbenchState.WORKSPACE;
}
return WorkbenchState.FOLDER;
}
return WorkbenchState.EMPTY;
}
public getWorkspaceFolder(resource: URI): IWorkspaceFolder | null {
return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME ? this.workspace.folders[0] : null;
}
public isInsideWorkspace(resource: URI): boolean {
return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME;
}
public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
return true;
}
}
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]);
}
});
}
export class SimpleBulkEditService implements IBulkEditService {
_serviceBrand: undefined;
constructor(private readonly _modelService: IModelService) {
//
}
apply(workspaceEdit: WorkspaceEdit, options?: IBulkEditOptions): Promise<IBulkEditResult> {
let edits = new Map<ITextModel, TextEdit[]>();
if (workspaceEdit.edits) {
for (let edit of workspaceEdit.edits) {
if (!isResourceTextEdit(edit)) {
return Promise.reject(new Error('bad edit - only text edits are supported'));
}
let model = this._modelService.getModel(edit.resource);
if (!model) {
return Promise.reject(new Error('bad edit - model not found'));
}
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.pushStackElement();
model.pushEditOperations([], edits.map((e) => EditOperation.replaceMove(Range.lift(e.range), e.text)), () => []);
model.pushStackElement();
totalFiles += 1;
totalEdits += edits.length;
});
return Promise.resolve({
selection: undefined,
ariaSummary: strings.format(SimpleServicesNLS.bulkEditServiceSummary, totalEdits, totalFiles)
});
}
}
export class SimpleUriLabelService implements ILabelService {
_serviceBrand: undefined;
private readonly _onDidRegisterFormatter = new Emitter<void>();
public readonly onDidChangeFormatters: Event<void> = this._onDidRegisterFormatter.event;
public getUriLabel(resource: URI, options?: { relative?: boolean, forceNoTildify?: boolean }): string {
if (resource.scheme === 'file') {
return resource.fsPath;
}
return resource.path;
}
getUriBasenameLabel(resource: URI): string {
return basename(resource);
}
public getWorkspaceLabel(workspace: IWorkspaceIdentifier | URI | IWorkspace, options?: { verbose: boolean; }): string {
return '';
}
public getSeparator(scheme: string, authority?: string): '/' | '\\' {
return '/';
}
public registerFormatter(formatter: ResourceLabelFormatter): IDisposable {
throw new Error('Not implemented');
}
public getHostLabel(): string {
return '';
}
}
export class SimpleLayoutService implements ILayoutService {
_serviceBrand: undefined;
public onLayout = Event.None;
private _dimension?: IDimension;
get dimension(): IDimension {
if (!this._dimension) {
this._dimension = dom.getClientArea(window.document.body);
}
return this._dimension;
}
get container(): HTMLElement {
return this._container;
}
constructor(private _container: HTMLElement) { }
}