Repository navigation
Expand file tree
/
Copy patheditor.ts
More file actions
581 lines (489 loc) · 16.6 KB
/
Copy patheditor.ts
File metadata and controls
581 lines (489 loc) · 16.6 KB
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { equals } from '../../../base/common/arrays.js';
import { Event } from '../../../base/common/event.js';
import { IDisposable } from '../../../base/common/lifecycle.js';
import { URI } from '../../../base/common/uri.js';
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
import { IUriIdentityService } from '../../uriIdentity/common/uriIdentity.js';
import { IRectangle } from '../../window/common/window.js';
export interface IResolvableEditorModel extends IDisposable {
/**
* Resolves the model.
*/
resolve(): Promise<void>;
/**
* Find out if the editor model was resolved or not.
*/
isResolved(): boolean;
}
export function isResolvedEditorModel(model: IDisposable | undefined | null): model is IResolvableEditorModel {
const candidate = model as IResolvableEditorModel | undefined | null;
return typeof candidate?.resolve === 'function'
&& typeof candidate?.isResolved === 'function';
}
export interface IBaseUntypedEditorInput {
/**
* Optional options to use when opening the input.
*/
options?: IEditorOptions;
/**
* Label to show for the input.
*/
readonly label?: string;
/**
* Description to show for the input.
*/
readonly description?: string;
}
export interface IBaseResourceEditorInput extends IBaseUntypedEditorInput {
/**
* Hint to indicate that this input should be treated as a
* untitled file.
*
* Without this hint, the editor service will make a guess by
* looking at the scheme of the resource(s).
*
* Use `forceUntitled: true` when you pass in a `resource` that
* does not use the `untitled` scheme. The `resource` will then
* be used as associated path when saving the untitled file.
*/
readonly forceUntitled?: boolean;
}
export interface IBaseTextResourceEditorInput extends IBaseResourceEditorInput {
/**
* Optional options to use when opening the text input.
*/
options?: ITextEditorOptions;
/**
* The contents of the text input if known. If provided,
* the input will not attempt to load the contents from
* disk and may appear dirty.
*/
contents?: string;
/**
* The encoding of the text input if known.
*/
encoding?: string;
/**
* The identifier of the language id of the text input
* if known to use when displaying the contents.
*/
languageId?: string;
}
export interface IResourceEditorInput extends IBaseResourceEditorInput {
/**
* The resource URI of the resource to open.
*/
readonly resource: URI;
}
export interface ITextResourceEditorInput extends IResourceEditorInput, IBaseTextResourceEditorInput {
/**
* Optional options to use when opening the text input.
*/
options?: ITextEditorOptions;
}
/**
* This identifier allows to uniquely identify an editor with a
* resource, type and editor identifier.
*/
export interface IResourceEditorInputIdentifier {
/**
* The type of the editor.
*/
readonly typeId: string;
/**
* The identifier of the editor if provided.
*/
readonly editorId: string | undefined;
/**
* The resource URI of the editor.
*/
readonly resource: URI;
}
export enum EditorActivation {
/**
* Activate the editor after it opened. This will automatically restore
* the editor if it is minimized.
*/
ACTIVATE = 1,
/**
* Only restore the editor if it is minimized but do not activate it.
*
* Note: will only work in combination with the `preserveFocus: true` option.
* Otherwise, if focus moves into the editor, it will activate and restore
* automatically.
*/
RESTORE,
/**
* Preserve the current active editor.
*
* Note: will only work in combination with the `preserveFocus: true` option.
* Otherwise, if focus moves into the editor, it will activate and restore
* automatically.
*/
PRESERVE
}
export enum EditorResolution {
/**
* Only exclusive editors are considered.
*
* Note: the value is non-zero so that `override` is truthy when set.
*/
EXCLUSIVE_ONLY = 1
}
export enum EditorOpenSource {
/**
* Default: the editor is opening via a programmatic call
* to the editor service API.
*/
API,
/**
* Indicates that a user action triggered the opening, e.g.
* via mouse or keyboard use.
*/
USER
}
/**
* An editor column or symbolic placement relative to the active editor.
*/
export enum ViewColumn {
Active = -1,
Beside = -2,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9
}
export interface IEditorOptions {
/**
* Tells the editor to not receive keyboard focus when the editor is being opened.
*
* Will also not activate the group the editor opens in unless the group is already
* the active one. This behaviour can be overridden via the `activation` option.
*/
preserveFocus?: boolean;
/**
* This option is only relevant if an editor is opened into a group that is not active
* already and allows to control if the inactive group should become active, restored
* or preserved.
*
* By default, the editor group will become active unless `preserveFocus` or `inactive`
* is specified.
*/
activation?: EditorActivation;
/**
* Tells the editor to reload the editor input in the editor even if it is identical to the one
* already showing. By default, the editor will not reload the input if it is identical to the
* one showing.
*/
forceReload?: boolean;
/**
* Will reveal the editor if it is already opened and visible in any of the opened editor groups.
*
* Note that this option is just a hint that might be ignored if the user wants to open an editor explicitly
* to the side of another one or into a specific editor group.
*/
revealIfVisible?: boolean;
/**
* Will reveal the editor if it is already opened (even when not visible) in any of the opened editor groups.
*
* Note that this option is just a hint that might be ignored if the user wants to open an editor explicitly
* to the side of another one or into a specific editor group.
*/
revealIfOpened?: boolean;
/**
* An editor that is pinned remains in the editor stack even when another editor is being opened.
* An editor that is not pinned will always get replaced by another editor that is not pinned.
*/
pinned?: boolean;
/**
* An editor that is sticky moves to the beginning of the editors list within the group and will remain
* there unless explicitly closed. Operations such as "Close All" will not close sticky editors.
*/
sticky?: boolean;
/**
* The index in the document stack where to insert the editor into when opening.
*/
index?: number;
/**
* An active editor that is opened will show its contents directly. Set to true to open an editor
* in the background without loading its contents.
*
* Will also not activate the group the editor opens in unless the group is already
* the active one. This behaviour can be overridden via the `activation` option.
*/
inactive?: boolean;
/**
* In case of an error opening the editor, will not present this error to the user (e.g. by showing
* a generic placeholder in the editor area). So it is up to the caller to provide error information
* in that case.
*
* By default, an error when opening an editor will result in a placeholder editor that shows the error.
* In certain cases a modal dialog may be presented to ask the user for further action.
*/
ignoreError?: boolean;
/**
* Allows to override the editor that should be used to display the input:
* - `undefined`: let the editor decide for itself
* - `string`: specific override by id
* - `EditorResolution`: specific override handling
*/
override?: string | EditorResolution;
/**
* A optional hint to signal in which context the editor opens.
*
* If configured to be `EditorOpenSource.USER`, this hint can be
* used in various places to control the experience. For example,
* if the editor to open fails with an error, a notification could
* inform about this in a modal dialog. If the editor opened through
* some background task, the notification would show in the background,
* not as a modal dialog.
*/
source?: EditorOpenSource;
/**
* Indicates whether the editor is being opened due to an explicit user
* action (`true`) or automatically (`false`) as a side effect of another
* action (e.g. the chat agent opening files it has edited).
*
* When omitted, callers should be treated as explicit. Layout logic may
* use this to decide whether to react to the visibility change (for
* example, by leaving the auxiliary side bar maximized when the change
* was not initiated by the user).
*/
isExplicit?: boolean;
/**
* An optional property to signal that certain view state should be
* applied when opening the editor.
*/
viewState?: object;
/**
* A transient editor will attempt to appear as preview and certain components
* (such as history tracking) may decide to ignore the editor when it becomes
* active.
* This option is meant to be used only when the editor is used for a short
* period of time, for example when opening a preview of the editor from a
* picker control in the background while navigating through results of the picker.
*
* Note: an editor that is already opened in a group that is not transient, will
* not turn transient.
*/
transient?: boolean;
/**
* Options that only apply when `AUX_WINDOW_GROUP` is used for opening.
*/
auxiliary?: {
/**
* Define the bounds of the editor window.
*/
bounds?: Partial<IRectangle>;
/**
* Show editor compact, hiding unnecessary elements.
*/
compact?: boolean;
/**
* Show the editor always on top of other windows.
*/
alwaysOnTop?: boolean;
};
/**
* Options that only apply when `MODAL_GROUP` is used for opening.
*/
modal?: IModalEditorPartOptions;
}
export interface IModalEditorPartOptions {
/**
* Whether the modal editor should be maximized.
*/
readonly maximized?: boolean;
/**
* Size of the modal editor part unless it is maximized.
*/
readonly size?: { readonly width: number; readonly height: number };
/**
* Position of the modal editor part unless it is maximized.
*/
readonly position?: { readonly left: number; readonly top: number };
/**
* The navigation context for navigating between items
* within this modal editor. Pass `undefined` to clear.
*/
readonly navigation?: IModalEditorNavigation;
/**
* Optional sidebar content to render on the left side of the
* modal editor. The caller provides a render callback that
* receives a container element and a layout callback, and
* returns a disposable to clean up when the modal closes.
*
* Note: the sidebar will only be shown when provided during
* opening and cannot currently be added, removed, or updated
* after the modal editor is opened.
*/
readonly sidebar?: IModalEditorSidebar;
}
/**
* Per-editor modal options provided by an editor input that wants to influence
* how it is rendered inside the modal editor part. Unlike
* {@link IModalEditorPartOptions}, these options are scoped to a single editor
* and resolved from the active editor (not from the part-level options API).
*/
export interface IModalEditorOptions {
/**
* When true, the modal editor renders a simplified header:
* uses the editor background, hides the title icon, removes the
* bottom border and uses a slightly taller fixed height. Useful
* for editors that provide their own header chrome.
*/
readonly compactHeader?: boolean;
/**
* Whether the modal editor can be moved into an editor area.
*/
readonly canMoveToEditorArea?: boolean;
}
/**
* Marker interface for editor inputs that want to customize how they are
* rendered when opened in the modal editor part (see {@link IModalEditorOptions}).
*/
export interface IModalEditorOptionsProvider {
getModalEditorOptions(): IModalEditorOptions | undefined;
}
export function isModalEditorOptionsProvider(obj: unknown): obj is IModalEditorOptionsProvider {
return !!obj && typeof (obj as IModalEditorOptionsProvider).getModalEditorOptions === 'function';
}
export function canMoveModalEditorToEditorArea(obj: unknown): boolean {
return !isModalEditorOptionsProvider(obj) || obj.getModalEditorOptions()?.canMoveToEditorArea !== false;
}
/**
* Modal sidebar supports rendering custom content in a sidebar next to the main editor content.
*/
export interface IModalEditorSidebar {
/**
* Sidebar width set by the user via resizing, if any.
*/
readonly sidebarWidth?: number;
/**
* Whether the sidebar is hidden.
*/
readonly sidebarHidden?: boolean;
/**
* Render the sidebar content into the given container.
*
* @param container The DOM element to render into.
* @param onDidLayout An event that fires when the sidebar is
* laid out with the available dimensions.
* @param contextKeyService A context key service scoped to the modal
* that content should descend from (e.g. when creating lists/trees)
* so that modal-level context keys remain active while the content
* has focus.
* @returns A disposable to clean up when the modal closes.
*/
readonly render: (container: unknown /* HTMLElement */, onDidLayout: Event<{ readonly height: number; readonly width: number }>, contextKeyService: IContextKeyService) => IDisposable;
}
/**
* Context for navigating between items within a modal editor.
*/
export interface IModalEditorNavigation {
/**
* Total number of items in the navigation list.
*/
readonly total: number;
/**
* Current 0-based index in the navigation list.
*/
readonly current: number;
/**
* Navigate to the item at the given 0-based index.
*/
readonly navigate: (index: number) => void;
}
export interface ITextEditorSelection {
readonly startLineNumber: number;
readonly startColumn: number;
readonly endLineNumber?: number;
readonly endColumn?: number;
}
export const enum TextEditorSelectionRevealType {
/**
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically.
*/
Center = 0,
/**
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.
*/
CenterIfOutsideViewport = 1,
/**
* Option to scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport, but not quite at the top.
*/
NearTop = 2,
/**
* Option to scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport, but not quite at the top.
* Only if it lies outside the viewport
*/
NearTopIfOutsideViewport = 3,
}
export const enum TextEditorSelectionSource {
/**
* Programmatic source indicates a selection change that
* was not triggered by the user via keyboard or mouse
* but through text editor APIs.
*/
PROGRAMMATIC = 'api',
/**
* Navigation source indicates a selection change that
* was caused via some command or UI component such as
* an outline tree.
*/
NAVIGATION = 'code.navigation',
/**
* Jump source indicates a selection change that
* was caused from within the text editor to another
* location in the same or different text editor such
* as "Go to definition".
*/
JUMP = 'code.jump'
}
export interface ITextEditorOptions extends IEditorOptions {
/**
* Text editor selection.
*/
selection?: ITextEditorSelection;
/**
* Option to control the text editor selection reveal type.
* Defaults to TextEditorSelectionRevealType.Center
*/
selectionRevealType?: TextEditorSelectionRevealType;
/**
* Source of the call that caused the selection.
*/
selectionSource?: TextEditorSelectionSource | string;
}
export type ITextEditorChange = [
originalStartLineNumber: number,
originalEndLineNumberExclusive: number,
modifiedStartLineNumber: number,
modifiedEndLineNumberExclusive: number
];
export interface ITextEditorDiffInformation {
readonly documentVersion: number;
readonly original: URI | undefined;
readonly modified: URI;
readonly changes: readonly ITextEditorChange[];
}
export function isTextEditorDiffInformationEqual(
uriIdentityService: IUriIdentityService,
diff1: ITextEditorDiffInformation | undefined,
diff2: ITextEditorDiffInformation | undefined): boolean {
return diff1?.documentVersion === diff2?.documentVersion &&
uriIdentityService.extUri.isEqual(diff1?.original, diff2?.original) &&
uriIdentityService.extUri.isEqual(diff1?.modified, diff2?.modified) &&
equals<ITextEditorChange>(diff1?.changes, diff2?.changes, (a, b) => {
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
});
}