@codingame/monaco-vscode-user-data-profile-service-override 5.3.0
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/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +31 -0
- package/userDataProfile.js +118 -0
- package/vscode/src/vs/platform/userDataProfile/browser/userDataProfile.js +95 -0
- package/vscode/src/vs/platform/userDataProfile/common/userDataProfileStorageService.js +84 -0
- package/vscode/src/vs/platform/userDataSync/common/extensionsMerge.js +331 -0
- package/vscode/src/vs/platform/userDataSync/common/extensionsSync.js +545 -0
- package/vscode/src/vs/platform/userDataSync/common/globalStateMerge.js +102 -0
- package/vscode/src/vs/platform/userDataSync/common/globalStateSync.js +431 -0
- package/vscode/src/vs/platform/userDataSync/common/keybindingsMerge.js +277 -0
- package/vscode/src/vs/platform/userDataSync/common/keybindingsSync.js +328 -0
- package/vscode/src/vs/platform/userDataSync/common/settingsSync.js +322 -0
- package/vscode/src/vs/platform/userDataSync/common/snippetsMerge.js +126 -0
- package/vscode/src/vs/platform/userDataSync/common/snippetsSync.js +478 -0
- package/vscode/src/vs/platform/userDataSync/common/tasksSync.js +245 -0
- package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.contribution.js +9 -0
- package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.js +495 -0
- package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfileActions.js +159 -0
- package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilePreview.js +24 -0
- package/vscode/src/vs/workbench/services/userData/browser/userDataInit.js +62 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/extensionsResource.js +328 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/globalStateResource.js +144 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/keybindingsResource.js +119 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/media/userDataProfileView.css.js +6 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/settingsResource.js +140 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/snippetsResource.js +155 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/tasksResource.js +118 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.js +1453 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileInit.js +151 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileManagement.js +180 -0
- package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileStorageService.js +39 -0
- package/vscode/src/vs/workbench/services/userDataSync/browser/userDataSyncInit.js +448 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
+
import { VSBuffer } from 'vscode/vscode/vs/base/common/buffer';
|
|
3
|
+
import { Event } from 'vscode/vscode/vs/base/common/event';
|
|
4
|
+
import { deepClone } from 'vscode/vscode/vs/base/common/objects';
|
|
5
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
|
|
6
|
+
import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment.service';
|
|
7
|
+
import { FileOperationError } from 'vscode/vscode/vs/platform/files/common/files';
|
|
8
|
+
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
|
|
9
|
+
import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
|
|
10
|
+
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
|
|
11
|
+
import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity.service';
|
|
12
|
+
import { IUserDataProfilesService } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfile.service';
|
|
13
|
+
import { AbstractSynchroniser, AbstractInitializer } from 'vscode/vscode/vs/platform/userDataSync/common/abstractSynchronizer';
|
|
14
|
+
import { merge, areSame } from './snippetsMerge.js';
|
|
15
|
+
import { USER_DATA_SYNC_SCHEME } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSync';
|
|
16
|
+
import { IUserDataSyncStoreService, IUserDataSyncLocalStoreService, IUserDataSyncLogService, IUserDataSyncEnablementService } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSync.service';
|
|
17
|
+
|
|
18
|
+
function parseSnippets(syncData) {
|
|
19
|
+
return JSON.parse(syncData.content);
|
|
20
|
+
}
|
|
21
|
+
let SnippetsSynchroniser = class SnippetsSynchroniser extends AbstractSynchroniser {
|
|
22
|
+
constructor(profile, collection, environmentService, fileService, storageService, userDataSyncStoreService, userDataSyncLocalStoreService, logService, configurationService, userDataSyncEnablementService, telemetryService, uriIdentityService) {
|
|
23
|
+
super({ syncResource: "snippets" , profile }, collection, fileService, environmentService, storageService, userDataSyncStoreService, userDataSyncLocalStoreService, userDataSyncEnablementService, telemetryService, logService, configurationService, uriIdentityService);
|
|
24
|
+
this.version = 1;
|
|
25
|
+
this.snippetsFolder = profile.snippetsHome;
|
|
26
|
+
this._register(this.fileService.watch(environmentService.userRoamingDataHome));
|
|
27
|
+
this._register(this.fileService.watch(this.snippetsFolder));
|
|
28
|
+
this._register(Event.filter(this.fileService.onDidFilesChange, e => e.affects(this.snippetsFolder))(() => this.triggerLocalChange()));
|
|
29
|
+
}
|
|
30
|
+
async generateSyncPreview(remoteUserData, lastSyncUserData, isRemoteDataFromCurrentMachine) {
|
|
31
|
+
const local = await this.getSnippetsFileContents();
|
|
32
|
+
const localSnippets = this.toSnippetsContents(local);
|
|
33
|
+
const remoteSnippets = remoteUserData.syncData ? this.parseSnippets(remoteUserData.syncData) : null;
|
|
34
|
+
lastSyncUserData = lastSyncUserData === null && isRemoteDataFromCurrentMachine ? remoteUserData : lastSyncUserData;
|
|
35
|
+
const lastSyncSnippets = lastSyncUserData && lastSyncUserData.syncData ? this.parseSnippets(lastSyncUserData.syncData) : null;
|
|
36
|
+
if (remoteSnippets) {
|
|
37
|
+
this.logService.trace(`${this.syncResourceLogLabel}: Merging remote snippets with local snippets...`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.logService.trace(`${this.syncResourceLogLabel}: Remote snippets does not exist. Synchronizing snippets for the first time.`);
|
|
41
|
+
}
|
|
42
|
+
const mergeResult = merge(localSnippets, remoteSnippets, lastSyncSnippets);
|
|
43
|
+
return this.getResourcePreviews(mergeResult, local, remoteSnippets || {}, lastSyncSnippets || {});
|
|
44
|
+
}
|
|
45
|
+
async hasRemoteChanged(lastSyncUserData) {
|
|
46
|
+
const lastSyncSnippets = lastSyncUserData.syncData ? this.parseSnippets(lastSyncUserData.syncData) : null;
|
|
47
|
+
if (lastSyncSnippets === null) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const local = await this.getSnippetsFileContents();
|
|
51
|
+
const localSnippets = this.toSnippetsContents(local);
|
|
52
|
+
const mergeResult = merge(localSnippets, lastSyncSnippets, lastSyncSnippets);
|
|
53
|
+
return ( Object.keys(mergeResult.remote.added)).length > 0 || ( Object.keys(mergeResult.remote.updated)).length > 0 || mergeResult.remote.removed.length > 0 || mergeResult.conflicts.length > 0;
|
|
54
|
+
}
|
|
55
|
+
async getMergeResult(resourcePreview, token) {
|
|
56
|
+
return resourcePreview.previewResult;
|
|
57
|
+
}
|
|
58
|
+
async getAcceptResult(resourcePreview, resource, content, token) {
|
|
59
|
+
if (this.extUri.isEqualOrParent(resource, this.syncPreviewFolder.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }))) {
|
|
60
|
+
return {
|
|
61
|
+
content: resourcePreview.fileContent ? ( resourcePreview.fileContent.value.toString()) : null,
|
|
62
|
+
localChange: 0 ,
|
|
63
|
+
remoteChange: resourcePreview.fileContent
|
|
64
|
+
? resourcePreview.remoteContent !== null ? 2 : 1
|
|
65
|
+
: 3
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (this.extUri.isEqualOrParent(resource, this.syncPreviewFolder.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }))) {
|
|
69
|
+
return {
|
|
70
|
+
content: resourcePreview.remoteContent,
|
|
71
|
+
localChange: resourcePreview.remoteContent !== null
|
|
72
|
+
? resourcePreview.fileContent ? 2 : 1
|
|
73
|
+
: 3 ,
|
|
74
|
+
remoteChange: 0 ,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (this.extUri.isEqualOrParent(resource, this.syncPreviewFolder)) {
|
|
78
|
+
if (content === undefined) {
|
|
79
|
+
return {
|
|
80
|
+
content: resourcePreview.previewResult.content,
|
|
81
|
+
localChange: resourcePreview.previewResult.localChange,
|
|
82
|
+
remoteChange: resourcePreview.previewResult.remoteChange,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return {
|
|
87
|
+
content,
|
|
88
|
+
localChange: content === null
|
|
89
|
+
? resourcePreview.fileContent !== null ? 3 : 0
|
|
90
|
+
: 2 ,
|
|
91
|
+
remoteChange: content === null
|
|
92
|
+
? resourcePreview.remoteContent !== null ? 3 : 0
|
|
93
|
+
: 2
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
throw ( new Error(`Invalid Resource: ${( resource.toString())}`));
|
|
98
|
+
}
|
|
99
|
+
async applyResult(remoteUserData, lastSyncUserData, resourcePreviews, force) {
|
|
100
|
+
const accptedResourcePreviews = ( resourcePreviews.map(
|
|
101
|
+
([resourcePreview, acceptResult]) => ({ ...resourcePreview, acceptResult })
|
|
102
|
+
));
|
|
103
|
+
if (accptedResourcePreviews.every(({ localChange, remoteChange }) => localChange === 0 && remoteChange === 0 )) {
|
|
104
|
+
this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing snippets.`);
|
|
105
|
+
}
|
|
106
|
+
if (( accptedResourcePreviews.some(({ localChange }) => localChange !== 0 ))) {
|
|
107
|
+
await this.updateLocalBackup(accptedResourcePreviews);
|
|
108
|
+
await this.updateLocalSnippets(accptedResourcePreviews, force);
|
|
109
|
+
}
|
|
110
|
+
if (( accptedResourcePreviews.some(({ remoteChange }) => remoteChange !== 0 ))) {
|
|
111
|
+
remoteUserData = await this.updateRemoteSnippets(accptedResourcePreviews, remoteUserData, force);
|
|
112
|
+
}
|
|
113
|
+
if (lastSyncUserData?.ref !== remoteUserData.ref) {
|
|
114
|
+
this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized snippets...`);
|
|
115
|
+
await this.updateLastSyncUserData(remoteUserData);
|
|
116
|
+
this.logService.info(`${this.syncResourceLogLabel}: Updated last synchronized snippets`);
|
|
117
|
+
}
|
|
118
|
+
for (const { previewResource } of accptedResourcePreviews) {
|
|
119
|
+
try {
|
|
120
|
+
await this.fileService.del(previewResource);
|
|
121
|
+
}
|
|
122
|
+
catch (e) { }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
getResourcePreviews(snippetsMergeResult, localFileContent, remoteSnippets, baseSnippets) {
|
|
126
|
+
const resourcePreviews = ( new Map());
|
|
127
|
+
for (const key of ( Object.keys(snippetsMergeResult.local.added))) {
|
|
128
|
+
const previewResult = {
|
|
129
|
+
content: snippetsMergeResult.local.added[key],
|
|
130
|
+
hasConflicts: false,
|
|
131
|
+
localChange: 1 ,
|
|
132
|
+
remoteChange: 0 ,
|
|
133
|
+
};
|
|
134
|
+
resourcePreviews.set(key, {
|
|
135
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
136
|
+
baseContent: null,
|
|
137
|
+
fileContent: null,
|
|
138
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
139
|
+
localContent: null,
|
|
140
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
141
|
+
remoteContent: remoteSnippets[key],
|
|
142
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
143
|
+
previewResult,
|
|
144
|
+
localChange: previewResult.localChange,
|
|
145
|
+
remoteChange: previewResult.remoteChange,
|
|
146
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
for (const key of ( Object.keys(snippetsMergeResult.local.updated))) {
|
|
150
|
+
const previewResult = {
|
|
151
|
+
content: snippetsMergeResult.local.updated[key],
|
|
152
|
+
hasConflicts: false,
|
|
153
|
+
localChange: 2 ,
|
|
154
|
+
remoteChange: 0 ,
|
|
155
|
+
};
|
|
156
|
+
const localContent = localFileContent[key] ? ( localFileContent[key].value.toString()) : null;
|
|
157
|
+
resourcePreviews.set(key, {
|
|
158
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
159
|
+
baseContent: baseSnippets[key] ?? null,
|
|
160
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
161
|
+
fileContent: localFileContent[key],
|
|
162
|
+
localContent,
|
|
163
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
164
|
+
remoteContent: remoteSnippets[key],
|
|
165
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
166
|
+
previewResult,
|
|
167
|
+
localChange: previewResult.localChange,
|
|
168
|
+
remoteChange: previewResult.remoteChange,
|
|
169
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
for (const key of snippetsMergeResult.local.removed) {
|
|
173
|
+
const previewResult = {
|
|
174
|
+
content: null,
|
|
175
|
+
hasConflicts: false,
|
|
176
|
+
localChange: 3 ,
|
|
177
|
+
remoteChange: 0 ,
|
|
178
|
+
};
|
|
179
|
+
const localContent = localFileContent[key] ? ( localFileContent[key].value.toString()) : null;
|
|
180
|
+
resourcePreviews.set(key, {
|
|
181
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
182
|
+
baseContent: baseSnippets[key] ?? null,
|
|
183
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
184
|
+
fileContent: localFileContent[key],
|
|
185
|
+
localContent,
|
|
186
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
187
|
+
remoteContent: null,
|
|
188
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
189
|
+
previewResult,
|
|
190
|
+
localChange: previewResult.localChange,
|
|
191
|
+
remoteChange: previewResult.remoteChange,
|
|
192
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
for (const key of ( Object.keys(snippetsMergeResult.remote.added))) {
|
|
196
|
+
const previewResult = {
|
|
197
|
+
content: snippetsMergeResult.remote.added[key],
|
|
198
|
+
hasConflicts: false,
|
|
199
|
+
localChange: 0 ,
|
|
200
|
+
remoteChange: 1 ,
|
|
201
|
+
};
|
|
202
|
+
const localContent = localFileContent[key] ? ( localFileContent[key].value.toString()) : null;
|
|
203
|
+
resourcePreviews.set(key, {
|
|
204
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
205
|
+
baseContent: baseSnippets[key] ?? null,
|
|
206
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
207
|
+
fileContent: localFileContent[key],
|
|
208
|
+
localContent,
|
|
209
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
210
|
+
remoteContent: null,
|
|
211
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
212
|
+
previewResult,
|
|
213
|
+
localChange: previewResult.localChange,
|
|
214
|
+
remoteChange: previewResult.remoteChange,
|
|
215
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
for (const key of ( Object.keys(snippetsMergeResult.remote.updated))) {
|
|
219
|
+
const previewResult = {
|
|
220
|
+
content: snippetsMergeResult.remote.updated[key],
|
|
221
|
+
hasConflicts: false,
|
|
222
|
+
localChange: 0 ,
|
|
223
|
+
remoteChange: 2 ,
|
|
224
|
+
};
|
|
225
|
+
const localContent = localFileContent[key] ? ( localFileContent[key].value.toString()) : null;
|
|
226
|
+
resourcePreviews.set(key, {
|
|
227
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
228
|
+
baseContent: baseSnippets[key] ?? null,
|
|
229
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
230
|
+
fileContent: localFileContent[key],
|
|
231
|
+
localContent,
|
|
232
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
233
|
+
remoteContent: remoteSnippets[key],
|
|
234
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
235
|
+
previewResult,
|
|
236
|
+
localChange: previewResult.localChange,
|
|
237
|
+
remoteChange: previewResult.remoteChange,
|
|
238
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
for (const key of snippetsMergeResult.remote.removed) {
|
|
242
|
+
const previewResult = {
|
|
243
|
+
content: null,
|
|
244
|
+
hasConflicts: false,
|
|
245
|
+
localChange: 0 ,
|
|
246
|
+
remoteChange: 3 ,
|
|
247
|
+
};
|
|
248
|
+
resourcePreviews.set(key, {
|
|
249
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
250
|
+
baseContent: baseSnippets[key] ?? null,
|
|
251
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
252
|
+
fileContent: null,
|
|
253
|
+
localContent: null,
|
|
254
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
255
|
+
remoteContent: remoteSnippets[key],
|
|
256
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
257
|
+
previewResult,
|
|
258
|
+
localChange: previewResult.localChange,
|
|
259
|
+
remoteChange: previewResult.remoteChange,
|
|
260
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
for (const key of snippetsMergeResult.conflicts) {
|
|
264
|
+
const previewResult = {
|
|
265
|
+
content: baseSnippets[key] ?? null,
|
|
266
|
+
hasConflicts: true,
|
|
267
|
+
localChange: localFileContent[key] ? 2 : 1 ,
|
|
268
|
+
remoteChange: remoteSnippets[key] ? 2 : 1
|
|
269
|
+
};
|
|
270
|
+
const localContent = localFileContent[key] ? ( localFileContent[key].value.toString()) : null;
|
|
271
|
+
resourcePreviews.set(key, {
|
|
272
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
273
|
+
baseContent: baseSnippets[key] ?? null,
|
|
274
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
275
|
+
fileContent: localFileContent[key] || null,
|
|
276
|
+
localContent,
|
|
277
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
278
|
+
remoteContent: remoteSnippets[key] || null,
|
|
279
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
280
|
+
previewResult,
|
|
281
|
+
localChange: previewResult.localChange,
|
|
282
|
+
remoteChange: previewResult.remoteChange,
|
|
283
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
for (const key of ( Object.keys(localFileContent))) {
|
|
287
|
+
if (!( resourcePreviews.has(key))) {
|
|
288
|
+
const previewResult = {
|
|
289
|
+
content: localFileContent[key] ? ( localFileContent[key].value.toString()) : null,
|
|
290
|
+
hasConflicts: false,
|
|
291
|
+
localChange: 0 ,
|
|
292
|
+
remoteChange: 0
|
|
293
|
+
};
|
|
294
|
+
const localContent = localFileContent[key] ? ( localFileContent[key].value.toString()) : null;
|
|
295
|
+
resourcePreviews.set(key, {
|
|
296
|
+
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
|
|
297
|
+
baseContent: baseSnippets[key] ?? null,
|
|
298
|
+
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
|
|
299
|
+
fileContent: localFileContent[key] || null,
|
|
300
|
+
localContent,
|
|
301
|
+
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
|
|
302
|
+
remoteContent: remoteSnippets[key] || null,
|
|
303
|
+
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
|
|
304
|
+
previewResult,
|
|
305
|
+
localChange: previewResult.localChange,
|
|
306
|
+
remoteChange: previewResult.remoteChange,
|
|
307
|
+
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return [...( resourcePreviews.values())];
|
|
312
|
+
}
|
|
313
|
+
async resolveContent(uri) {
|
|
314
|
+
if (this.extUri.isEqualOrParent(uri, this.syncPreviewFolder.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }))
|
|
315
|
+
|| this.extUri.isEqualOrParent(uri, this.syncPreviewFolder.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }))
|
|
316
|
+
|| this.extUri.isEqualOrParent(uri, this.syncPreviewFolder.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }))
|
|
317
|
+
|| this.extUri.isEqualOrParent(uri, this.syncPreviewFolder.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' }))) {
|
|
318
|
+
return this.resolvePreviewContent(uri);
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
async hasLocalData() {
|
|
323
|
+
try {
|
|
324
|
+
const localSnippets = await this.getSnippetsFileContents();
|
|
325
|
+
if (( Object.keys(localSnippets)).length) {
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
async updateLocalBackup(resourcePreviews) {
|
|
334
|
+
const local = {};
|
|
335
|
+
for (const resourcePreview of resourcePreviews) {
|
|
336
|
+
if (resourcePreview.fileContent) {
|
|
337
|
+
local[this.extUri.basename(resourcePreview.localResource)] = resourcePreview.fileContent;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
await this.backupLocal(JSON.stringify(this.toSnippetsContents(local)));
|
|
341
|
+
}
|
|
342
|
+
async updateLocalSnippets(resourcePreviews, force) {
|
|
343
|
+
for (const { fileContent, acceptResult, localResource, remoteResource, localChange } of resourcePreviews) {
|
|
344
|
+
if (localChange !== 0 ) {
|
|
345
|
+
const key = remoteResource ? this.extUri.basename(remoteResource) : this.extUri.basename(localResource);
|
|
346
|
+
const resource = this.extUri.joinPath(this.snippetsFolder, key);
|
|
347
|
+
if (localChange === 3 ) {
|
|
348
|
+
this.logService.trace(`${this.syncResourceLogLabel}: Deleting snippet...`, this.extUri.basename(resource));
|
|
349
|
+
await this.fileService.del(resource);
|
|
350
|
+
this.logService.info(`${this.syncResourceLogLabel}: Deleted snippet`, this.extUri.basename(resource));
|
|
351
|
+
}
|
|
352
|
+
else if (localChange === 1 ) {
|
|
353
|
+
this.logService.trace(`${this.syncResourceLogLabel}: Creating snippet...`, this.extUri.basename(resource));
|
|
354
|
+
await this.fileService.createFile(resource, VSBuffer.fromString(acceptResult.content), { overwrite: force });
|
|
355
|
+
this.logService.info(`${this.syncResourceLogLabel}: Created snippet`, this.extUri.basename(resource));
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
this.logService.trace(`${this.syncResourceLogLabel}: Updating snippet...`, this.extUri.basename(resource));
|
|
359
|
+
await this.fileService.writeFile(resource, VSBuffer.fromString(acceptResult.content), force ? undefined : fileContent);
|
|
360
|
+
this.logService.info(`${this.syncResourceLogLabel}: Updated snippet`, this.extUri.basename(resource));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
async updateRemoteSnippets(resourcePreviews, remoteUserData, forcePush) {
|
|
366
|
+
const currentSnippets = remoteUserData.syncData ? this.parseSnippets(remoteUserData.syncData) : {};
|
|
367
|
+
const newSnippets = deepClone(currentSnippets);
|
|
368
|
+
for (const { acceptResult, localResource, remoteResource, remoteChange } of resourcePreviews) {
|
|
369
|
+
if (remoteChange !== 0 ) {
|
|
370
|
+
const key = localResource ? this.extUri.basename(localResource) : this.extUri.basename(remoteResource);
|
|
371
|
+
if (remoteChange === 3 ) {
|
|
372
|
+
delete newSnippets[key];
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
newSnippets[key] = acceptResult.content;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (!areSame(currentSnippets, newSnippets)) {
|
|
380
|
+
this.logService.trace(`${this.syncResourceLogLabel}: Updating remote snippets...`);
|
|
381
|
+
remoteUserData = await this.updateRemoteUserData(JSON.stringify(newSnippets), forcePush ? null : remoteUserData.ref);
|
|
382
|
+
this.logService.info(`${this.syncResourceLogLabel}: Updated remote snippets`);
|
|
383
|
+
}
|
|
384
|
+
return remoteUserData;
|
|
385
|
+
}
|
|
386
|
+
parseSnippets(syncData) {
|
|
387
|
+
return parseSnippets(syncData);
|
|
388
|
+
}
|
|
389
|
+
toSnippetsContents(snippetsFileContents) {
|
|
390
|
+
const snippets = {};
|
|
391
|
+
for (const key of ( Object.keys(snippetsFileContents))) {
|
|
392
|
+
snippets[key] = ( snippetsFileContents[key].value.toString());
|
|
393
|
+
}
|
|
394
|
+
return snippets;
|
|
395
|
+
}
|
|
396
|
+
async getSnippetsFileContents() {
|
|
397
|
+
const snippets = {};
|
|
398
|
+
let stat;
|
|
399
|
+
try {
|
|
400
|
+
stat = await this.fileService.resolve(this.snippetsFolder);
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
if (e instanceof FileOperationError && e.fileOperationResult === 1 ) {
|
|
404
|
+
return snippets;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
throw e;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
for (const entry of stat.children || []) {
|
|
411
|
+
const resource = entry.resource;
|
|
412
|
+
const extension = this.extUri.extname(resource);
|
|
413
|
+
if (extension === '.json' || extension === '.code-snippets') {
|
|
414
|
+
const key = this.extUri.relativePath(this.snippetsFolder, resource);
|
|
415
|
+
const content = await this.fileService.readFile(resource);
|
|
416
|
+
snippets[key] = content;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return snippets;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
SnippetsSynchroniser = ( __decorate([
|
|
423
|
+
( __param(2, IEnvironmentService)),
|
|
424
|
+
( __param(3, IFileService)),
|
|
425
|
+
( __param(4, IStorageService)),
|
|
426
|
+
( __param(5, IUserDataSyncStoreService)),
|
|
427
|
+
( __param(6, IUserDataSyncLocalStoreService)),
|
|
428
|
+
( __param(7, IUserDataSyncLogService)),
|
|
429
|
+
( __param(8, IConfigurationService)),
|
|
430
|
+
( __param(9, IUserDataSyncEnablementService)),
|
|
431
|
+
( __param(10, ITelemetryService)),
|
|
432
|
+
( __param(11, IUriIdentityService))
|
|
433
|
+
], SnippetsSynchroniser));
|
|
434
|
+
let SnippetsInitializer = class SnippetsInitializer extends AbstractInitializer {
|
|
435
|
+
constructor(fileService, userDataProfilesService, environmentService, logService, storageService, uriIdentityService) {
|
|
436
|
+
super("snippets" , userDataProfilesService, environmentService, logService, fileService, storageService, uriIdentityService);
|
|
437
|
+
}
|
|
438
|
+
async doInitialize(remoteUserData) {
|
|
439
|
+
const remoteSnippets = remoteUserData.syncData ? JSON.parse(remoteUserData.syncData.content) : null;
|
|
440
|
+
if (!remoteSnippets) {
|
|
441
|
+
this.logService.info('Skipping initializing snippets because remote snippets does not exist.');
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const isEmpty = await this.isEmpty();
|
|
445
|
+
if (!isEmpty) {
|
|
446
|
+
this.logService.info('Skipping initializing snippets because local snippets exist.');
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
for (const key of ( Object.keys(remoteSnippets))) {
|
|
450
|
+
const content = remoteSnippets[key];
|
|
451
|
+
if (content) {
|
|
452
|
+
const resource = this.extUri.joinPath(this.userDataProfilesService.defaultProfile.snippetsHome, key);
|
|
453
|
+
await this.fileService.createFile(resource, VSBuffer.fromString(content));
|
|
454
|
+
this.logService.info('Created snippet', this.extUri.basename(resource));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
await this.updateLastSyncUserData(remoteUserData);
|
|
458
|
+
}
|
|
459
|
+
async isEmpty() {
|
|
460
|
+
try {
|
|
461
|
+
const stat = await this.fileService.resolve(this.userDataProfilesService.defaultProfile.snippetsHome);
|
|
462
|
+
return !stat.children?.length;
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
return error.fileOperationResult === 1 ;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
SnippetsInitializer = ( __decorate([
|
|
470
|
+
( __param(0, IFileService)),
|
|
471
|
+
( __param(1, IUserDataProfilesService)),
|
|
472
|
+
( __param(2, IEnvironmentService)),
|
|
473
|
+
( __param(3, IUserDataSyncLogService)),
|
|
474
|
+
( __param(4, IStorageService)),
|
|
475
|
+
( __param(5, IUriIdentityService))
|
|
476
|
+
], SnippetsInitializer));
|
|
477
|
+
|
|
478
|
+
export { SnippetsInitializer, SnippetsSynchroniser, parseSnippets };
|