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
|
/*---------------------------------------------------------------------------------------------
* 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 'vs/nls';
import { URI } from 'vs/base/common/uri';
import { Event } from 'vs/base/common/event';
import { Schemas } from 'vs/base/common/network';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { IWorkingCopyHistoryEntry, IWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistory';
import { API_OPEN_DIFF_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
import { LocalHistoryFileSystemProvider } from 'vs/workbench/contrib/localHistory/browser/localHistoryFileSystemProvider';
import { ContextKeyExpr, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { registerAction2, Action2, MenuId } from 'vs/platform/actions/common/actions';
import { basename, basenameOrAuthority, dirname } from 'vs/base/common/resources';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { EditorResourceAccessor, SaveSourceRegistry, SideBySideEditor } from 'vs/workbench/common/editor';
import { IFileService } from 'vs/platform/files/common/files';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ActiveEditorContext, ResourceContextKey } from 'vs/workbench/common/contextkeys';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
import { IModelService } from 'vs/editor/common/services/model';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { ILabelService } from 'vs/platform/label/common/label';
import { firstOrDefault } from 'vs/base/common/arrays';
import { LOCAL_HISTORY_DATE_FORMATTER, LOCAL_HISTORY_ICON_RESTORE, LOCAL_HISTORY_MENU_CONTEXT_KEY } from 'vs/workbench/contrib/localHistory/browser/localHistory';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
const LOCAL_HISTORY_CATEGORY = { value: localize('localHistory.category', "Local History"), original: 'Local History' };
export interface ITimelineCommandArgument {
uri: URI;
handle: string;
}
//#region Compare with File
export const COMPARE_WITH_FILE_LABEL = { value: localize('localHistory.compareWithFile', "Compare with File"), original: 'Compare with File' };
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.compareWithFile',
title: COMPARE_WITH_FILE_LABEL,
menu: {
id: MenuId.TimelineItemContext,
group: '1_compare',
order: 1,
when: LOCAL_HISTORY_MENU_CONTEXT_KEY
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const commandService = accessor.get(ICommandService);
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
return commandService.executeCommand(API_OPEN_DIFF_EDITOR_COMMAND_ID, ...toDiffEditorArguments(entry, entry.workingCopy.resource));
}
}
});
//#endregion
//#region Compare with Previous
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.compareWithPrevious',
title: { value: localize('localHistory.compareWithPrevious', "Compare with Previous"), original: 'Compare with Previous' },
menu: {
id: MenuId.TimelineItemContext,
group: '1_compare',
order: 2,
when: LOCAL_HISTORY_MENU_CONTEXT_KEY
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const commandService = accessor.get(ICommandService);
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const editorService = accessor.get(IEditorService);
const { entry, previous } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
// Without a previous entry, just show the entry directly
if (!previous) {
return openEntry(entry, editorService);
}
// Open real diff editor
return commandService.executeCommand(API_OPEN_DIFF_EDITOR_COMMAND_ID, ...toDiffEditorArguments(previous, entry));
}
}
});
//#endregion
//#region Select for Compare / Compare with Selected
let itemSelectedForCompare: ITimelineCommandArgument | undefined = undefined;
const LocalHistoryItemSelectedForCompare = new RawContextKey<boolean>('localHistoryItemSelectedForCompare', false, true);
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.selectForCompare',
title: { value: localize('localHistory.selectForCompare', "Select for Compare"), original: 'Select for Compare' },
menu: {
id: MenuId.TimelineItemContext,
group: '2_compare_with',
order: 2,
when: LOCAL_HISTORY_MENU_CONTEXT_KEY
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const contextKeyService = accessor.get(IContextKeyService);
const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
itemSelectedForCompare = item;
LocalHistoryItemSelectedForCompare.bindTo(contextKeyService).set(true);
}
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.compareWithSelected',
title: { value: localize('localHistory.compareWithSelected', "Compare with Selected"), original: 'Compare with Selected' },
menu: {
id: MenuId.TimelineItemContext,
group: '2_compare_with',
order: 1,
when: ContextKeyExpr.and(LOCAL_HISTORY_MENU_CONTEXT_KEY, LocalHistoryItemSelectedForCompare)
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const commandService = accessor.get(ICommandService);
if (!itemSelectedForCompare) {
return;
}
const selectedEntry = (await findLocalHistoryEntry(workingCopyHistoryService, itemSelectedForCompare)).entry;
if (!selectedEntry) {
return;
}
const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
return commandService.executeCommand(API_OPEN_DIFF_EDITOR_COMMAND_ID, ...toDiffEditorArguments(selectedEntry, entry));
}
}
});
//#endregion
//#region Show Contents
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.open',
title: { value: localize('localHistory.open', "Show Contents"), original: 'Show Contents' },
menu: {
id: MenuId.TimelineItemContext,
group: '3_contents',
order: 1,
when: LOCAL_HISTORY_MENU_CONTEXT_KEY
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const editorService = accessor.get(IEditorService);
const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
return openEntry(entry, editorService);
}
}
});
//#region Restore Contents
const RESTORE_CONTENTS_LABEL = { value: localize('localHistory.restore', "Restore Contents"), original: 'Restore Contents' };
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.restoreViaEditor',
title: RESTORE_CONTENTS_LABEL,
menu: {
id: MenuId.EditorTitle,
group: 'navigation',
order: -10,
when: ResourceContextKey.Scheme.isEqualTo(LocalHistoryFileSystemProvider.SCHEMA)
},
icon: LOCAL_HISTORY_ICON_RESTORE
});
}
async run(accessor: ServicesAccessor, uri: URI): Promise<void> {
const { associatedResource, location } = LocalHistoryFileSystemProvider.fromLocalHistoryFileSystem(uri);
return restore(accessor, { uri: associatedResource, handle: basenameOrAuthority(location) });
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.restore',
title: RESTORE_CONTENTS_LABEL,
menu: {
id: MenuId.TimelineItemContext,
group: '3_contents',
order: 2,
when: LOCAL_HISTORY_MENU_CONTEXT_KEY
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
return restore(accessor, item);
}
});
const restoreSaveSource = SaveSourceRegistry.registerSource('localHistoryRestore.source', localize('localHistoryRestore.source', "File Restored"));
async function restore(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const fileService = accessor.get(IFileService);
const dialogService = accessor.get(IDialogService);
const workingCopyService = accessor.get(IWorkingCopyService);
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const editorService = accessor.get(IEditorService);
const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
// Ask for confirmation
const { confirmed } = await dialogService.confirm({
message: localize('confirmRestoreMessage', "Do you want to restore the contents of '{0}'?", basename(entry.workingCopy.resource)),
detail: localize('confirmRestoreDetail', "Restoring will discard any unsaved changes."),
primaryButton: localize({ key: 'restoreButtonLabel', comment: ['&& denotes a mnemonic'] }, "&&Restore"),
type: 'warning'
});
if (!confirmed) {
return;
}
// Revert all dirty working copies for target
const workingCopies = workingCopyService.getAll(entry.workingCopy.resource);
if (workingCopies) {
for (const workingCopy of workingCopies) {
if (workingCopy.isDirty()) {
await workingCopy.revert({ soft: true });
}
}
}
// Replace target with contents of history entry
await fileService.cloneFile(entry.location, entry.workingCopy.resource);
// Restore all working copies for target
if (workingCopies) {
for (const workingCopy of workingCopies) {
await workingCopy.revert({ force: true });
}
}
// Open target
await editorService.openEditor({ resource: entry.workingCopy.resource });
// Add new entry
await workingCopyHistoryService.addEntry({
resource: entry.workingCopy.resource,
source: restoreSaveSource
}, CancellationToken.None);
// Close source
await closeEntry(entry, editorService);
}
}
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.restoreViaPicker',
title: { value: localize('localHistory.restoreViaPicker', "Find Entry to Restore"), original: 'Find Entry to Restore' },
f1: true,
category: LOCAL_HISTORY_CATEGORY
});
}
async run(accessor: ServicesAccessor): Promise<void> {
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const quickInputService = accessor.get(IQuickInputService);
const modelService = accessor.get(IModelService);
const languageService = accessor.get(ILanguageService);
const labelService = accessor.get(ILabelService);
const editorService = accessor.get(IEditorService);
const fileService = accessor.get(IFileService);
const commandService = accessor.get(ICommandService);
// Show all resources with associated history entries in picker
// with progress because this operation will take longer the more
// files have been saved overall.
const resourcePicker = quickInputService.createQuickPick<IQuickPickItem & { resource: URI }>();
let cts = new CancellationTokenSource();
resourcePicker.onDidHide(() => cts.dispose(true));
resourcePicker.busy = true;
resourcePicker.show();
const resources = await workingCopyHistoryService.getAll(cts.token);
resourcePicker.busy = false;
resourcePicker.placeholder = localize('restoreViaPicker.filePlaceholder', "Select the file to show local history for");
resourcePicker.matchOnLabel = true;
resourcePicker.matchOnDescription = true;
resourcePicker.items = resources.map(resource => ({
resource,
label: basenameOrAuthority(resource),
description: labelService.getUriLabel(dirname(resource), { relative: true }),
iconClasses: getIconClasses(modelService, languageService, resource)
})).sort((r1, r2) => r1.resource.fsPath < r2.resource.fsPath ? -1 : 1);
await Event.toPromise(resourcePicker.onDidAccept);
resourcePicker.dispose();
const resource = firstOrDefault(resourcePicker.selectedItems)?.resource;
if (!resource) {
return;
}
// Show all entries for the picked resource in another picker
// and open the entry in the end that was selected by the user
const entryPicker = quickInputService.createQuickPick<IQuickPickItem & { entry: IWorkingCopyHistoryEntry }>();
cts = new CancellationTokenSource();
entryPicker.onDidHide(() => cts.dispose(true));
entryPicker.busy = true;
entryPicker.show();
const entries = await workingCopyHistoryService.getEntries(resource, cts.token);
entryPicker.busy = false;
entryPicker.placeholder = localize('restoreViaPicker.entryPlaceholder', "Select the local history entry to open");
entryPicker.matchOnLabel = true;
entryPicker.matchOnDescription = true;
entryPicker.items = Array.from(entries).reverse().map(entry => ({
entry,
label: `$(circle-outline) ${SaveSourceRegistry.getSourceLabel(entry.source)}`,
description: toLocalHistoryEntryDateLabel(entry.timestamp)
}));
await Event.toPromise(entryPicker.onDidAccept);
entryPicker.dispose();
const selectedItem = firstOrDefault(entryPicker.selectedItems);
if (!selectedItem) {
return;
}
const resourceExists = await fileService.exists(selectedItem.entry.workingCopy.resource);
if (resourceExists) {
return commandService.executeCommand(API_OPEN_DIFF_EDITOR_COMMAND_ID, ...toDiffEditorArguments(selectedItem.entry, selectedItem.entry.workingCopy.resource));
}
return openEntry(selectedItem.entry, editorService);
}
});
//#endregion
//#region Rename
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.rename',
title: { value: localize('localHistory.rename', "Rename"), original: 'Rename' },
menu: {
id: MenuId.TimelineItemContext,
group: '5_edit',
order: 1,
when: LOCAL_HISTORY_MENU_CONTEXT_KEY
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const quickInputService = accessor.get(IQuickInputService);
const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
const inputBox = quickInputService.createInputBox();
inputBox.title = localize('renameLocalHistoryEntryTitle', "Rename Local History Entry");
inputBox.ignoreFocusOut = true;
inputBox.placeholder = localize('renameLocalHistoryPlaceholder', "Enter the new name of the local history entry");
inputBox.value = SaveSourceRegistry.getSourceLabel(entry.source);
inputBox.show();
inputBox.onDidAccept(() => {
if (inputBox.value) {
workingCopyHistoryService.updateEntry(entry, { source: inputBox.value }, CancellationToken.None);
}
inputBox.dispose();
});
}
}
});
//#endregion
//#region Delete
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.delete',
title: { value: localize('localHistory.delete', "Delete"), original: 'Delete' },
menu: {
id: MenuId.TimelineItemContext,
group: '5_edit',
order: 2,
when: LOCAL_HISTORY_MENU_CONTEXT_KEY
}
});
}
async run(accessor: ServicesAccessor, item: ITimelineCommandArgument): Promise<void> {
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const editorService = accessor.get(IEditorService);
const dialogService = accessor.get(IDialogService);
const { entry } = await findLocalHistoryEntry(workingCopyHistoryService, item);
if (entry) {
// Ask for confirmation
const { confirmed } = await dialogService.confirm({
message: localize('confirmDeleteMessage', "Do you want to delete the local history entry of '{0}' from {1}?", entry.workingCopy.name, toLocalHistoryEntryDateLabel(entry.timestamp)),
detail: localize('confirmDeleteDetail', "This action is irreversible!"),
primaryButton: localize({ key: 'deleteButtonLabel', comment: ['&& denotes a mnemonic'] }, "&&Delete"),
type: 'warning'
});
if (!confirmed) {
return;
}
// Remove via service
await workingCopyHistoryService.removeEntry(entry, CancellationToken.None);
// Close any opened editors
await closeEntry(entry, editorService);
}
}
});
//#endregion
//#region Delete All
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.deleteAll',
title: { value: localize('localHistory.deleteAll', "Delete All"), original: 'Delete All' },
f1: true,
category: LOCAL_HISTORY_CATEGORY
});
}
async run(accessor: ServicesAccessor): Promise<void> {
const dialogService = accessor.get(IDialogService);
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
// Ask for confirmation
const { confirmed } = await dialogService.confirm({
message: localize('confirmDeleteAllMessage', "Do you want to delete all entries of all files in local history?"),
detail: localize('confirmDeleteAllDetail', "This action is irreversible!"),
primaryButton: localize({ key: 'deleteAllButtonLabel', comment: ['&& denotes a mnemonic'] }, "&&Delete All"),
type: 'warning'
});
if (!confirmed) {
return;
}
// Remove via service
await workingCopyHistoryService.removeAll(CancellationToken.None);
}
});
//#endregion
//#region Create
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.localHistory.create',
title: { value: localize('localHistory.create', "Create Entry"), original: 'Create Entry' },
f1: true,
category: LOCAL_HISTORY_CATEGORY,
precondition: ActiveEditorContext
});
}
async run(accessor: ServicesAccessor): Promise<void> {
const workingCopyHistoryService = accessor.get(IWorkingCopyHistoryService);
const quickInputService = accessor.get(IQuickInputService);
const editorService = accessor.get(IEditorService);
const labelService = accessor.get(ILabelService);
const pathService = accessor.get(IPathService);
const resource = EditorResourceAccessor.getOriginalUri(editorService.activeEditor, { supportSideBySide: SideBySideEditor.PRIMARY });
if (resource?.scheme !== pathService.defaultUriScheme && resource?.scheme !== Schemas.vscodeUserData) {
return; // only enable for selected schemes
}
const inputBox = quickInputService.createInputBox();
inputBox.title = localize('createLocalHistoryEntryTitle', "Create Local History Entry");
inputBox.ignoreFocusOut = true;
inputBox.placeholder = localize('createLocalHistoryPlaceholder', "Enter the new name of the local history entry for '{0}'", labelService.getUriBasenameLabel(resource));
inputBox.show();
inputBox.onDidAccept(async () => {
let entrySource = inputBox.value;
inputBox.dispose();
if (entrySource) {
await workingCopyHistoryService.addEntry({ resource, source: inputBox.value }, CancellationToken.None);
}
});
}
});
//#endregion
//#region Helpers
async function openEntry(entry: IWorkingCopyHistoryEntry, editorService: IEditorService): Promise<void> {
const resource = LocalHistoryFileSystemProvider.toLocalHistoryFileSystem({ location: entry.location, associatedResource: entry.workingCopy.resource });
await editorService.openEditor({
resource,
label: localize('localHistoryEditorLabel', "{0} ({1} • {2})", entry.workingCopy.name, SaveSourceRegistry.getSourceLabel(entry.source), toLocalHistoryEntryDateLabel(entry.timestamp))
});
}
async function closeEntry(entry: IWorkingCopyHistoryEntry, editorService: IEditorService): Promise<void> {
const resource = LocalHistoryFileSystemProvider.toLocalHistoryFileSystem({ location: entry.location, associatedResource: entry.workingCopy.resource });
const editors = editorService.findEditors(resource, { supportSideBySide: SideBySideEditor.ANY });
await editorService.closeEditors(editors, { preserveFocus: true });
}
export function toDiffEditorArguments(entry: IWorkingCopyHistoryEntry, resource: URI): unknown[];
export function toDiffEditorArguments(previousEntry: IWorkingCopyHistoryEntry, entry: IWorkingCopyHistoryEntry): unknown[];
export function toDiffEditorArguments(arg1: IWorkingCopyHistoryEntry, arg2: IWorkingCopyHistoryEntry | URI): unknown[] {
// Left hand side is always a working copy history entry
const originalResource = LocalHistoryFileSystemProvider.toLocalHistoryFileSystem({ location: arg1.location, associatedResource: arg1.workingCopy.resource });
let label: string;
// Right hand side depends on how the method was called
// and is either another working copy history entry
// or the file on disk.
let modifiedResource: URI;
// Compare with file on disk
if (URI.isUri(arg2)) {
const resource = arg2;
modifiedResource = resource;
label = localize('localHistoryCompareToFileEditorLabel', "{0} ({1} • {2}) ↔ {3}", arg1.workingCopy.name, SaveSourceRegistry.getSourceLabel(arg1.source), toLocalHistoryEntryDateLabel(arg1.timestamp), arg1.workingCopy.name);
}
// Compare with another entry
else {
const modified = arg2;
modifiedResource = LocalHistoryFileSystemProvider.toLocalHistoryFileSystem({ location: modified.location, associatedResource: modified.workingCopy.resource });
label = localize('localHistoryCompareToPreviousEditorLabel', "{0} ({1} • {2}) ↔ {3} ({4} • {5})", arg1.workingCopy.name, SaveSourceRegistry.getSourceLabel(arg1.source), toLocalHistoryEntryDateLabel(arg1.timestamp), modified.workingCopy.name, SaveSourceRegistry.getSourceLabel(modified.source), toLocalHistoryEntryDateLabel(modified.timestamp));
}
return [
originalResource,
modifiedResource,
label,
undefined // important to keep order of arguments in command proper
];
}
export async function findLocalHistoryEntry(workingCopyHistoryService: IWorkingCopyHistoryService, descriptor: ITimelineCommandArgument): Promise<{ entry: IWorkingCopyHistoryEntry | undefined; previous: IWorkingCopyHistoryEntry | undefined }> {
const entries = await workingCopyHistoryService.getEntries(descriptor.uri, CancellationToken.None);
let currentEntry: IWorkingCopyHistoryEntry | undefined = undefined;
let previousEntry: IWorkingCopyHistoryEntry | undefined = undefined;
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
if (entry.id === descriptor.handle) {
currentEntry = entry;
previousEntry = entries[i - 1];
break;
}
}
return {
entry: currentEntry,
previous: previousEntry
};
}
const SEP = /\//g;
function toLocalHistoryEntryDateLabel(timestamp: number): string {
return `${LOCAL_HISTORY_DATE_FORMATTER.value.format(timestamp).replace(SEP, '-')}`; // preserving `/` will break editor labels, so replace it with a non-path symbol
}
//#endregion
|