@codingame/monaco-vscode-working-copy-service-override 7.0.11 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/vscode/src/vs/workbench/services/workingCopy/common/workingCopyHistoryService.js +5 -6
- package/vscode/src/vs/workbench/services/workingCopy/common/workingCopyHistoryTracker.js +2 -3
- package/workingCopy.js +24 -3
- package/vscode/src/vs/workbench/services/workingCopy/browser/workingCopyBackupService.js +0 -26
- package/vscode/src/vs/workbench/services/workingCopy/browser/workingCopyBackupTracker.js +0 -45
- package/vscode/src/vs/workbench/services/workingCopy/common/workingCopyBackupTracker.js +0 -258
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-working-copy-service-override",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"vscode": "npm:@codingame/monaco-vscode-api@7.
|
|
30
|
-
"@codingame/monaco-vscode-files-service-override": "7.
|
|
29
|
+
"vscode": "npm:@codingame/monaco-vscode-api@7.1.1",
|
|
30
|
+
"@codingame/monaco-vscode-files-service-override": "7.1.1"
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
-
import {
|
|
2
|
+
import { localize } from 'vscode/vscode/vs/nls';
|
|
3
3
|
import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
|
|
4
4
|
import { assertIsDefined } from 'vscode/vscode/vs/base/common/types';
|
|
5
5
|
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
|
|
@@ -30,10 +30,9 @@ import { lastOrDefault, distinct } from 'vscode/vscode/vs/base/common/arrays';
|
|
|
30
30
|
import { escapeRegExpCharacters } from 'vscode/vscode/vs/base/common/strings';
|
|
31
31
|
|
|
32
32
|
var WorkingCopyHistoryService_1, NativeWorkingCopyHistoryService_1;
|
|
33
|
-
const _moduleId = "vs/workbench/services/workingCopy/common/workingCopyHistoryService";
|
|
34
33
|
class WorkingCopyHistoryModel {
|
|
35
34
|
static { this.ENTRIES_FILE = 'entries.json'; }
|
|
36
|
-
static { this.FILE_SAVED_SOURCE = SaveSourceRegistry.registerSource('default.source', (
|
|
35
|
+
static { this.FILE_SAVED_SOURCE = SaveSourceRegistry.registerSource('default.source', ( localize(8524, "File Saved"))); }
|
|
37
36
|
static { this.SETTINGS = {
|
|
38
37
|
MAX_ENTRIES: 'workbench.localHistory.maxFileEntries',
|
|
39
38
|
MERGE_PERIOD: 'workbench.localHistory.mergeWindow'
|
|
@@ -379,8 +378,8 @@ class WorkingCopyHistoryModel {
|
|
|
379
378
|
}
|
|
380
379
|
let WorkingCopyHistoryService = class WorkingCopyHistoryService extends Disposable {
|
|
381
380
|
static { WorkingCopyHistoryService_1 = this; }
|
|
382
|
-
static { this.FILE_MOVED_SOURCE = SaveSourceRegistry.registerSource('moved.source', (
|
|
383
|
-
static { this.FILE_RENAMED_SOURCE = SaveSourceRegistry.registerSource('renamed.source', (
|
|
381
|
+
static { this.FILE_MOVED_SOURCE = SaveSourceRegistry.registerSource('moved.source', ( localize(8525, "File Moved"))); }
|
|
382
|
+
static { this.FILE_RENAMED_SOURCE = SaveSourceRegistry.registerSource('renamed.source', ( localize(8526, "File Renamed"))); }
|
|
384
383
|
constructor(fileService, remoteAgentService, environmentService, uriIdentityService, labelService, logService, configurationService) {
|
|
385
384
|
super();
|
|
386
385
|
this.fileService = fileService;
|
|
@@ -597,7 +596,7 @@ let NativeWorkingCopyHistoryService = class NativeWorkingCopyHistoryService exte
|
|
|
597
596
|
onWillShutdown(e) {
|
|
598
597
|
this.storeAllScheduler.dispose();
|
|
599
598
|
this.storeAllCts.dispose(true);
|
|
600
|
-
e.join(this.storeAll(e.token), { id: 'join.workingCopyHistory', label: (
|
|
599
|
+
e.join(this.storeAll(e.token), { id: 'join.workingCopyHistory', label: ( localize(8527, "Saving local history")) });
|
|
601
600
|
}
|
|
602
601
|
onDidChangeModels() {
|
|
603
602
|
if (!this.storeAllScheduler.isScheduled()) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
-
import {
|
|
2
|
+
import { localize } from 'vscode/vscode/vs/nls';
|
|
3
3
|
import { Limiter, GlobalIdleValue } from 'vscode/vscode/vs/base/common/async';
|
|
4
4
|
import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
|
|
5
5
|
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
@@ -20,7 +20,6 @@ import { FileOperation } from 'vscode/vscode/vs/platform/files/common/files';
|
|
|
20
20
|
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
|
|
21
21
|
|
|
22
22
|
var WorkingCopyHistoryTracker_1;
|
|
23
|
-
const _moduleId = "vs/workbench/services/workingCopy/common/workingCopyHistoryTracker";
|
|
24
23
|
let WorkingCopyHistoryTracker = class WorkingCopyHistoryTracker extends Disposable {
|
|
25
24
|
static { WorkingCopyHistoryTracker_1 = this; }
|
|
26
25
|
static { this.SETTINGS = {
|
|
@@ -28,7 +27,7 @@ let WorkingCopyHistoryTracker = class WorkingCopyHistoryTracker extends Disposab
|
|
|
28
27
|
SIZE_LIMIT: 'workbench.localHistory.maxFileSize',
|
|
29
28
|
EXCLUDES: 'workbench.localHistory.exclude'
|
|
30
29
|
}; }
|
|
31
|
-
static { this.UNDO_REDO_SAVE_SOURCE = SaveSourceRegistry.registerSource('undoRedo.source', (
|
|
30
|
+
static { this.UNDO_REDO_SAVE_SOURCE = SaveSourceRegistry.registerSource('undoRedo.source', ( localize(10832, "Undo / Redo"))); }
|
|
32
31
|
constructor(workingCopyService, workingCopyHistoryService, uriIdentityService, pathService, configurationService, undoRedoService, contextService, fileService) {
|
|
33
32
|
super();
|
|
34
33
|
this.workingCopyService = workingCopyService;
|
package/workingCopy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
1
2
|
import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
|
|
2
|
-
import { BrowserWorkingCopyBackupService } from './vscode/src/vs/workbench/services/workingCopy/browser/workingCopyBackupService.js';
|
|
3
3
|
import { IWorkingCopyBackupService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyBackup.service';
|
|
4
4
|
import { WorkingCopyService } from './vscode/src/vs/workbench/services/workingCopy/common/workingCopyService.js';
|
|
5
5
|
import { IWorkingCopyService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyService.service';
|
|
@@ -7,12 +7,33 @@ import { WorkingCopyEditorService } from './vscode/src/vs/workbench/services/wor
|
|
|
7
7
|
import { IWorkingCopyEditorService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyEditorService.service';
|
|
8
8
|
import { IWorkingCopyHistoryService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyHistory.service';
|
|
9
9
|
import { BrowserWorkingCopyHistoryService } from './vscode/src/vs/workbench/services/workingCopy/browser/workingCopyHistoryService.js';
|
|
10
|
+
import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace.service';
|
|
11
|
+
import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService.service';
|
|
12
|
+
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
|
|
13
|
+
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
|
|
14
|
+
import { joinPath } from 'vscode/vscode/vs/base/common/resources';
|
|
15
|
+
import { WorkingCopyBackupService } from './vscode/src/vs/workbench/services/workingCopy/common/workingCopyBackupService.js';
|
|
10
16
|
import getServiceOverride$1 from '@codingame/monaco-vscode-files-service-override';
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
let BrowserWorkingCopyBackupService = class BrowserWorkingCopyBackupService extends WorkingCopyBackupService {
|
|
19
|
+
constructor(memory, contextService, environmentService, fileService, logService) {
|
|
20
|
+
super(memory ? undefined : joinPath(environmentService.userRoamingDataHome, 'Backups', contextService.getWorkspace().id), fileService, logService);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
BrowserWorkingCopyBackupService = __decorate([
|
|
24
|
+
( __param(1, IWorkspaceContextService)),
|
|
25
|
+
( __param(2, IWorkbenchEnvironmentService)),
|
|
26
|
+
( __param(3, IFileService)),
|
|
27
|
+
( __param(4, ILogService))
|
|
28
|
+
], BrowserWorkingCopyBackupService);
|
|
29
|
+
function getServiceOverride({ storage = 'userData' } = {}) {
|
|
13
30
|
return {
|
|
14
31
|
...getServiceOverride$1(),
|
|
15
|
-
|
|
32
|
+
...(storage != null
|
|
33
|
+
? {
|
|
34
|
+
[( IWorkingCopyBackupService.toString())]: new SyncDescriptor(BrowserWorkingCopyBackupService, [storage === 'memory'], false)
|
|
35
|
+
}
|
|
36
|
+
: {}),
|
|
16
37
|
[( IWorkingCopyService.toString())]: new SyncDescriptor(WorkingCopyService, [], false),
|
|
17
38
|
[( IWorkingCopyEditorService.toString())]: new SyncDescriptor(WorkingCopyEditorService, [], false),
|
|
18
39
|
[( IWorkingCopyHistoryService.toString())]: new SyncDescriptor(BrowserWorkingCopyHistoryService, [], false)
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
-
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
|
|
3
|
-
import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService.service';
|
|
4
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
|
|
5
|
-
import { WorkingCopyBackupService } from '../common/workingCopyBackupService.js';
|
|
6
|
-
import 'vscode/vscode/vs/platform/instantiation/common/extensions';
|
|
7
|
-
import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
8
|
-
import { joinPath } from 'vscode/vscode/vs/base/common/resources';
|
|
9
|
-
import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace.service';
|
|
10
|
-
import { registerWorkbenchContribution2, WorkbenchPhase } from 'vscode/vscode/vs/workbench/common/contributions';
|
|
11
|
-
import { BrowserWorkingCopyBackupTracker } from './workingCopyBackupTracker.js';
|
|
12
|
-
|
|
13
|
-
let BrowserWorkingCopyBackupService = class BrowserWorkingCopyBackupService extends WorkingCopyBackupService {
|
|
14
|
-
constructor(contextService, environmentService, fileService, logService) {
|
|
15
|
-
super(joinPath(environmentService.userRoamingDataHome, 'Backups', contextService.getWorkspace().id), fileService, logService);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
BrowserWorkingCopyBackupService = ( __decorate([
|
|
19
|
-
( __param(0, IWorkspaceContextService)),
|
|
20
|
-
( __param(1, IWorkbenchEnvironmentService)),
|
|
21
|
-
( __param(2, IFileService)),
|
|
22
|
-
( __param(3, ILogService))
|
|
23
|
-
], BrowserWorkingCopyBackupService));
|
|
24
|
-
registerWorkbenchContribution2(BrowserWorkingCopyBackupTracker.ID, BrowserWorkingCopyBackupTracker, WorkbenchPhase.BlockStartup);
|
|
25
|
-
|
|
26
|
-
export { BrowserWorkingCopyBackupService };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
-
import { IWorkingCopyBackupService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyBackup.service';
|
|
3
|
-
import { IFilesConfigurationService } from 'vscode/vscode/vs/workbench/services/filesConfiguration/common/filesConfigurationService.service';
|
|
4
|
-
import { IWorkingCopyService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyService.service';
|
|
5
|
-
import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle.service';
|
|
6
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
|
|
7
|
-
import { WorkingCopyBackupTracker } from '../common/workingCopyBackupTracker.js';
|
|
8
|
-
import { IWorkingCopyEditorService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyEditorService.service';
|
|
9
|
-
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService.service';
|
|
10
|
-
import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService.service';
|
|
11
|
-
|
|
12
|
-
let BrowserWorkingCopyBackupTracker = class BrowserWorkingCopyBackupTracker extends WorkingCopyBackupTracker {
|
|
13
|
-
static { this.ID = 'workbench.contrib.browserWorkingCopyBackupTracker'; }
|
|
14
|
-
constructor(workingCopyBackupService, filesConfigurationService, workingCopyService, lifecycleService, logService, workingCopyEditorService, editorService, editorGroupService) {
|
|
15
|
-
super(workingCopyBackupService, workingCopyService, logService, lifecycleService, filesConfigurationService, workingCopyEditorService, editorService, editorGroupService);
|
|
16
|
-
}
|
|
17
|
-
onFinalBeforeShutdown(reason) {
|
|
18
|
-
const modifiedWorkingCopies = this.workingCopyService.modifiedWorkingCopies;
|
|
19
|
-
if (!modifiedWorkingCopies.length) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (!this.filesConfigurationService.isHotExitEnabled) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
for (const modifiedWorkingCopy of modifiedWorkingCopies) {
|
|
26
|
-
if (!this.workingCopyBackupService.hasBackupSync(modifiedWorkingCopy, this.getContentVersion(modifiedWorkingCopy))) {
|
|
27
|
-
this.logService.warn('Unload veto: pending backups');
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
BrowserWorkingCopyBackupTracker = ( __decorate([
|
|
35
|
-
( __param(0, IWorkingCopyBackupService)),
|
|
36
|
-
( __param(1, IFilesConfigurationService)),
|
|
37
|
-
( __param(2, IWorkingCopyService)),
|
|
38
|
-
( __param(3, ILifecycleService)),
|
|
39
|
-
( __param(4, ILogService)),
|
|
40
|
-
( __param(5, IWorkingCopyEditorService)),
|
|
41
|
-
( __param(6, IEditorService)),
|
|
42
|
-
( __param(7, IEditorGroupsService))
|
|
43
|
-
], BrowserWorkingCopyBackupTracker));
|
|
44
|
-
|
|
45
|
-
export { BrowserWorkingCopyBackupTracker };
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { Disposable, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
2
|
-
import { WorkingCopyCapabilities } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopy';
|
|
3
|
-
import { LifecyclePhase } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
|
|
4
|
-
import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
|
|
5
|
-
import { Promises } from 'vscode/vscode/vs/base/common/async';
|
|
6
|
-
import { EditorsOrder } from 'vscode/vscode/vs/workbench/common/editor';
|
|
7
|
-
|
|
8
|
-
class WorkingCopyBackupTracker extends Disposable {
|
|
9
|
-
constructor(workingCopyBackupService, workingCopyService, logService, lifecycleService, filesConfigurationService, workingCopyEditorService, editorService, editorGroupService) {
|
|
10
|
-
super();
|
|
11
|
-
this.workingCopyBackupService = workingCopyBackupService;
|
|
12
|
-
this.workingCopyService = workingCopyService;
|
|
13
|
-
this.logService = logService;
|
|
14
|
-
this.lifecycleService = lifecycleService;
|
|
15
|
-
this.filesConfigurationService = filesConfigurationService;
|
|
16
|
-
this.workingCopyEditorService = workingCopyEditorService;
|
|
17
|
-
this.editorService = editorService;
|
|
18
|
-
this.editorGroupService = editorGroupService;
|
|
19
|
-
this.mapWorkingCopyToContentVersion = ( new Map());
|
|
20
|
-
this.pendingBackupOperations = ( new Map());
|
|
21
|
-
this.suspended = false;
|
|
22
|
-
this.unrestoredBackups = ( new Set());
|
|
23
|
-
this.whenReady = this.resolveBackupsToRestore();
|
|
24
|
-
this._isReady = false;
|
|
25
|
-
for (const workingCopy of this.workingCopyService.modifiedWorkingCopies) {
|
|
26
|
-
this.onDidRegister(workingCopy);
|
|
27
|
-
}
|
|
28
|
-
this.registerListeners();
|
|
29
|
-
}
|
|
30
|
-
registerListeners() {
|
|
31
|
-
this._register(this.workingCopyService.onDidRegister(workingCopy => this.onDidRegister(workingCopy)));
|
|
32
|
-
this._register(this.workingCopyService.onDidUnregister(workingCopy => this.onDidUnregister(workingCopy)));
|
|
33
|
-
this._register(this.workingCopyService.onDidChangeDirty(workingCopy => this.onDidChangeDirty(workingCopy)));
|
|
34
|
-
this._register(this.workingCopyService.onDidChangeContent(workingCopy => this.onDidChangeContent(workingCopy)));
|
|
35
|
-
this._register(this.lifecycleService.onBeforeShutdown(event => event.finalVeto(() => this.onFinalBeforeShutdown(event.reason), 'veto.backups')));
|
|
36
|
-
this._register(this.lifecycleService.onWillShutdown(() => this.onWillShutdown()));
|
|
37
|
-
this._register(this.workingCopyEditorService.onDidRegisterHandler(handler => this.restoreBackups(handler)));
|
|
38
|
-
}
|
|
39
|
-
onWillShutdown() {
|
|
40
|
-
this.cancelBackupOperations();
|
|
41
|
-
this.suspendBackupOperations();
|
|
42
|
-
}
|
|
43
|
-
static { this.DEFAULT_BACKUP_SCHEDULE_DELAYS = {
|
|
44
|
-
['default']: 1000,
|
|
45
|
-
['delayed']: 2000
|
|
46
|
-
}; }
|
|
47
|
-
onDidRegister(workingCopy) {
|
|
48
|
-
if (this.suspended) {
|
|
49
|
-
this.logService.warn(`[backup tracker] suspended, ignoring register event`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (workingCopy.isModified()) {
|
|
53
|
-
this.scheduleBackup(workingCopy);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
onDidUnregister(workingCopy) {
|
|
57
|
-
this.mapWorkingCopyToContentVersion.delete(workingCopy);
|
|
58
|
-
if (this.suspended) {
|
|
59
|
-
this.logService.warn(`[backup tracker] suspended, ignoring unregister event`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
this.discardBackup(workingCopy);
|
|
63
|
-
}
|
|
64
|
-
onDidChangeDirty(workingCopy) {
|
|
65
|
-
if (this.suspended) {
|
|
66
|
-
this.logService.warn(`[backup tracker] suspended, ignoring dirty change event`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (workingCopy.isDirty()) {
|
|
70
|
-
this.scheduleBackup(workingCopy);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.discardBackup(workingCopy);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
onDidChangeContent(workingCopy) {
|
|
77
|
-
const contentVersionId = this.getContentVersion(workingCopy);
|
|
78
|
-
this.mapWorkingCopyToContentVersion.set(workingCopy, contentVersionId + 1);
|
|
79
|
-
if (this.suspended) {
|
|
80
|
-
this.logService.warn(`[backup tracker] suspended, ignoring content change event`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (workingCopy.isModified()) {
|
|
84
|
-
this.scheduleBackup(workingCopy);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
scheduleBackup(workingCopy) {
|
|
88
|
-
this.cancelBackupOperation(workingCopy);
|
|
89
|
-
this.logService.trace(`[backup tracker] scheduling backup`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
90
|
-
const workingCopyIdentifier = { resource: workingCopy.resource, typeId: workingCopy.typeId };
|
|
91
|
-
const cts = ( new CancellationTokenSource());
|
|
92
|
-
const handle = setTimeout(async () => {
|
|
93
|
-
if (cts.token.isCancellationRequested) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (workingCopy.isModified()) {
|
|
97
|
-
this.logService.trace(`[backup tracker] creating backup`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
98
|
-
try {
|
|
99
|
-
const backup = await workingCopy.backup(cts.token);
|
|
100
|
-
if (cts.token.isCancellationRequested) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (workingCopy.isModified()) {
|
|
104
|
-
this.logService.trace(`[backup tracker] storing backup`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
105
|
-
await this.workingCopyBackupService.backup(workingCopy, backup.content, this.getContentVersion(workingCopy), backup.meta, cts.token);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
this.logService.error(error);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (!cts.token.isCancellationRequested) {
|
|
113
|
-
this.doClearPendingBackupOperation(workingCopyIdentifier);
|
|
114
|
-
}
|
|
115
|
-
}, this.getBackupScheduleDelay(workingCopy));
|
|
116
|
-
this.pendingBackupOperations.set(workingCopyIdentifier, {
|
|
117
|
-
cancel: () => {
|
|
118
|
-
this.logService.trace(`[backup tracker] clearing pending backup creation`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
119
|
-
cts.cancel();
|
|
120
|
-
},
|
|
121
|
-
disposable: toDisposable(() => {
|
|
122
|
-
cts.dispose();
|
|
123
|
-
clearTimeout(handle);
|
|
124
|
-
})
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
getBackupScheduleDelay(workingCopy) {
|
|
128
|
-
if (typeof workingCopy.backupDelay === 'number') {
|
|
129
|
-
return workingCopy.backupDelay;
|
|
130
|
-
}
|
|
131
|
-
let backupScheduleDelay;
|
|
132
|
-
if (workingCopy.capabilities & WorkingCopyCapabilities.Untitled) {
|
|
133
|
-
backupScheduleDelay = 'default';
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
backupScheduleDelay = this.filesConfigurationService.hasShortAutoSaveDelay(workingCopy.resource) ? 'delayed' : 'default';
|
|
137
|
-
}
|
|
138
|
-
return WorkingCopyBackupTracker.DEFAULT_BACKUP_SCHEDULE_DELAYS[backupScheduleDelay];
|
|
139
|
-
}
|
|
140
|
-
getContentVersion(workingCopy) {
|
|
141
|
-
return this.mapWorkingCopyToContentVersion.get(workingCopy) || 0;
|
|
142
|
-
}
|
|
143
|
-
discardBackup(workingCopy) {
|
|
144
|
-
this.cancelBackupOperation(workingCopy);
|
|
145
|
-
const workingCopyIdentifier = { resource: workingCopy.resource, typeId: workingCopy.typeId };
|
|
146
|
-
const cts = ( new CancellationTokenSource());
|
|
147
|
-
this.doDiscardBackup(workingCopyIdentifier, cts);
|
|
148
|
-
this.pendingBackupOperations.set(workingCopyIdentifier, {
|
|
149
|
-
cancel: () => {
|
|
150
|
-
this.logService.trace(`[backup tracker] clearing pending backup discard`, ( workingCopy.resource.toString()), workingCopy.typeId);
|
|
151
|
-
cts.cancel();
|
|
152
|
-
},
|
|
153
|
-
disposable: cts
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
async doDiscardBackup(workingCopyIdentifier, cts) {
|
|
157
|
-
this.logService.trace(`[backup tracker] discarding backup`, ( workingCopyIdentifier.resource.toString()), workingCopyIdentifier.typeId);
|
|
158
|
-
try {
|
|
159
|
-
await this.workingCopyBackupService.discardBackup(workingCopyIdentifier, cts.token);
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
this.logService.error(error);
|
|
163
|
-
}
|
|
164
|
-
if (!cts.token.isCancellationRequested) {
|
|
165
|
-
this.doClearPendingBackupOperation(workingCopyIdentifier);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
cancelBackupOperation(workingCopy) {
|
|
169
|
-
let workingCopyIdentifier = undefined;
|
|
170
|
-
for (const [identifier] of this.pendingBackupOperations) {
|
|
171
|
-
if (( identifier.resource.toString()) === ( workingCopy.resource.toString()) && identifier.typeId === workingCopy.typeId) {
|
|
172
|
-
workingCopyIdentifier = identifier;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (workingCopyIdentifier) {
|
|
177
|
-
this.doClearPendingBackupOperation(workingCopyIdentifier, { cancel: true });
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
doClearPendingBackupOperation(workingCopyIdentifier, options) {
|
|
181
|
-
const pendingBackupOperation = this.pendingBackupOperations.get(workingCopyIdentifier);
|
|
182
|
-
if (!pendingBackupOperation) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (options?.cancel) {
|
|
186
|
-
pendingBackupOperation.cancel();
|
|
187
|
-
}
|
|
188
|
-
pendingBackupOperation.disposable.dispose();
|
|
189
|
-
this.pendingBackupOperations.delete(workingCopyIdentifier);
|
|
190
|
-
}
|
|
191
|
-
cancelBackupOperations() {
|
|
192
|
-
for (const [, operation] of this.pendingBackupOperations) {
|
|
193
|
-
operation.cancel();
|
|
194
|
-
operation.disposable.dispose();
|
|
195
|
-
}
|
|
196
|
-
this.pendingBackupOperations.clear();
|
|
197
|
-
}
|
|
198
|
-
suspendBackupOperations() {
|
|
199
|
-
this.suspended = true;
|
|
200
|
-
return { resume: () => this.suspended = false };
|
|
201
|
-
}
|
|
202
|
-
get isReady() { return this._isReady; }
|
|
203
|
-
async resolveBackupsToRestore() {
|
|
204
|
-
await this.lifecycleService.when(LifecyclePhase.Restored);
|
|
205
|
-
for (const backup of await this.workingCopyBackupService.getBackups()) {
|
|
206
|
-
this.unrestoredBackups.add(backup);
|
|
207
|
-
}
|
|
208
|
-
this._isReady = true;
|
|
209
|
-
}
|
|
210
|
-
async restoreBackups(handler) {
|
|
211
|
-
await this.whenReady;
|
|
212
|
-
const openedEditorsForBackups = ( new Set());
|
|
213
|
-
const nonOpenedEditorsForBackups = ( new Set());
|
|
214
|
-
const restoredBackups = ( new Set());
|
|
215
|
-
for (const unrestoredBackup of this.unrestoredBackups) {
|
|
216
|
-
const canHandleUnrestoredBackup = await handler.handles(unrestoredBackup);
|
|
217
|
-
if (!canHandleUnrestoredBackup) {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
let hasOpenedEditorForBackup = false;
|
|
221
|
-
for (const { editor } of this.editorService.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)) {
|
|
222
|
-
const isUnrestoredBackupOpened = handler.isOpen(unrestoredBackup, editor);
|
|
223
|
-
if (isUnrestoredBackupOpened) {
|
|
224
|
-
openedEditorsForBackups.add(editor);
|
|
225
|
-
hasOpenedEditorForBackup = true;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (!hasOpenedEditorForBackup) {
|
|
229
|
-
nonOpenedEditorsForBackups.add(await handler.createEditor(unrestoredBackup));
|
|
230
|
-
}
|
|
231
|
-
restoredBackups.add(unrestoredBackup);
|
|
232
|
-
}
|
|
233
|
-
if (nonOpenedEditorsForBackups.size > 0) {
|
|
234
|
-
await this.editorGroupService.activeGroup.openEditors(( [...nonOpenedEditorsForBackups].map(nonOpenedEditorForBackup => ({
|
|
235
|
-
editor: nonOpenedEditorForBackup,
|
|
236
|
-
options: {
|
|
237
|
-
pinned: true,
|
|
238
|
-
preserveFocus: true,
|
|
239
|
-
inactive: true
|
|
240
|
-
}
|
|
241
|
-
}))));
|
|
242
|
-
for (const nonOpenedEditorForBackup of nonOpenedEditorsForBackups) {
|
|
243
|
-
openedEditorsForBackups.add(nonOpenedEditorForBackup);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
await Promises.settled(( [...openedEditorsForBackups].map(async (openedEditorForBackup) => {
|
|
247
|
-
if (this.editorService.isVisible(openedEditorForBackup)) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
return openedEditorForBackup.resolve();
|
|
251
|
-
})));
|
|
252
|
-
for (const restoredBackup of restoredBackups) {
|
|
253
|
-
this.unrestoredBackups.delete(restoredBackup);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export { WorkingCopyBackupTracker };
|