/
workbenchTestServices.ts
1585 lines (1297 loc) · 73.8 KB
/
workbenchTestServices.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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { basename } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { IEditorInputWithOptions, IEditorIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, IEditorInput, IEditorPane, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorInput, EditorOptions, EditorsOrder, IFileEditorInput, IEditorInputFactoryRegistry, IEditorInputSerializer, Extensions as EditorExtensions, ISaveOptions, IMoveResult, ITextEditorPane, ITextDiffEditorPane, IVisibleEditorPane, IEditorOpenContext, SideBySideEditorInput, IEditorMoveEvent } from 'vs/workbench/common/editor';
import { EditorServiceImpl, IEditorGroupView, IEditorGroupsAccessor, IEditorGroupTitleHeight } from 'vs/workbench/browser/parts/editor/editor';
import { Event, Emitter } from 'vs/base/common/event';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IWorkbenchLayoutService, Parts, Position as PartPosition } from 'vs/workbench/services/layout/browser/layoutService';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IEditorOptions, IResourceEditorInput, IEditorModel, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IUntitledTextEditorService, UntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ILifecycleService, BeforeShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase, WillShutdownEvent } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { FileOperationEvent, IFileService, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, ICreateFileOptions, IFileSystemProvider, FileSystemProviderCapabilities, IFileChange, IWatchOptions, IStat, FileType, FileDeleteOptions, FileOverwriteOptions, FileWriteOptions, FileOpenOptions, IFileStatWithMetadata, IResolveMetadataFileOptions, IWriteFileOptions, IReadFileOptions, IFileContent, IFileStreamContent, FileOperationError, IFileSystemProviderWithFileReadStreamCapability, FileReadStreamOptions, IReadFileStreamOptions } from 'vs/platform/files/common/files';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IResourceEncoding, ITextFileService, IReadTextFileOptions, ITextFileStreamContent, IWriteTextFileOptions, ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { MenuBarVisibility, IWindowOpenable, IOpenWindowOptions, IOpenEmptyWindowOptions } from 'vs/platform/windows/common/windows';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { ITextResourceConfigurationService, ITextResourcePropertiesService } from 'vs/editor/common/services/textResourceConfigurationService';
import { IPosition, Position as EditorPosition } from 'vs/editor/common/core/position';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { MockContextKeyService, MockKeybindingService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
import { ITextBufferFactory, DefaultEndOfLine, EndOfLinePreference, ITextSnapshot } from 'vs/editor/common/model';
import { Range } from 'vs/editor/common/core/range';
import { IDialogService, IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, IFileDialogService, ConfirmResult } from 'vs/platform/dialogs/common/dialogs';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
import { IDisposable, toDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation, ICloseAllEditorsOptions, ICloseEditorsFilter } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditorInputType, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, IOpenEditorOverrideEntry } from 'vs/workbench/services/editor/common/editorService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor';
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { Dimension, IDimension } from 'vs/base/browser/dom';
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { ILabelService } from 'vs/platform/label/common/label';
import { timeout } from 'vs/base/common/async';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ViewletDescriptor, Viewlet } from 'vs/workbench/browser/viewlet';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { IProcessEnvironment, isLinux, isWindows } from 'vs/base/common/platform';
import { LabelService } from 'vs/workbench/services/label/common/labelService';
import { Part } from 'vs/workbench/browser/part';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPanel } from 'vs/workbench/common/panel';
import { IBadge } from 'vs/workbench/services/activity/common/activity';
import { bufferToStream, VSBuffer, VSBufferReadable } from 'vs/base/common/buffer';
import { Schemas } from 'vs/base/common/network';
import { IProductService } from 'vs/platform/product/common/productService';
import product from 'vs/platform/product/common/product';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IFilesConfigurationService, FilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { BrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
import { BrowserTextFileService } from 'vs/workbench/services/textfile/browser/browserTextFileService';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { Direction } from 'vs/base/browser/ui/grid/grid';
import { IProgressService, IProgressOptions, IProgressWindowOptions, IProgressNotificationOptions, IProgressCompositeOptions, IProgress, IProgressStep, Progress } from 'vs/platform/progress/common/progress';
import { IWorkingCopyFileService, WorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
import { UndoRedoService } from 'vs/platform/undoRedo/common/undoRedoService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
import { CancellationToken } from 'vs/base/common/cancellation';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { TestDialogService } from 'vs/platform/dialogs/test/common/testDialogService';
import { CodeEditorService } from 'vs/workbench/services/editor/browser/codeEditorService';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IDiffEditor, IEditor } from 'vs/editor/common/editorCommon';
import { IInputBox, IInputOptions, IPickOptions, IQuickInputButton, IQuickInputService, IQuickNavigateConfiguration, IQuickPick, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
import { QuickInputService } from 'vs/workbench/services/quickinput/browser/quickInputService';
import { IListService } from 'vs/platform/list/browser/listService';
import { win32, posix } from 'vs/base/common/path';
import { TestWorkingCopyService, TestContextService, TestStorageService, TestTextResourcePropertiesService, TestExtensionService } from 'vs/workbench/test/common/workbenchTestServices';
import { IViewsService, IView, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { IPaneComposite } from 'vs/workbench/common/panecomposite';
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
import { UriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentityService';
import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager';
import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider';
import { newWriteableStream, ReadableStreamEvents } from 'vs/base/common/stream';
import { EncodingOracle, IEncodingOverride } from 'vs/workbench/services/textfile/browser/textFileService';
import { UTF16le, UTF16be, UTF8_with_bom } from 'vs/workbench/services/textfile/common/encoding';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { Iterable } from 'vs/base/common/iterator';
import { InMemoryBackupFileService } from 'vs/workbench/services/backup/common/backupFileService';
import { hash } from 'vs/base/common/hash';
import { BrowserBackupFileService } from 'vs/workbench/services/backup/browser/backupFileService';
import { FileService } from 'vs/platform/files/common/fileService';
import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResourceEditor';
import { TestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
import { TextFileEditor } from 'vs/workbench/contrib/files/browser/editors/textFileEditor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
import { IEnterWorkspaceResult, IRecent, IRecentlyOpened, IWorkspaceFolderCreationData, IWorkspaceIdentifier, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspaceTrustService } from 'vs/platform/workspace/common/workspaceTrust';
import { TestWorkspaceTrustService } from 'vs/workbench/services/workspaces/test/common/testWorkspaceTrustService';
import { ILocalTerminalService, IShellLaunchConfig, ITerminalChildProcess, ITerminalsLayoutInfo, ITerminalsLayoutInfoById } from 'vs/platform/terminal/common/terminal';
import { IProcessDetails, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess';
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { isArray } from 'vs/base/common/types';
export function createFileEditorInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined, undefined, undefined, undefined);
}
Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerFileEditorInputFactory({
createFileEditorInput: (resource, preferredResource, preferredName, preferredDescription, preferredEncoding, preferredMode, instantiationService): IFileEditorInput => {
return instantiationService.createInstance(FileEditorInput, resource, preferredResource, preferredName, preferredDescription, preferredEncoding, preferredMode);
},
isFileEditorInput: (obj): obj is IFileEditorInput => {
return obj instanceof FileEditorInput;
}
});
export class TestTextResourceEditor extends TextResourceEditor {
protected createEditorControl(parent: HTMLElement, configuration: any): IEditor {
return this.instantiationService.createInstance(TestCodeEditor, parent, configuration, {});
}
}
export class TestTextFileEditor extends TextFileEditor {
protected createEditorControl(parent: HTMLElement, configuration: any): IEditor {
return this.instantiationService.createInstance(TestCodeEditor, parent, configuration, {});
}
}
export interface ITestInstantiationService extends IInstantiationService {
stub<T>(service: ServiceIdentifier<T>, ctor: any): T;
}
export function workbenchInstantiationService(
overrides?: {
textFileService?: (instantiationService: IInstantiationService) => ITextFileService;
pathService?: (instantiationService: IInstantiationService) => IPathService,
editorService?: (instantiationService: IInstantiationService) => IEditorService,
contextKeyService?: (instantiationService: IInstantiationService) => IContextKeyService,
},
disposables: DisposableStore = new DisposableStore()
): ITestInstantiationService {
const instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
instantiationService.stub(IWorkingCopyService, disposables.add(new TestWorkingCopyService()));
instantiationService.stub(IEnvironmentService, TestEnvironmentService);
instantiationService.stub(IWorkbenchEnvironmentService, TestEnvironmentService);
const contextKeyService = overrides?.contextKeyService ? overrides.contextKeyService(instantiationService) : instantiationService.createInstance(MockContextKeyService);
instantiationService.stub(IContextKeyService, contextKeyService);
instantiationService.stub(IProgressService, new TestProgressService());
const workspaceContextService = new TestContextService(TestWorkspace);
instantiationService.stub(IWorkspaceContextService, workspaceContextService);
const configService = new TestConfigurationService();
instantiationService.stub(IConfigurationService, configService);
instantiationService.stub(IFilesConfigurationService, disposables.add(new TestFilesConfigurationService(contextKeyService, configService)));
instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService));
instantiationService.stub(IUntitledTextEditorService, disposables.add(instantiationService.createInstance(UntitledTextEditorService)));
instantiationService.stub(IStorageService, disposables.add(new TestStorageService()));
instantiationService.stub(IPathService, overrides?.pathService ? overrides.pathService(instantiationService) : new TestPathService());
const layoutService = new TestLayoutService();
instantiationService.stub(IWorkbenchLayoutService, layoutService);
instantiationService.stub(IDialogService, new TestDialogService());
const accessibilityService = new TestAccessibilityService();
instantiationService.stub(IAccessibilityService, accessibilityService);
instantiationService.stub(IFileDialogService, instantiationService.createInstance(TestFileDialogService));
instantiationService.stub(IModeService, disposables.add(instantiationService.createInstance(ModeServiceImpl)));
instantiationService.stub(IHistoryService, new TestHistoryService());
instantiationService.stub(ITextResourcePropertiesService, new TestTextResourcePropertiesService(configService));
instantiationService.stub(IUndoRedoService, instantiationService.createInstance(UndoRedoService));
const themeService = new TestThemeService();
instantiationService.stub(IThemeService, themeService);
instantiationService.stub(IModelService, disposables.add(instantiationService.createInstance(ModelServiceImpl)));
const fileService = new TestFileService();
instantiationService.stub(IFileService, fileService);
instantiationService.stub(IUriIdentityService, new UriIdentityService(fileService));
instantiationService.stub(IBackupFileService, new TestBackupFileService());
instantiationService.stub(ITelemetryService, NullTelemetryService);
instantiationService.stub(INotificationService, new TestNotificationService());
instantiationService.stub(IUntitledTextEditorService, disposables.add(instantiationService.createInstance(UntitledTextEditorService)));
instantiationService.stub(IMenuService, new TestMenuService());
const keybindingService = new MockKeybindingService();
instantiationService.stub(IKeybindingService, keybindingService);
instantiationService.stub(IDecorationsService, new TestDecorationsService());
instantiationService.stub(IExtensionService, new TestExtensionService());
instantiationService.stub(IWorkingCopyFileService, disposables.add(instantiationService.createInstance(WorkingCopyFileService)));
instantiationService.stub(ITextFileService, overrides?.textFileService ? overrides.textFileService(instantiationService) : disposables.add(<ITextFileService>instantiationService.createInstance(TestTextFileService)));
instantiationService.stub(IHostService, <IHostService>instantiationService.createInstance(TestHostService));
instantiationService.stub(ITextModelService, <ITextModelService>disposables.add(instantiationService.createInstance(TextModelResolverService)));
instantiationService.stub(ILogService, new NullLogService());
const editorGroupService = new TestEditorGroupsService([new TestEditorGroupView(0)]);
instantiationService.stub(IEditorGroupsService, editorGroupService);
instantiationService.stub(ILabelService, <ILabelService>disposables.add(instantiationService.createInstance(LabelService)));
const editorService = overrides?.editorService ? overrides.editorService(instantiationService) : new TestEditorService(editorGroupService);
instantiationService.stub(IEditorService, editorService);
instantiationService.stub(ICodeEditorService, disposables.add(new CodeEditorService(editorService, themeService, configService)));
instantiationService.stub(IViewletService, new TestViewletService());
instantiationService.stub(IListService, new TestListService());
instantiationService.stub(IQuickInputService, disposables.add(new QuickInputService(configService, instantiationService, keybindingService, contextKeyService, themeService, accessibilityService, layoutService)));
instantiationService.stub(IWorkspacesService, new TestWorkspacesService());
instantiationService.stub(IWorkspaceTrustService, new TestWorkspaceTrustService());
instantiationService.stub(ITerminalInstanceService, new TestTerminalInstanceService());
instantiationService.stub(ILocalTerminalService, new TestLocalTerminalService());
return instantiationService;
}
export class TestServiceAccessor {
constructor(
@ILifecycleService public lifecycleService: TestLifecycleService,
@ITextFileService public textFileService: TestTextFileService,
@IWorkingCopyFileService public workingCopyFileService: IWorkingCopyFileService,
@IFilesConfigurationService public filesConfigurationService: TestFilesConfigurationService,
@IWorkspaceContextService public contextService: TestContextService,
@IModelService public modelService: ModelServiceImpl,
@IFileService public fileService: TestFileService,
@IFileDialogService public fileDialogService: TestFileDialogService,
@IWorkingCopyService public workingCopyService: IWorkingCopyService,
@IEditorService public editorService: TestEditorService,
@IEditorGroupsService public editorGroupService: IEditorGroupsService,
@IModeService public modeService: IModeService,
@ITextModelService public textModelResolverService: ITextModelService,
@IUntitledTextEditorService public untitledTextEditorService: UntitledTextEditorService,
@IConfigurationService public testConfigurationService: TestConfigurationService,
@IBackupFileService public backupFileService: TestBackupFileService,
@IHostService public hostService: TestHostService,
@IQuickInputService public quickInputService: IQuickInputService,
@ILabelService public labelService: ILabelService,
@ILogService public logService: ILogService,
@IUriIdentityService public uriIdentityService: IUriIdentityService
) { }
}
export class TestTextFileService extends BrowserTextFileService {
private readStreamError: FileOperationError | undefined = undefined;
private writeError: FileOperationError | undefined = undefined;
constructor(
@IFileService protected fileService: IFileService,
@IUntitledTextEditorService untitledTextEditorService: IUntitledTextEditorService,
@ILifecycleService lifecycleService: ILifecycleService,
@IInstantiationService instantiationService: IInstantiationService,
@IModelService modelService: IModelService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
@IDialogService dialogService: IDialogService,
@IFileDialogService fileDialogService: IFileDialogService,
@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
@IProductService productService: IProductService,
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
@ITextModelService textModelService: ITextModelService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@IPathService pathService: IPathService,
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
@IUriIdentityService uriIdentityService: IUriIdentityService,
@IModeService modeService: IModeService,
@ILogService logService: ILogService
) {
super(
fileService,
untitledTextEditorService,
lifecycleService,
instantiationService,
modelService,
environmentService,
dialogService,
fileDialogService,
textResourceConfigurationService,
filesConfigurationService,
textModelService,
codeEditorService,
pathService,
workingCopyFileService,
uriIdentityService,
modeService,
logService
);
}
setReadStreamErrorOnce(error: FileOperationError): void {
this.readStreamError = error;
}
async readStream(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileStreamContent> {
if (this.readStreamError) {
const error = this.readStreamError;
this.readStreamError = undefined;
throw error;
}
const content = await this.fileService.readFileStream(resource, options);
return {
resource: content.resource,
name: content.name,
mtime: content.mtime,
ctime: content.ctime,
etag: content.etag,
encoding: 'utf8',
value: await createTextBufferFactoryFromStream(content.value),
size: 10
};
}
setWriteErrorOnce(error: FileOperationError): void {
this.writeError = error;
}
async write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata> {
if (this.writeError) {
const error = this.writeError;
this.writeError = undefined;
throw error;
}
return super.write(resource, value, options);
}
}
export class TestBrowserTextFileServiceWithEncodingOverrides extends BrowserTextFileService {
private _testEncoding: TestEncodingOracle | undefined;
get encoding(): TestEncodingOracle {
if (!this._testEncoding) {
this._testEncoding = this._register(this.instantiationService.createInstance(TestEncodingOracle));
}
return this._testEncoding;
}
}
export class TestEncodingOracle extends EncodingOracle {
protected get encodingOverrides(): IEncodingOverride[] {
return [
{ extension: 'utf16le', encoding: UTF16le },
{ extension: 'utf16be', encoding: UTF16be },
{ extension: 'utf8bom', encoding: UTF8_with_bom }
];
}
protected set encodingOverrides(overrides: IEncodingOverride[]) { }
}
class TestEnvironmentServiceWithArgs extends BrowserWorkbenchEnvironmentService {
args = [];
}
export const TestProductService = { _serviceBrand: undefined, ...product };
export const TestEnvironmentService = new TestEnvironmentServiceWithArgs(Object.create(null), TestProductService);
export class TestProgressService implements IProgressService {
declare readonly _serviceBrand: undefined;
withProgress(
options: IProgressOptions | IProgressWindowOptions | IProgressNotificationOptions | IProgressCompositeOptions,
task: (progress: IProgress<IProgressStep>) => Promise<any>,
onDidCancel?: ((choice?: number | undefined) => void) | undefined
): Promise<any> {
return task(Progress.None);
}
}
export class TestAccessibilityService implements IAccessibilityService {
declare readonly _serviceBrand: undefined;
onDidChangeScreenReaderOptimized = Event.None;
isScreenReaderOptimized(): boolean { return false; }
alwaysUnderlineAccessKeys(): Promise<boolean> { return Promise.resolve(false); }
setAccessibilitySupport(accessibilitySupport: AccessibilitySupport): void { }
getAccessibilitySupport(): AccessibilitySupport { return AccessibilitySupport.Unknown; }
}
export class TestDecorationsService implements IDecorationsService {
declare readonly _serviceBrand: undefined;
onDidChangeDecorations: Event<IResourceDecorationChangeEvent> = Event.None;
registerDecorationsProvider(_provider: IDecorationsProvider): IDisposable { return Disposable.None; }
getDecoration(_uri: URI, _includeChildren: boolean, _overwrite?: IDecorationData): IDecoration | undefined { return undefined; }
}
export class TestMenuService implements IMenuService {
declare readonly _serviceBrand: undefined;
createMenu(_id: MenuId, _scopedKeybindingService: IContextKeyService): IMenu {
return {
onDidChange: Event.None,
dispose: () => undefined,
getActions: () => []
};
}
}
export class TestHistoryService implements IHistoryService {
declare readonly _serviceBrand: undefined;
constructor(private root?: URI) { }
reopenLastClosedEditor(): void { }
forward(): void { }
back(): void { }
last(): void { }
removeFromHistory(_input: IEditorInput | IResourceEditorInput): void { }
clear(): void { }
clearRecentlyOpened(): void { }
getHistory(): ReadonlyArray<IEditorInput | IResourceEditorInput> { return []; }
openNextRecentlyUsedEditor(group?: GroupIdentifier): void { }
openPreviouslyUsedEditor(group?: GroupIdentifier): void { }
getLastActiveWorkspaceRoot(_schemeFilter: string): URI | undefined { return this.root; }
getLastActiveFile(_schemeFilter: string): URI | undefined { return undefined; }
openLastEditLocation(): void { }
}
export class TestFileDialogService implements IFileDialogService {
declare readonly _serviceBrand: undefined;
private confirmResult!: ConfirmResult;
constructor(
@IPathService private readonly pathService: IPathService
) { }
async defaultFilePath(_schemeFilter?: string): Promise<URI> { return this.pathService.userHome(); }
async defaultFolderPath(_schemeFilter?: string): Promise<URI> { return this.pathService.userHome(); }
async defaultWorkspacePath(_schemeFilter?: string): Promise<URI> { return this.pathService.userHome(); }
pickFileFolderAndOpen(_options: IPickAndOpenOptions): Promise<any> { return Promise.resolve(0); }
pickFileAndOpen(_options: IPickAndOpenOptions): Promise<any> { return Promise.resolve(0); }
pickFolderAndOpen(_options: IPickAndOpenOptions): Promise<any> { return Promise.resolve(0); }
pickWorkspaceAndOpen(_options: IPickAndOpenOptions): Promise<any> { return Promise.resolve(0); }
private fileToSave!: URI;
setPickFileToSave(path: URI): void { this.fileToSave = path; }
pickFileToSave(defaultUri: URI, availableFileSystems?: string[]): Promise<URI | undefined> { return Promise.resolve(this.fileToSave); }
showSaveDialog(_options: ISaveDialogOptions): Promise<URI | undefined> { return Promise.resolve(undefined); }
showOpenDialog(_options: IOpenDialogOptions): Promise<URI[] | undefined> { return Promise.resolve(undefined); }
setConfirmResult(result: ConfirmResult): void { this.confirmResult = result; }
showSaveConfirm(fileNamesOrResources: (string | URI)[]): Promise<ConfirmResult> { return Promise.resolve(this.confirmResult); }
}
export class TestLayoutService implements IWorkbenchLayoutService {
declare readonly _serviceBrand: undefined;
openedDefaultEditors = false;
dimension: IDimension = { width: 800, height: 600 };
container: HTMLElement = window.document.body;
onDidChangeZenMode: Event<boolean> = Event.None;
onDidChangeCenteredLayout: Event<boolean> = Event.None;
onDidChangeFullscreen: Event<boolean> = Event.None;
onDidChangeWindowMaximized: Event<boolean> = Event.None;
onDidChangePanelPosition: Event<string> = Event.None;
onDidChangePartVisibility: Event<void> = Event.None;
onDidLayout = Event.None;
onDidChangeNotificationsVisibility = Event.None;
layout(): void { }
isRestored(): boolean { return true; }
hasFocus(_part: Parts): boolean { return false; }
focusPart(_part: Parts): void { }
hasWindowBorder(): boolean { return false; }
getWindowBorderWidth(): number { return 0; }
getWindowBorderRadius(): string | undefined { return undefined; }
isVisible(_part: Parts): boolean { return true; }
getDimension(_part: Parts): Dimension { return new Dimension(0, 0); }
getContainer(_part: Parts): HTMLElement { return null!; }
isTitleBarHidden(): boolean { return false; }
isStatusBarHidden(): boolean { return false; }
isActivityBarHidden(): boolean { return false; }
setActivityBarHidden(_hidden: boolean): void { }
isSideBarHidden(): boolean { return false; }
async setEditorHidden(_hidden: boolean): Promise<void> { }
async setSideBarHidden(_hidden: boolean): Promise<void> { }
isPanelHidden(): boolean { return false; }
async setPanelHidden(_hidden: boolean): Promise<void> { }
toggleMaximizedPanel(): void { }
isPanelMaximized(): boolean { return false; }
getMenubarVisibility(): MenuBarVisibility { throw new Error('not implemented'); }
toggleMenuBar(): void { }
getSideBarPosition() { return 0; }
getPanelPosition() { return 0; }
async setPanelPosition(_position: PartPosition): Promise<void> { }
addClass(_clazz: string): void { }
removeClass(_clazz: string): void { }
getMaximumEditorDimensions(): Dimension { throw new Error('not implemented'); }
toggleZenMode(): void { }
isEditorLayoutCentered(): boolean { return false; }
centerEditorLayout(_active: boolean): void { }
resizePart(_part: Parts, _sizeChangeWidth: number, _sizeChangeHeight: number): void { }
registerPart(part: Part): void { }
isWindowMaximized() { return false; }
updateWindowMaximizedState(maximized: boolean): void { }
getVisibleNeighborPart(part: Parts, direction: Direction): Parts | undefined { return undefined; }
focus() { }
}
let activeViewlet: Viewlet = {} as any;
export class TestViewletService implements IViewletService {
declare readonly _serviceBrand: undefined;
onDidViewletRegisterEmitter = new Emitter<ViewletDescriptor>();
onDidViewletDeregisterEmitter = new Emitter<ViewletDescriptor>();
onDidViewletOpenEmitter = new Emitter<IViewlet>();
onDidViewletCloseEmitter = new Emitter<IViewlet>();
onDidViewletRegister = this.onDidViewletRegisterEmitter.event;
onDidViewletDeregister = this.onDidViewletDeregisterEmitter.event;
onDidViewletOpen = this.onDidViewletOpenEmitter.event;
onDidViewletClose = this.onDidViewletCloseEmitter.event;
openViewlet(id: string, focus?: boolean): Promise<IViewlet | undefined> { return Promise.resolve(undefined); }
getViewlets(): ViewletDescriptor[] { return []; }
getAllViewlets(): ViewletDescriptor[] { return []; }
getActiveViewlet(): IViewlet { return activeViewlet; }
getDefaultViewletId(): string { return 'workbench.view.explorer'; }
getViewlet(id: string): ViewletDescriptor | undefined { return undefined; }
getProgressIndicator(id: string) { return undefined; }
hideActiveViewlet(): void { }
getLastActiveViewletId(): string { return undefined!; }
dispose() { }
}
export class TestPanelService implements IPanelService {
declare readonly _serviceBrand: undefined;
onDidPanelOpen = new Emitter<{ panel: IPanel, focus: boolean; }>().event;
onDidPanelClose = new Emitter<IPanel>().event;
async openPanel(id?: string, focus?: boolean): Promise<undefined> { return undefined; }
getPanel(id: string): any { return activeViewlet; }
getPanels() { return []; }
getPinnedPanels() { return []; }
getActivePanel(): IPanel { return activeViewlet; }
setPanelEnablement(id: string, enabled: boolean): void { }
dispose() { }
showActivity(panelId: string, badge: IBadge, clazz?: string): IDisposable { throw new Error('Method not implemented.'); }
getProgressIndicator(id: string) { return null!; }
hideActivePanel(): void { }
getLastActivePanelId(): string { return undefined!; }
}
export class TestViewsService implements IViewsService {
declare readonly _serviceBrand: undefined;
onDidChangeViewContainerVisibility = new Emitter<{ id: string; visible: boolean; location: ViewContainerLocation; }>().event;
isViewContainerVisible(id: string): boolean { return true; }
getVisibleViewContainer(): ViewContainer | null { return null; }
openViewContainer(id: string, focus?: boolean): Promise<IPaneComposite | null> { return Promise.resolve(null); }
closeViewContainer(id: string): void { }
onDidChangeViewVisibilityEmitter = new Emitter<{ id: string; visible: boolean; }>();
onDidChangeViewVisibility = this.onDidChangeViewVisibilityEmitter.event;
isViewVisible(id: string): boolean { return true; }
getActiveViewWithId<T extends IView>(id: string): T | null { return null; }
getViewWithId<T extends IView>(id: string): T | null { return null; }
openView<T extends IView>(id: string, focus?: boolean | undefined): Promise<T | null> { return Promise.resolve(null); }
closeView(id: string): void { }
getViewProgressIndicator(id: string) { return null!; }
getActiveViewPaneContainerWithId(id: string) { return null; }
}
export class TestEditorGroupsService implements IEditorGroupsService {
declare readonly _serviceBrand: undefined;
constructor(public groups: TestEditorGroupView[] = []) { }
onDidChangeActiveGroup: Event<IEditorGroup> = Event.None;
onDidActivateGroup: Event<IEditorGroup> = Event.None;
onDidAddGroup: Event<IEditorGroup> = Event.None;
onDidRemoveGroup: Event<IEditorGroup> = Event.None;
onDidMoveGroup: Event<IEditorGroup> = Event.None;
onDidChangeGroupIndex: Event<IEditorGroup> = Event.None;
onDidLayout: Event<IDimension> = Event.None;
onDidChangeEditorPartOptions = Event.None;
orientation = GroupOrientation.HORIZONTAL;
whenRestored: Promise<void> = Promise.resolve(undefined);
willRestoreEditors = false;
contentDimension = { width: 800, height: 600 };
get activeGroup(): IEditorGroup { return this.groups[0]; }
get count(): number { return this.groups.length; }
getGroups(_order?: GroupsOrder): ReadonlyArray<IEditorGroup> { return this.groups; }
getGroup(identifier: number): IEditorGroup | undefined { return this.groups.find(group => group.id === identifier); }
getLabel(_identifier: number): string { return 'Group 1'; }
findGroup(_scope: IFindGroupScope, _source?: number | IEditorGroup, _wrap?: boolean): IEditorGroup { throw new Error('not implemented'); }
activateGroup(_group: number | IEditorGroup): IEditorGroup { throw new Error('not implemented'); }
restoreGroup(_group: number | IEditorGroup): IEditorGroup { throw new Error('not implemented'); }
getSize(_group: number | IEditorGroup): { width: number, height: number; } { return { width: 100, height: 100 }; }
setSize(_group: number | IEditorGroup, _size: { width: number, height: number; }): void { }
arrangeGroups(_arrangement: GroupsArrangement): void { }
applyLayout(_layout: EditorGroupLayout): void { }
setGroupOrientation(_orientation: GroupOrientation): void { }
addGroup(_location: number | IEditorGroup, _direction: GroupDirection, _options?: IAddGroupOptions): IEditorGroup { throw new Error('not implemented'); }
removeGroup(_group: number | IEditorGroup): void { }
moveGroup(_group: number | IEditorGroup, _location: number | IEditorGroup, _direction: GroupDirection): IEditorGroup { throw new Error('not implemented'); }
mergeGroup(_group: number | IEditorGroup, _target: number | IEditorGroup, _options?: IMergeGroupOptions): IEditorGroup { throw new Error('not implemented'); }
mergeAllGroups(): IEditorGroup { throw new Error('not implemented'); }
copyGroup(_group: number | IEditorGroup, _location: number | IEditorGroup, _direction: GroupDirection): IEditorGroup { throw new Error('not implemented'); }
centerLayout(active: boolean): void { }
isLayoutCentered(): boolean { return false; }
partOptions!: IEditorPartOptions;
enforcePartOptions(options: IEditorPartOptions): IDisposable { return Disposable.None; }
}
export class TestEditorGroupView implements IEditorGroupView {
constructor(public id: number) { }
get group(): EditorGroup { throw new Error('not implemented'); }
activeEditorPane!: IVisibleEditorPane;
activeEditor!: IEditorInput;
previewEditor!: IEditorInput;
count!: number;
stickyCount!: number;
disposed!: boolean;
editors: ReadonlyArray<IEditorInput> = [];
label!: string;
ariaLabel!: string;
index!: number;
whenRestored: Promise<void> = Promise.resolve(undefined);
element!: HTMLElement;
minimumWidth!: number;
maximumWidth!: number;
minimumHeight!: number;
maximumHeight!: number;
titleHeight!: IEditorGroupTitleHeight;
isEmpty = true;
isMinimized = false;
onWillDispose: Event<void> = Event.None;
onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidOpenEditorFail: Event<IEditorInput> = Event.None;
onDidFocus: Event<void> = Event.None;
onDidChange: Event<{ width: number; height: number; }> = Event.None;
onWillMoveEditor: Event<IEditorMoveEvent> = Event.None;
getEditors(_order?: EditorsOrder): ReadonlyArray<IEditorInput> { return []; }
getEditorByIndex(_index: number): IEditorInput { throw new Error('not implemented'); }
getIndexOfEditor(_editor: IEditorInput): number { return -1; }
openEditor(_editor: IEditorInput, _options?: IEditorOptions): Promise<IEditorPane> { throw new Error('not implemented'); }
openEditors(_editors: IEditorInputWithOptions[]): Promise<IEditorPane> { throw new Error('not implemented'); }
isOpened(_editor: IEditorInput | IResourceEditorInput): boolean { return false; }
isPinned(_editor: IEditorInput): boolean { return false; }
isSticky(_editor: IEditorInput): boolean { return false; }
isActive(_editor: IEditorInput): boolean { return false; }
moveEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IEditorOptions | ITextEditorOptions): void { }
copyEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IEditorOptions | ITextEditorOptions): void { }
async closeEditor(_editor?: IEditorInput, options?: ICloseEditorOptions): Promise<void> { }
async closeEditors(_editors: IEditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> { }
async closeAllEditors(options?: ICloseAllEditorsOptions): Promise<void> { }
async replaceEditors(_editors: IEditorReplacement[]): Promise<void> { }
pinEditor(_editor?: IEditorInput): void { }
stickEditor(editor?: IEditorInput | undefined): void { }
unstickEditor(editor?: IEditorInput | undefined): void { }
focus(): void { }
get scopedContextKeyService(): IContextKeyService { throw new Error('not implemented'); }
setActive(_isActive: boolean): void { }
notifyIndexChanged(_index: number): void { }
dispose(): void { }
toJSON(): object { return Object.create(null); }
layout(_width: number, _height: number): void { }
relayout() { }
}
export class TestEditorGroupAccessor implements IEditorGroupsAccessor {
groups: IEditorGroupView[] = [];
activeGroup!: IEditorGroupView;
partOptions: IEditorPartOptions = {};
onDidChangeEditorPartOptions = Event.None;
onDidVisibilityChange = Event.None;
getGroup(identifier: number): IEditorGroupView | undefined { throw new Error('Method not implemented.'); }
getGroups(order: GroupsOrder): IEditorGroupView[] { throw new Error('Method not implemented.'); }
activateGroup(identifier: number | IEditorGroupView): IEditorGroupView { throw new Error('Method not implemented.'); }
restoreGroup(identifier: number | IEditorGroupView): IEditorGroupView { throw new Error('Method not implemented.'); }
addGroup(location: number | IEditorGroupView, direction: GroupDirection, options?: IAddGroupOptions | undefined): IEditorGroupView { throw new Error('Method not implemented.'); }
mergeGroup(group: number | IEditorGroupView, target: number | IEditorGroupView, options?: IMergeGroupOptions | undefined): IEditorGroupView { throw new Error('Method not implemented.'); }
moveGroup(group: number | IEditorGroupView, location: number | IEditorGroupView, direction: GroupDirection): IEditorGroupView { throw new Error('Method not implemented.'); }
copyGroup(group: number | IEditorGroupView, location: number | IEditorGroupView, direction: GroupDirection): IEditorGroupView { throw new Error('Method not implemented.'); }
removeGroup(group: number | IEditorGroupView): void { throw new Error('Method not implemented.'); }
arrangeGroups(arrangement: GroupsArrangement, target?: number | IEditorGroupView | undefined): void { throw new Error('Method not implemented.'); }
}
export class TestEditorService implements EditorServiceImpl {
declare readonly _serviceBrand: undefined;
onDidActiveEditorChange: Event<void> = Event.None;
onDidVisibleEditorsChange: Event<void> = Event.None;
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidOpenEditorFail: Event<IEditorIdentifier> = Event.None;
onDidMostRecentlyActiveEditorsChange: Event<void> = Event.None;
private _activeTextEditorControl: ICodeEditor | IDiffEditor | undefined;
public get activeTextEditorControl(): ICodeEditor | IDiffEditor | undefined { return this._activeTextEditorControl; }
public set activeTextEditorControl(value: ICodeEditor | IDiffEditor | undefined) { this._activeTextEditorControl = value; }
activeEditorPane: IVisibleEditorPane | undefined;
activeTextEditorMode: string | undefined;
private _activeEditor: IEditorInput | undefined;
public get activeEditor(): IEditorInput | undefined { return this._activeEditor; }
public set activeEditor(value: IEditorInput | undefined) { this._activeEditor = value; }
editors: ReadonlyArray<IEditorInput> = [];
mostRecentlyActiveEditors: ReadonlyArray<IEditorIdentifier> = [];
visibleEditorPanes: ReadonlyArray<IVisibleEditorPane> = [];
visibleTextEditorControls = [];
visibleEditors: ReadonlyArray<IEditorInput> = [];
count = this.editors.length;
constructor(private editorGroupService?: IEditorGroupsService) { }
getEditors() { return []; }
findEditors() { return []; }
getEditorOverrides(resource: URI, options: IEditorOptions | undefined, group: IEditorGroup | undefined): [IOpenEditorOverrideHandler, IOpenEditorOverrideEntry][] { return []; }
overrideOpenEditor(_handler: IOpenEditorOverrideHandler): IDisposable { return toDisposable(() => undefined); }
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
openEditor(editor: IResourceEditorInput | IUntitledTextResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditorPane | undefined>;
openEditor(editor: IResourceDiffEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditorPane | undefined>;
async openEditor(editor: IEditorInput | IResourceEditorInputType, optionsOrGroup?: IEditorOptions | ITextEditorOptions | IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined> {
throw new Error('not implemented');
}
doResolveEditorOpenRequest(editor: IEditorInput | IResourceEditorInputType): [IEditorGroup, EditorInput, EditorOptions | undefined] | undefined {
if (!this.editorGroupService) {
return undefined;
}
return [this.editorGroupService.activeGroup, editor as EditorInput, undefined];
}
openEditors(_editors: any, _group?: any): Promise<IEditorPane[]> { throw new Error('not implemented'); }
isOpen(_editor: IEditorInput | IResourceEditorInput): boolean { return false; }
replaceEditors(_editors: any, _group: any) { return Promise.resolve(undefined); }
createEditorInput(_input: IResourceEditorInput | IUntitledTextResourceEditorInput | IResourceDiffEditorInput): EditorInput { throw new Error('not implemented'); }
save(editors: IEditorIdentifier[], options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
saveAll(options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean; }): Promise<void> { throw new Error('Method not implemented.'); }
}
export class TestFileService implements IFileService {
declare readonly _serviceBrand: undefined;
private readonly _onDidFilesChange = new Emitter<FileChangesEvent>();
private readonly _onDidRunOperation = new Emitter<FileOperationEvent>();
readonly onWillActivateFileSystemProvider = Event.None;
readonly onDidChangeFileSystemProviderCapabilities = Event.None;
readonly onError: Event<Error> = Event.None;
private content = 'Hello Html';
private lastReadFileUri!: URI;
setContent(content: string): void { this.content = content; }
getContent(): string { return this.content; }
getLastReadFileUri(): URI { return this.lastReadFileUri; }
get onDidFilesChange(): Event<FileChangesEvent> { return this._onDidFilesChange.event; }
fireFileChanges(event: FileChangesEvent): void { this._onDidFilesChange.fire(event); }
get onDidRunOperation(): Event<FileOperationEvent> { return this._onDidRunOperation.event; }
fireAfterOperation(event: FileOperationEvent): void { this._onDidRunOperation.fire(event); }
resolve(resource: URI, _options?: IResolveFileOptions): Promise<IFileStat>;
resolve(resource: URI, _options: IResolveMetadataFileOptions): Promise<IFileStatWithMetadata>;
resolve(resource: URI, _options?: IResolveFileOptions): Promise<IFileStat> {
return Promise.resolve({
resource,
etag: Date.now().toString(),
encoding: 'utf8',
mtime: Date.now(),
size: 42,
isFile: true,
isDirectory: false,
isSymbolicLink: false,
name: basename(resource)
});
}
async resolveAll(toResolve: { resource: URI, options?: IResolveFileOptions; }[]): Promise<IResolveFileResult[]> {
const stats = await Promise.all(toResolve.map(resourceAndOption => this.resolve(resourceAndOption.resource, resourceAndOption.options)));
return stats.map(stat => ({ stat, success: true }));
}
readonly notExistsSet = new Set<URI>();
async exists(_resource: URI): Promise<boolean> { return !this.notExistsSet.has(_resource); }
readShouldThrowError: Error | undefined = undefined;
readFile(resource: URI, options?: IReadFileOptions | undefined): Promise<IFileContent> {
if (this.readShouldThrowError) {
throw this.readShouldThrowError;
}
this.lastReadFileUri = resource;
return Promise.resolve({
resource: resource,
value: VSBuffer.fromString(this.content),
etag: 'index.txt',
encoding: 'utf8',
mtime: Date.now(),
ctime: Date.now(),
name: basename(resource),
size: 1
});
}
readFileStream(resource: URI, options?: IReadFileStreamOptions | undefined): Promise<IFileStreamContent> {
if (this.readShouldThrowError) {
throw this.readShouldThrowError;
}
this.lastReadFileUri = resource;
return Promise.resolve({
resource,
value: bufferToStream(VSBuffer.fromString(this.content)),
etag: 'index.txt',
encoding: 'utf8',
mtime: Date.now(),
ctime: Date.now(),
size: 1,
name: basename(resource)
});
}
writeShouldThrowError: Error | undefined = undefined;
async writeFile(resource: URI, bufferOrReadable: VSBuffer | VSBufferReadable, options?: IWriteFileOptions): Promise<IFileStatWithMetadata> {
await timeout(0);
if (this.writeShouldThrowError) {
throw this.writeShouldThrowError;
}
return ({
resource,
etag: 'index.txt',
mtime: Date.now(),
ctime: Date.now(),
size: 42,
isFile: true,
isDirectory: false,
isSymbolicLink: false,
name: basename(resource)
});
}
move(_source: URI, _target: URI, _overwrite?: boolean): Promise<IFileStatWithMetadata> { return Promise.resolve(null!); }
copy(_source: URI, _target: URI, _overwrite?: boolean): Promise<IFileStatWithMetadata> { return Promise.resolve(null!); }
createFile(_resource: URI, _content?: VSBuffer | VSBufferReadable, _options?: ICreateFileOptions): Promise<IFileStatWithMetadata> { return Promise.resolve(null!); }
createFolder(_resource: URI): Promise<IFileStatWithMetadata> { return Promise.resolve(null!); }
onDidChangeFileSystemProviderRegistrations = Event.None;
private providers = new Map<string, IFileSystemProvider>();
registerProvider(scheme: string, provider: IFileSystemProvider) {
this.providers.set(scheme, provider);
return toDisposable(() => this.providers.delete(scheme));
}
activateProvider(_scheme: string): Promise<void> { throw new Error('not implemented'); }
canHandleResource(resource: URI): boolean { return resource.scheme === Schemas.file || this.providers.has(resource.scheme); }
listCapabilities() {
return [
{ scheme: Schemas.file, capabilities: FileSystemProviderCapabilities.FileOpenReadWriteClose },
...Iterable.map(this.providers, ([scheme, p]) => { return { scheme, capabilities: p.capabilities }; })
];
}
hasCapability(resource: URI, capability: FileSystemProviderCapabilities): boolean {
if (capability === FileSystemProviderCapabilities.PathCaseSensitive && isLinux) {
return true;
}
return false;
}
async del(_resource: URI, _options?: { useTrash?: boolean, recursive?: boolean; }): Promise<void> { }
readonly watches: URI[] = [];
watch(_resource: URI): IDisposable {
this.watches.push(_resource);
return toDisposable(() => this.watches.splice(this.watches.indexOf(_resource), 1));
}
getWriteEncoding(_resource: URI): IResourceEncoding { return { encoding: 'utf8', hasBOM: false }; }
dispose(): void { }
async canCreateFile(source: URI, options?: ICreateFileOptions): Promise<Error | true> { return true; }
async canMove(source: URI, target: URI, overwrite?: boolean | undefined): Promise<Error | true> { return true; }
async canCopy(source: URI, target: URI, overwrite?: boolean | undefined): Promise<Error | true> { return true; }
async canDelete(resource: URI, options?: { useTrash?: boolean | undefined; recursive?: boolean | undefined; } | undefined): Promise<Error | true> { return true; }
}
export class TestBackupFileService extends InMemoryBackupFileService {
constructor() {
super(resource => String(hash(resource.path)));
}
parseBackupContent(textBufferFactory: ITextBufferFactory): string {
const textBuffer = textBufferFactory.create(DefaultEndOfLine.LF).textBuffer;
const lineCount = textBuffer.getLineCount();
const range = new Range(1, 1, lineCount, textBuffer.getLineLength(lineCount) + 1);
return textBuffer.getValueInRange(range, EndOfLinePreference.TextDefined);
}
}
export class InMemoryTestBackupFileService extends BrowserBackupFileService {
readonly fileService: IFileService;
private backupResourceJoiners: Function[];
private discardBackupJoiners: Function[];
discardedBackups: URI[];
constructor() {
const environmentService = TestEnvironmentService;
const logService = new NullLogService();
const fileService = new FileService(logService);
fileService.registerProvider(Schemas.file, new InMemoryFileSystemProvider());
fileService.registerProvider(Schemas.userData, new InMemoryFileSystemProvider());
super(new TestContextService(TestWorkspace), environmentService, fileService, logService);
this.fileService = fileService;
this.backupResourceJoiners = [];
this.discardBackupJoiners = [];
this.discardedBackups = [];
}
joinBackupResource(): Promise<void> {
return new Promise(resolve => this.backupResourceJoiners.push(resolve));
}
joinDiscardBackup(): Promise<void> {
return new Promise(resolve => this.discardBackupJoiners.push(resolve));