-
Notifications
You must be signed in to change notification settings - Fork 29.7k
/
editor.ts
1696 lines (1382 loc) · 51.7 KB
/
editor.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 { localize } from '../../nls.js';
import { Event } from '../../base/common/event.js';
import { DeepRequiredNonNullable, assertIsDefined } from '../../base/common/types.js';
import { URI } from '../../base/common/uri.js';
import { Disposable, IDisposable, toDisposable } from '../../base/common/lifecycle.js';
import { ICodeEditorViewState, IDiffEditor, IDiffEditorViewState, IEditor, IEditorViewState } from '../../editor/common/editorCommon.js';
import { IEditorOptions, IResourceEditorInput, ITextResourceEditorInput, IBaseTextResourceEditorInput, IBaseUntypedEditorInput, ITextEditorOptions } from '../../platform/editor/common/editor.js';
import type { EditorInput } from './editor/editorInput.js';
import { IInstantiationService, IConstructorSignature, ServicesAccessor, BrandedService } from '../../platform/instantiation/common/instantiation.js';
import { IContextKeyService } from '../../platform/contextkey/common/contextkey.js';
import { Registry } from '../../platform/registry/common/platform.js';
import { IEncodingSupport, ILanguageSupport } from '../services/textfile/common/textfiles.js';
import { IEditorGroup } from '../services/editor/common/editorGroupsService.js';
import { ICompositeControl, IComposite } from './composite.js';
import { FileType, IFileReadLimits, IFileService } from '../../platform/files/common/files.js';
import { IPathData } from '../../platform/window/common/window.js';
import { IExtUri } from '../../base/common/resources.js';
import { Schemas } from '../../base/common/network.js';
import { IEditorService } from '../services/editor/common/editorService.js';
import { ILogService } from '../../platform/log/common/log.js';
import { IErrorWithActions, createErrorWithActions, isErrorWithActions } from '../../base/common/errorMessage.js';
import { IAction, toAction } from '../../base/common/actions.js';
import Severity from '../../base/common/severity.js';
import { IPreferencesService } from '../services/preferences/common/preferences.js';
import { IReadonlyEditorGroupModel } from './editor/editorGroupModel.js';
// Static values for editor contributions
export const EditorExtensions = {
EditorPane: 'workbench.contributions.editors',
EditorFactory: 'workbench.contributions.editor.inputFactories'
};
// Static information regarding the text editor
export const DEFAULT_EDITOR_ASSOCIATION = {
id: 'default',
displayName: localize('promptOpenWith.defaultEditor.displayName', "Text Editor"),
providerDisplayName: localize('builtinProviderDisplayName', "Built-in")
};
/**
* Side by side editor id.
*/
export const SIDE_BY_SIDE_EDITOR_ID = 'workbench.editor.sidebysideEditor';
/**
* Text diff editor id.
*/
export const TEXT_DIFF_EDITOR_ID = 'workbench.editors.textDiffEditor';
/**
* Binary diff editor id.
*/
export const BINARY_DIFF_EDITOR_ID = 'workbench.editors.binaryResourceDiffEditor';
export interface IEditorDescriptor<T extends IEditorPane> {
/**
* The unique type identifier of the editor. All instances
* of the same `IEditorPane` should have the same type
* identifier.
*/
readonly typeId: string;
/**
* The display name of the editor.
*/
readonly name: string;
/**
* Instantiates the editor pane using the provided services.
*/
instantiate(instantiationService: IInstantiationService, group: IEditorGroup): T;
/**
* Whether the descriptor is for the provided editor pane.
*/
describes(editorPane: T): boolean;
}
/**
* The editor pane is the container for workbench editors.
*/
export interface IEditorPane extends IComposite {
/**
* An event to notify when the `IEditorControl` in this
* editor pane changes.
*
* This can be used for editor panes that are a compound
* of multiple editor controls to signal that the active
* editor control has changed when the user clicks around.
*/
readonly onDidChangeControl: Event<void>;
/**
* An optional event to notify when the selection inside the editor
* pane changed in case the editor has a selection concept.
*
* For example, in a text editor pane, the selection changes whenever
* the cursor is set to a new location.
*/
readonly onDidChangeSelection?: Event<IEditorPaneSelectionChangeEvent>;
/**
* An optional event to notify when the editor inside the pane scrolled
*/
readonly onDidChangeScroll?: Event<void>;
/**
* The assigned input of this editor.
*/
readonly input: EditorInput | undefined;
/**
* The assigned options of the editor.
*/
readonly options: IEditorOptions | undefined;
/**
* The assigned group this editor is showing in.
*/
readonly group: IEditorGroup;
/**
* The minimum width of this editor.
*/
readonly minimumWidth: number;
/**
* The maximum width of this editor.
*/
readonly maximumWidth: number;
/**
* The minimum height of this editor.
*/
readonly minimumHeight: number;
/**
* The maximum height of this editor.
*/
readonly maximumHeight: number;
/**
* An event to notify whenever minimum/maximum width/height changes.
*/
readonly onDidChangeSizeConstraints: Event<{ width: number; height: number } | undefined>;
/**
* The context key service for this editor. Should be overridden by
* editors that have their own ScopedContextKeyService
*/
readonly scopedContextKeyService: IContextKeyService | undefined;
/**
* Returns the underlying control of this editor. Callers need to cast
* the control to a specific instance as needed, e.g. by using the
* `isCodeEditor` helper method to access the text code editor.
*
* Use the `onDidChangeControl` event to track whenever the control
* changes.
*/
getControl(): IEditorControl | undefined;
/**
* Returns the current view state of the editor if any.
*
* This method is optional to override for the editor pane
* and should only be overridden when the pane can deal with
* `IEditorOptions.viewState` to be applied when opening.
*/
getViewState(): object | undefined;
/**
* An optional method to return the current selection in
* the editor pane in case the editor pane has a selection
* concept.
*
* Clients of this method will typically react to the
* `onDidChangeSelection` event to receive the current
* selection as needed.
*/
getSelection?(): IEditorPaneSelection | undefined;
/**
* An optional method to return the current scroll position
* of an editor inside the pane.
*
* Clients of this method will typically react to the
* `onDidChangeScroll` event to receive the current
* scroll position as needed.
*/
getScrollPosition?(): IEditorPaneScrollPosition;
/**
* An optional method to set the current scroll position
* of an editor inside the pane.
*/
setScrollPosition?(scrollPosition: IEditorPaneScrollPosition): void;
/**
* Finds out if this editor is visible or not.
*/
isVisible(): boolean;
}
export interface IEditorPaneSelectionChangeEvent {
/**
* More details for how the selection was made.
*/
reason: EditorPaneSelectionChangeReason;
}
export const enum EditorPaneSelectionChangeReason {
/**
* The selection was changed as a result of a programmatic
* method invocation.
*
* For a text editor pane, this for example can be a selection
* being restored from previous view state automatically.
*/
PROGRAMMATIC = 1,
/**
* The selection was changed by the user.
*
* This typically means the user changed the selection
* with mouse or keyboard.
*/
USER,
/**
* The selection was changed as a result of editing in
* the editor pane.
*
* For a text editor pane, this for example can be typing
* in the text of the editor pane.
*/
EDIT,
/**
* The selection was changed as a result of a navigation
* action.
*
* For a text editor pane, this for example can be a result
* of selecting an entry from a text outline view.
*/
NAVIGATION,
/**
* The selection was changed as a result of a jump action
* from within the editor pane.
*
* For a text editor pane, this for example can be a result
* of invoking "Go to definition" from a symbol.
*/
JUMP
}
export interface IEditorPaneSelection {
/**
* Asks to compare this selection to another selection.
*/
compare(otherSelection: IEditorPaneSelection): EditorPaneSelectionCompareResult;
/**
* Asks to massage the provided `options` in a way
* that the selection can be restored when the editor
* is opened again.
*
* For a text editor this means to apply the selected
* line and column as text editor options.
*/
restore(options: IEditorOptions): IEditorOptions;
/**
* Only used for logging to print more info about the selection.
*/
log?(): string;
}
export const enum EditorPaneSelectionCompareResult {
/**
* The selections are identical.
*/
IDENTICAL = 1,
/**
* The selections are similar.
*
* For a text editor this can mean that the one
* selection is in close proximity to the other
* selection.
*
* Upstream clients may decide in this case to
* not treat the selection different from the
* previous one because it is not distinct enough.
*/
SIMILAR = 2,
/**
* The selections are entirely different.
*/
DIFFERENT = 3
}
export interface IEditorPaneWithSelection extends IEditorPane {
readonly onDidChangeSelection: Event<IEditorPaneSelectionChangeEvent>;
getSelection(): IEditorPaneSelection | undefined;
}
export function isEditorPaneWithSelection(editorPane: IEditorPane | undefined): editorPane is IEditorPaneWithSelection {
const candidate = editorPane as IEditorPaneWithSelection | undefined;
return !!candidate && typeof candidate.getSelection === 'function' && !!candidate.onDidChangeSelection;
}
export interface IEditorPaneWithScrolling extends IEditorPane {
readonly onDidChangeScroll: Event<void>;
getScrollPosition(): IEditorPaneScrollPosition;
setScrollPosition(position: IEditorPaneScrollPosition): void;
}
export function isEditorPaneWithScrolling(editorPane: IEditorPane | undefined): editorPane is IEditorPaneWithScrolling {
const candidate = editorPane as IEditorPaneWithScrolling | undefined;
return !!candidate && typeof candidate.getScrollPosition === 'function' && typeof candidate.setScrollPosition === 'function' && !!candidate.onDidChangeScroll;
}
/**
* Scroll position of a pane
*/
export interface IEditorPaneScrollPosition {
readonly scrollTop: number;
readonly scrollLeft?: number;
}
/**
* Try to retrieve the view state for the editor pane that
* has the provided editor input opened, if at all.
*
* This method will return `undefined` if the editor input
* is not visible in any of the opened editor panes.
*/
export function findViewStateForEditor(input: EditorInput, group: GroupIdentifier, editorService: IEditorService): object | undefined {
for (const editorPane of editorService.visibleEditorPanes) {
if (editorPane.group.id === group && input.matches(editorPane.input)) {
return editorPane.getViewState();
}
}
return undefined;
}
/**
* Overrides `IEditorPane` where `input` and `group` are known to be set.
*/
export interface IVisibleEditorPane extends IEditorPane {
readonly input: EditorInput;
}
/**
* The text editor pane is the container for workbench text editors.
*/
export interface ITextEditorPane extends IEditorPane {
/**
* Returns the underlying text editor widget of this editor.
*/
getControl(): IEditor | undefined;
}
/**
* The text editor pane is the container for workbench text diff editors.
*/
export interface ITextDiffEditorPane extends IEditorPane {
/**
* Returns the underlying text diff editor widget of this editor.
*/
getControl(): IDiffEditor | undefined;
}
/**
* Marker interface for the control inside an editor pane. Callers
* have to cast the control to work with it, e.g. via methods
* such as `isCodeEditor(control)`.
*/
export interface IEditorControl extends ICompositeControl { }
export interface IFileEditorFactory {
/**
* The type identifier of the file editor.
*/
typeId: string;
/**
* Creates new new editor capable of showing files.
*/
createFileEditor(resource: URI, preferredResource: URI | undefined, preferredName: string | undefined, preferredDescription: string | undefined, preferredEncoding: string | undefined, preferredLanguageId: string | undefined, preferredContents: string | undefined, instantiationService: IInstantiationService): IFileEditorInput;
/**
* Check if the provided object is a file editor.
*/
isFileEditor(obj: unknown): obj is IFileEditorInput;
}
export interface IEditorFactoryRegistry {
/**
* Registers the file editor factory to use for file editors.
*/
registerFileEditorFactory(factory: IFileEditorFactory): void;
/**
* Returns the file editor factory to use for file editors.
*/
getFileEditorFactory(): IFileEditorFactory;
/**
* Registers a editor serializer for the given editor to the registry.
* An editor serializer is capable of serializing and deserializing editor
* from string data.
*
* @param editorTypeId the type identifier of the editor
* @param serializer the editor serializer for serialization/deserialization
*/
registerEditorSerializer<Services extends BrandedService[]>(editorTypeId: string, ctor: { new(...Services: Services): IEditorSerializer }): IDisposable;
/**
* Returns the editor serializer for the given editor.
*/
getEditorSerializer(editor: EditorInput): IEditorSerializer | undefined;
getEditorSerializer(editorTypeId: string): IEditorSerializer | undefined;
/**
* Starts the registry by providing the required services.
*/
start(accessor: ServicesAccessor): void;
}
export interface IEditorSerializer {
/**
* Determines whether the given editor can be serialized by the serializer.
*/
canSerialize(editor: EditorInput): boolean;
/**
* Returns a string representation of the provided editor that contains enough information
* to deserialize back to the original editor from the deserialize() method.
*/
serialize(editor: EditorInput): string | undefined;
/**
* Returns an editor from the provided serialized form of the editor. This form matches
* the value returned from the serialize() method.
*/
deserialize(instantiationService: IInstantiationService, serializedEditor: string): EditorInput | undefined;
}
export interface IUntitledTextResourceEditorInput extends IBaseTextResourceEditorInput {
/**
* Optional resource for the untitled editor. Depending on the value, the editor:
* - should get a unique name if `undefined` (for example `Untitled-1`)
* - should use the resource directly if the scheme is `untitled:`
* - should change the scheme to `untitled:` otherwise and assume an associated path
*
* Untitled editors with associated path behave slightly different from other untitled
* editors:
* - they are dirty right when opening
* - they will not ask for a file path when saving but use the associated path
*/
readonly resource: URI | undefined;
}
/**
* A resource side by side editor input shows 2 editors side by side but
* without highlighting any differences.
*
* Note: both sides will be resolved as editor individually. As such, it is
* possible to show 2 different editors side by side.
*
* @see {@link IResourceDiffEditorInput} for a variant that compares 2 editors.
*/
export interface IResourceSideBySideEditorInput extends IBaseUntypedEditorInput {
/**
* The right hand side editor to open inside a side-by-side editor.
*/
readonly primary: IResourceEditorInput | ITextResourceEditorInput | IUntitledTextResourceEditorInput;
/**
* The left hand side editor to open inside a side-by-side editor.
*/
readonly secondary: IResourceEditorInput | ITextResourceEditorInput | IUntitledTextResourceEditorInput;
}
/**
* A resource diff editor input compares 2 editors side by side
* highlighting the differences.
*
* Note: both sides must be resolvable to the same editor, or
* a text based presentation will be used as fallback.
*/
export interface IResourceDiffEditorInput extends IBaseUntypedEditorInput {
/**
* The left hand side editor to open inside a diff editor.
*/
readonly original: IResourceEditorInput | ITextResourceEditorInput | IUntitledTextResourceEditorInput;
/**
* The right hand side editor to open inside a diff editor.
*/
readonly modified: IResourceEditorInput | ITextResourceEditorInput | IUntitledTextResourceEditorInput;
}
/**
* A resource list diff editor input compares multiple resources side by side
* highlighting the differences.
*/
export interface IResourceMultiDiffEditorInput extends IBaseUntypedEditorInput {
/**
* A unique identifier of this multi diff editor input.
* If a second multi diff editor with the same uri is opened, the existing one is revealed instead (even if the resources list is different!).
*/
readonly multiDiffSource?: URI;
/**
* The list of resources to compare.
* If not set, the resources are dynamically derived from the {@link multiDiffSource}.
*/
readonly resources?: IMultiDiffEditorResource[];
/**
* Whether the editor should be serialized and stored for subsequent sessions.
*/
readonly isTransient?: boolean;
}
export interface IMultiDiffEditorResource extends IResourceDiffEditorInput {
readonly goToFileResource?: URI;
}
export type IResourceMergeEditorInputSide = (IResourceEditorInput | ITextResourceEditorInput) & { detail?: string };
/**
* A resource merge editor input compares multiple editors
* highlighting the differences for merging.
*
* Note: all sides must be resolvable to the same editor, or
* a text based presentation will be used as fallback.
*/
export interface IResourceMergeEditorInput extends IBaseUntypedEditorInput {
/**
* The one changed version of the file.
*/
readonly input1: IResourceMergeEditorInputSide;
/**
* The second changed version of the file.
*/
readonly input2: IResourceMergeEditorInputSide;
/**
* The base common ancestor of the file to merge.
*/
readonly base: IResourceEditorInput | ITextResourceEditorInput;
/**
* The resulting output of the merge.
*/
readonly result: IResourceEditorInput | ITextResourceEditorInput;
}
export function isResourceEditorInput(editor: unknown): editor is IResourceEditorInput {
if (isEditorInput(editor)) {
return false; // make sure to not accidentally match on typed editor inputs
}
const candidate = editor as IResourceEditorInput | undefined;
return URI.isUri(candidate?.resource);
}
export function isResourceDiffEditorInput(editor: unknown): editor is IResourceDiffEditorInput {
if (isEditorInput(editor)) {
return false; // make sure to not accidentally match on typed editor inputs
}
const candidate = editor as IResourceDiffEditorInput | undefined;
return candidate?.original !== undefined && candidate.modified !== undefined;
}
export function isResourceMultiDiffEditorInput(editor: unknown): editor is IResourceMultiDiffEditorInput {
if (isEditorInput(editor)) {
return false; // make sure to not accidentally match on typed editor inputs
}
const candidate = editor as IResourceMultiDiffEditorInput | undefined;
if (!candidate) {
return false;
}
if (candidate.resources && !Array.isArray(candidate.resources)) {
return false;
}
return !!candidate.resources || !!candidate.multiDiffSource;
}
export function isResourceSideBySideEditorInput(editor: unknown): editor is IResourceSideBySideEditorInput {
if (isEditorInput(editor)) {
return false; // make sure to not accidentally match on typed editor inputs
}
if (isResourceDiffEditorInput(editor)) {
return false; // make sure to not accidentally match on diff editors
}
const candidate = editor as IResourceSideBySideEditorInput | undefined;
return candidate?.primary !== undefined && candidate.secondary !== undefined;
}
export function isUntitledResourceEditorInput(editor: unknown): editor is IUntitledTextResourceEditorInput {
if (isEditorInput(editor)) {
return false; // make sure to not accidentally match on typed editor inputs
}
const candidate = editor as IUntitledTextResourceEditorInput | undefined;
if (!candidate) {
return false;
}
return candidate.resource === undefined || candidate.resource.scheme === Schemas.untitled || candidate.forceUntitled === true;
}
export function isResourceMergeEditorInput(editor: unknown): editor is IResourceMergeEditorInput {
if (isEditorInput(editor)) {
return false; // make sure to not accidentally match on typed editor inputs
}
const candidate = editor as IResourceMergeEditorInput | undefined;
return URI.isUri(candidate?.base?.resource) && URI.isUri(candidate?.input1?.resource) && URI.isUri(candidate?.input2?.resource) && URI.isUri(candidate?.result?.resource);
}
export const enum Verbosity {
SHORT,
MEDIUM,
LONG
}
export const enum SaveReason {
/**
* Explicit user gesture.
*/
EXPLICIT = 1,
/**
* Auto save after a timeout.
*/
AUTO = 2,
/**
* Auto save after editor focus change.
*/
FOCUS_CHANGE = 3,
/**
* Auto save after window change.
*/
WINDOW_CHANGE = 4
}
export type SaveSource = string;
interface ISaveSourceDescriptor {
source: SaveSource;
label: string;
}
class SaveSourceFactory {
private readonly mapIdToSaveSource = new Map<SaveSource, ISaveSourceDescriptor>();
/**
* Registers a `SaveSource` with an identifier and label
* to the registry so that it can be used in save operations.
*/
registerSource(id: string, label: string): SaveSource {
let sourceDescriptor = this.mapIdToSaveSource.get(id);
if (!sourceDescriptor) {
sourceDescriptor = { source: id, label };
this.mapIdToSaveSource.set(id, sourceDescriptor);
}
return sourceDescriptor.source;
}
getSourceLabel(source: SaveSource): string {
return this.mapIdToSaveSource.get(source)?.label ?? source;
}
}
export const SaveSourceRegistry = new SaveSourceFactory();
export interface ISaveOptions {
/**
* An indicator how the save operation was triggered.
*/
reason?: SaveReason;
/**
* An indicator about the source of the save operation.
*
* Must use `SaveSourceRegistry.registerSource()` to obtain.
*/
readonly source?: SaveSource;
/**
* Forces to save the contents of the working copy
* again even if the working copy is not dirty.
*/
readonly force?: boolean;
/**
* Instructs the save operation to skip any save participants.
*/
readonly skipSaveParticipants?: boolean;
/**
* A hint as to which file systems should be available for saving.
*/
readonly availableFileSystems?: string[];
}
export interface IRevertOptions {
/**
* Forces to load the contents of the working copy
* again even if the working copy is not dirty.
*/
readonly force?: boolean;
/**
* A soft revert will clear dirty state of a working copy
* but will not attempt to load it from its persisted state.
*
* This option may be used in scenarios where an editor is
* closed and where we do not require to load the contents.
*/
readonly soft?: boolean;
}
export interface IMoveResult {
editor: EditorInput | IUntypedEditorInput;
options?: IEditorOptions;
}
export const enum EditorInputCapabilities {
/**
* Signals no specific capability for the input.
*/
None = 0,
/**
* Signals that the input is readonly.
*/
Readonly = 1 << 1,
/**
* Signals that the input is untitled.
*/
Untitled = 1 << 2,
/**
* Signals that the input can only be shown in one group
* and not be split into multiple groups.
*/
Singleton = 1 << 3,
/**
* Signals that the input requires workspace trust.
*/
RequiresTrust = 1 << 4,
/**
* Signals that the editor can split into 2 in the same
* editor group.
*/
CanSplitInGroup = 1 << 5,
/**
* Signals that the editor wants its description to be
* visible when presented to the user. By default, a UI
* component may decide to hide the description portion
* for brevity.
*/
ForceDescription = 1 << 6,
/**
* Signals that the editor supports dropping into the
* editor by holding shift.
*/
CanDropIntoEditor = 1 << 7,
/**
* Signals that the editor is composed of multiple editors
* within.
*/
MultipleEditors = 1 << 8,
/**
* Signals that the editor cannot be in a dirty state
* and may still have unsaved changes
*/
Scratchpad = 1 << 9
}
export type IUntypedEditorInput = IResourceEditorInput | ITextResourceEditorInput | IUntitledTextResourceEditorInput | IResourceDiffEditorInput | IResourceMultiDiffEditorInput | IResourceSideBySideEditorInput | IResourceMergeEditorInput;
export abstract class AbstractEditorInput extends Disposable {
// Marker class for implementing `isEditorInput`
}
export function isEditorInput(editor: unknown): editor is EditorInput {
return editor instanceof AbstractEditorInput;
}
export interface EditorInputWithPreferredResource {
/**
* An editor may provide an additional preferred resource alongside
* the `resource` property. While the `resource` property serves as
* unique identifier of the editor that should be used whenever we
* compare to other editors, the `preferredResource` should be used
* in places where e.g. the resource is shown to the user.
*
* For example: on Windows and macOS, the same URI with different
* casing may point to the same file. The editor may chose to
* "normalize" the URIs so that only one editor opens for different
* URIs. But when displaying the editor label to the user, the
* preferred URI should be used.
*
* Not all editors have a `preferredResource`. The `EditorResourceAccessor`
* utility can be used to always get the right resource without having
* to do instanceof checks.
*/
readonly preferredResource: URI;
}
function isEditorInputWithPreferredResource(editor: unknown): editor is EditorInputWithPreferredResource {
const candidate = editor as EditorInputWithPreferredResource | undefined;
return URI.isUri(candidate?.preferredResource);
}
export interface ISideBySideEditorInput extends EditorInput {
/**
* The primary editor input is shown on the right hand side.
*/
primary: EditorInput;
/**
* The secondary editor input is shown on the left hand side.
*/
secondary: EditorInput;
}
export function isSideBySideEditorInput(editor: unknown): editor is ISideBySideEditorInput {
const candidate = editor as ISideBySideEditorInput | undefined;
return isEditorInput(candidate?.primary) && isEditorInput(candidate?.secondary);
}
export interface IDiffEditorInput extends EditorInput {
/**
* The modified (primary) editor input is shown on the right hand side.
*/
modified: EditorInput;
/**
* The original (secondary) editor input is shown on the left hand side.
*/
original: EditorInput;
}
export function isDiffEditorInput(editor: unknown): editor is IDiffEditorInput {
const candidate = editor as IDiffEditorInput | undefined;
return isEditorInput(candidate?.modified) && isEditorInput(candidate?.original);
}
export interface IUntypedFileEditorInput extends ITextResourceEditorInput {
/**
* A marker to create a `IFileEditorInput` from this untyped input.
*/
forceFile: true;
}
/**
* This is a tagging interface to declare an editor input being capable of dealing with files. It is only used in the editor registry
* to register this kind of input to the platform.
*/
export interface IFileEditorInput extends EditorInput, IEncodingSupport, ILanguageSupport, EditorInputWithPreferredResource {
/**
* Gets the resource this file input is about. This will always be the
* canonical form of the resource, so it may differ from the original
* resource that was provided to create the input. Use `preferredResource`
* for the form as it was created.
*/
readonly resource: URI;
/**
* Sets the preferred resource to use for this file input.
*/
setPreferredResource(preferredResource: URI): void;
/**
* Sets the preferred name to use for this file input.
*
* Note: for certain file schemes the input may decide to ignore this
* name and use our standard naming. Specifically for schemes we own,
* we do not let others override the name.
*/
setPreferredName(name: string): void;
/**
* Sets the preferred description to use for this file input.
*
* Note: for certain file schemes the input may decide to ignore this
* description and use our standard naming. Specifically for schemes we own,
* we do not let others override the description.
*/
setPreferredDescription(description: string): void;
/**
* Sets the preferred encoding to use for this file input.
*/
setPreferredEncoding(encoding: string): void;
/**
* Sets the preferred language id to use for this file input.
*/
setPreferredLanguageId(languageId: string): void;
/**
* Sets the preferred contents to use for this file input.
*/
setPreferredContents(contents: string): void;
/**
* Forces this file input to open as binary instead of text.
*/
setForceOpenAsBinary(): void;
/**
* Figure out if the file input has been resolved or not.
*/
isResolved(): boolean;
}
export interface IFileLimitedEditorInputOptions extends IEditorOptions {
/**
* If provided, the size of the file will be checked against the limits
* and an error will be thrown if any limit is exceeded.
*/
readonly limits?: IFileReadLimits;
}
export interface IFileEditorInputOptions extends ITextEditorOptions, IFileLimitedEditorInputOptions { }
export function createTooLargeFileError(group: IEditorGroup, input: EditorInput, options: IEditorOptions | undefined, message: string, preferencesService: IPreferencesService): Error {