@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.
Files changed (33) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/package.json +31 -0
  4. package/userDataProfile.js +118 -0
  5. package/vscode/src/vs/platform/userDataProfile/browser/userDataProfile.js +95 -0
  6. package/vscode/src/vs/platform/userDataProfile/common/userDataProfileStorageService.js +84 -0
  7. package/vscode/src/vs/platform/userDataSync/common/extensionsMerge.js +331 -0
  8. package/vscode/src/vs/platform/userDataSync/common/extensionsSync.js +545 -0
  9. package/vscode/src/vs/platform/userDataSync/common/globalStateMerge.js +102 -0
  10. package/vscode/src/vs/platform/userDataSync/common/globalStateSync.js +431 -0
  11. package/vscode/src/vs/platform/userDataSync/common/keybindingsMerge.js +277 -0
  12. package/vscode/src/vs/platform/userDataSync/common/keybindingsSync.js +328 -0
  13. package/vscode/src/vs/platform/userDataSync/common/settingsSync.js +322 -0
  14. package/vscode/src/vs/platform/userDataSync/common/snippetsMerge.js +126 -0
  15. package/vscode/src/vs/platform/userDataSync/common/snippetsSync.js +478 -0
  16. package/vscode/src/vs/platform/userDataSync/common/tasksSync.js +245 -0
  17. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.contribution.js +9 -0
  18. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.js +495 -0
  19. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfileActions.js +159 -0
  20. package/vscode/src/vs/workbench/contrib/userDataProfile/browser/userDataProfilePreview.js +24 -0
  21. package/vscode/src/vs/workbench/services/userData/browser/userDataInit.js +62 -0
  22. package/vscode/src/vs/workbench/services/userDataProfile/browser/extensionsResource.js +328 -0
  23. package/vscode/src/vs/workbench/services/userDataProfile/browser/globalStateResource.js +144 -0
  24. package/vscode/src/vs/workbench/services/userDataProfile/browser/keybindingsResource.js +119 -0
  25. package/vscode/src/vs/workbench/services/userDataProfile/browser/media/userDataProfileView.css.js +6 -0
  26. package/vscode/src/vs/workbench/services/userDataProfile/browser/settingsResource.js +140 -0
  27. package/vscode/src/vs/workbench/services/userDataProfile/browser/snippetsResource.js +155 -0
  28. package/vscode/src/vs/workbench/services/userDataProfile/browser/tasksResource.js +118 -0
  29. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.js +1453 -0
  30. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileInit.js +151 -0
  31. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileManagement.js +180 -0
  32. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileStorageService.js +39 -0
  33. package/vscode/src/vs/workbench/services/userDataSync/browser/userDataSyncInit.js +448 -0
@@ -0,0 +1,277 @@
1
+ import { equals } from 'vscode/vscode/vs/base/common/arrays';
2
+ import { parse } from 'vscode/vscode/vs/base/common/json';
3
+ import { equals as equals$1 } from 'vscode/vscode/vs/base/common/objects';
4
+ import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
5
+ import { edit } from 'vscode/vscode/vs/platform/userDataSync/common/content';
6
+
7
+ function parseKeybindings(content) {
8
+ return parse(content) || [];
9
+ }
10
+ async function merge(localContent, remoteContent, baseContent, formattingOptions, userDataSyncUtilService) {
11
+ const local = parseKeybindings(localContent);
12
+ const remote = parseKeybindings(remoteContent);
13
+ const base = baseContent ? parseKeybindings(baseContent) : null;
14
+ const userbindings = ( [...local, ...remote, ...(base || [])].map(keybinding => keybinding.key));
15
+ const normalizedKeys = await userDataSyncUtilService.resolveUserBindings(userbindings);
16
+ const keybindingsMergeResult = computeMergeResultByKeybinding(local, remote, base, normalizedKeys);
17
+ if (!keybindingsMergeResult.hasLocalForwarded && !keybindingsMergeResult.hasRemoteForwarded) {
18
+ return { mergeContent: localContent, hasChanges: false, hasConflicts: false };
19
+ }
20
+ if (!keybindingsMergeResult.hasLocalForwarded && keybindingsMergeResult.hasRemoteForwarded) {
21
+ return { mergeContent: remoteContent, hasChanges: true, hasConflicts: false };
22
+ }
23
+ if (keybindingsMergeResult.hasLocalForwarded && !keybindingsMergeResult.hasRemoteForwarded) {
24
+ return { mergeContent: localContent, hasChanges: true, hasConflicts: false };
25
+ }
26
+ const localByCommand = byCommand(local);
27
+ const remoteByCommand = byCommand(remote);
28
+ const baseByCommand = base ? byCommand(base) : null;
29
+ const localToRemoteByCommand = compareByCommand(localByCommand, remoteByCommand, normalizedKeys);
30
+ const baseToLocalByCommand = baseByCommand ? compareByCommand(baseByCommand, localByCommand, normalizedKeys) : { added: [...( localByCommand.keys())].reduce((r, k) => { r.add(k); return r; }, ( new Set())), removed: ( new Set()), updated: ( new Set()) };
31
+ const baseToRemoteByCommand = baseByCommand ? compareByCommand(baseByCommand, remoteByCommand, normalizedKeys) : { added: [...( remoteByCommand.keys())].reduce((r, k) => { r.add(k); return r; }, ( new Set())), removed: ( new Set()), updated: ( new Set()) };
32
+ const commandsMergeResult = computeMergeResult(localToRemoteByCommand, baseToLocalByCommand, baseToRemoteByCommand);
33
+ let mergeContent = localContent;
34
+ for (const command of ( commandsMergeResult.removed.values())) {
35
+ if (( commandsMergeResult.conflicts.has(command))) {
36
+ continue;
37
+ }
38
+ mergeContent = removeKeybindings(mergeContent, command, formattingOptions);
39
+ }
40
+ for (const command of ( commandsMergeResult.added.values())) {
41
+ if (( commandsMergeResult.conflicts.has(command))) {
42
+ continue;
43
+ }
44
+ const keybindings = remoteByCommand.get(command);
45
+ if (( keybindings.some(keybinding => keybinding.command !== `-${command}` && ( keybindingsMergeResult.conflicts.has(normalizedKeys[keybinding.key]))))) {
46
+ commandsMergeResult.conflicts.add(command);
47
+ continue;
48
+ }
49
+ mergeContent = addKeybindings(mergeContent, keybindings, formattingOptions);
50
+ }
51
+ for (const command of ( commandsMergeResult.updated.values())) {
52
+ if (( commandsMergeResult.conflicts.has(command))) {
53
+ continue;
54
+ }
55
+ const keybindings = remoteByCommand.get(command);
56
+ if (( keybindings.some(keybinding => keybinding.command !== `-${command}` && ( keybindingsMergeResult.conflicts.has(normalizedKeys[keybinding.key]))))) {
57
+ commandsMergeResult.conflicts.add(command);
58
+ continue;
59
+ }
60
+ mergeContent = updateKeybindings(mergeContent, command, keybindings, formattingOptions);
61
+ }
62
+ return { mergeContent, hasChanges: true, hasConflicts: commandsMergeResult.conflicts.size > 0 };
63
+ }
64
+ function computeMergeResult(localToRemote, baseToLocal, baseToRemote) {
65
+ const added = ( new Set());
66
+ const removed = ( new Set());
67
+ const updated = ( new Set());
68
+ const conflicts = ( new Set());
69
+ for (const key of ( baseToLocal.removed.values())) {
70
+ if (( baseToRemote.updated.has(key))) {
71
+ conflicts.add(key);
72
+ }
73
+ }
74
+ for (const key of ( baseToRemote.removed.values())) {
75
+ if (( conflicts.has(key))) {
76
+ continue;
77
+ }
78
+ if (( baseToLocal.updated.has(key))) {
79
+ conflicts.add(key);
80
+ }
81
+ else {
82
+ removed.add(key);
83
+ }
84
+ }
85
+ for (const key of ( baseToLocal.added.values())) {
86
+ if (( conflicts.has(key))) {
87
+ continue;
88
+ }
89
+ if (( baseToRemote.added.has(key))) {
90
+ if (( localToRemote.updated.has(key))) {
91
+ conflicts.add(key);
92
+ }
93
+ }
94
+ }
95
+ for (const key of ( baseToRemote.added.values())) {
96
+ if (( conflicts.has(key))) {
97
+ continue;
98
+ }
99
+ if (( baseToLocal.added.has(key))) {
100
+ if (( localToRemote.updated.has(key))) {
101
+ conflicts.add(key);
102
+ }
103
+ }
104
+ else {
105
+ added.add(key);
106
+ }
107
+ }
108
+ for (const key of ( baseToLocal.updated.values())) {
109
+ if (( conflicts.has(key))) {
110
+ continue;
111
+ }
112
+ if (( baseToRemote.updated.has(key))) {
113
+ if (( localToRemote.updated.has(key))) {
114
+ conflicts.add(key);
115
+ }
116
+ }
117
+ }
118
+ for (const key of ( baseToRemote.updated.values())) {
119
+ if (( conflicts.has(key))) {
120
+ continue;
121
+ }
122
+ if (( baseToLocal.updated.has(key))) {
123
+ if (( localToRemote.updated.has(key))) {
124
+ conflicts.add(key);
125
+ }
126
+ }
127
+ else {
128
+ updated.add(key);
129
+ }
130
+ }
131
+ return { added, removed, updated, conflicts };
132
+ }
133
+ function computeMergeResultByKeybinding(local, remote, base, normalizedKeys) {
134
+ const empty = ( new Set());
135
+ const localByKeybinding = byKeybinding(local, normalizedKeys);
136
+ const remoteByKeybinding = byKeybinding(remote, normalizedKeys);
137
+ const baseByKeybinding = base ? byKeybinding(base, normalizedKeys) : null;
138
+ const localToRemoteByKeybinding = compareByKeybinding(localByKeybinding, remoteByKeybinding);
139
+ if (localToRemoteByKeybinding.added.size === 0 && localToRemoteByKeybinding.removed.size === 0 && localToRemoteByKeybinding.updated.size === 0) {
140
+ return { hasLocalForwarded: false, hasRemoteForwarded: false, added: empty, removed: empty, updated: empty, conflicts: empty };
141
+ }
142
+ const baseToLocalByKeybinding = baseByKeybinding ? compareByKeybinding(baseByKeybinding, localByKeybinding) : { added: [...( localByKeybinding.keys())].reduce((r, k) => { r.add(k); return r; }, ( new Set())), removed: ( new Set()), updated: ( new Set()) };
143
+ if (baseToLocalByKeybinding.added.size === 0 && baseToLocalByKeybinding.removed.size === 0 && baseToLocalByKeybinding.updated.size === 0) {
144
+ return { hasLocalForwarded: false, hasRemoteForwarded: true, added: empty, removed: empty, updated: empty, conflicts: empty };
145
+ }
146
+ const baseToRemoteByKeybinding = baseByKeybinding ? compareByKeybinding(baseByKeybinding, remoteByKeybinding) : { added: [...( remoteByKeybinding.keys())].reduce((r, k) => { r.add(k); return r; }, ( new Set())), removed: ( new Set()), updated: ( new Set()) };
147
+ if (baseToRemoteByKeybinding.added.size === 0 && baseToRemoteByKeybinding.removed.size === 0 && baseToRemoteByKeybinding.updated.size === 0) {
148
+ return { hasLocalForwarded: true, hasRemoteForwarded: false, added: empty, removed: empty, updated: empty, conflicts: empty };
149
+ }
150
+ const { added, removed, updated, conflicts } = computeMergeResult(localToRemoteByKeybinding, baseToLocalByKeybinding, baseToRemoteByKeybinding);
151
+ return { hasLocalForwarded: true, hasRemoteForwarded: true, added, removed, updated, conflicts };
152
+ }
153
+ function byKeybinding(keybindings, keys) {
154
+ const map = ( new Map());
155
+ for (const keybinding of keybindings) {
156
+ const key = keys[keybinding.key];
157
+ let value = map.get(key);
158
+ if (!value) {
159
+ value = [];
160
+ map.set(key, value);
161
+ }
162
+ value.push(keybinding);
163
+ }
164
+ return map;
165
+ }
166
+ function byCommand(keybindings) {
167
+ const map = ( new Map());
168
+ for (const keybinding of keybindings) {
169
+ const command = keybinding.command[0] === '-' ? keybinding.command.substring(1) : keybinding.command;
170
+ let value = map.get(command);
171
+ if (!value) {
172
+ value = [];
173
+ map.set(command, value);
174
+ }
175
+ value.push(keybinding);
176
+ }
177
+ return map;
178
+ }
179
+ function compareByKeybinding(from, to) {
180
+ const fromKeys = [...( from.keys())];
181
+ const toKeys = [...( to.keys())];
182
+ const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, ( new Set()));
183
+ const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, ( new Set()));
184
+ const updated = ( new Set());
185
+ for (const key of fromKeys) {
186
+ if (( removed.has(key))) {
187
+ continue;
188
+ }
189
+ const value1 = ( from.get(key).map(keybinding => ({ ...keybinding, ...{ key } })));
190
+ const value2 = ( to.get(key).map(keybinding => ({ ...keybinding, ...{ key } })));
191
+ if (!equals(value1, value2, (a, b) => isSameKeybinding(a, b))) {
192
+ updated.add(key);
193
+ }
194
+ }
195
+ return { added, removed, updated };
196
+ }
197
+ function compareByCommand(from, to, normalizedKeys) {
198
+ const fromKeys = [...( from.keys())];
199
+ const toKeys = [...( to.keys())];
200
+ const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, ( new Set()));
201
+ const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, ( new Set()));
202
+ const updated = ( new Set());
203
+ for (const key of fromKeys) {
204
+ if (( removed.has(key))) {
205
+ continue;
206
+ }
207
+ const value1 = ( from.get(key).map(
208
+ keybinding => ({ ...keybinding, ...{ key: normalizedKeys[keybinding.key] } })
209
+ ));
210
+ const value2 = ( to.get(key).map(
211
+ keybinding => ({ ...keybinding, ...{ key: normalizedKeys[keybinding.key] } })
212
+ ));
213
+ if (!areSameKeybindingsWithSameCommand(value1, value2)) {
214
+ updated.add(key);
215
+ }
216
+ }
217
+ return { added, removed, updated };
218
+ }
219
+ function areSameKeybindingsWithSameCommand(value1, value2) {
220
+ if (!equals(value1.filter(({ command }) => command[0] !== '-'), value2.filter(({ command }) => command[0] !== '-'), (a, b) => isSameKeybinding(a, b))) {
221
+ return false;
222
+ }
223
+ if (!equals(value1.filter(({ command }) => command[0] === '-'), value2.filter(({ command }) => command[0] === '-'), (a, b) => isSameKeybinding(a, b))) {
224
+ return false;
225
+ }
226
+ return true;
227
+ }
228
+ function isSameKeybinding(a, b) {
229
+ if (a.command !== b.command) {
230
+ return false;
231
+ }
232
+ if (a.key !== b.key) {
233
+ return false;
234
+ }
235
+ const whenA = ContextKeyExpr.deserialize(a.when);
236
+ const whenB = ContextKeyExpr.deserialize(b.when);
237
+ if ((whenA && !whenB) || (!whenA && whenB)) {
238
+ return false;
239
+ }
240
+ if (whenA && whenB && !whenA.equals(whenB)) {
241
+ return false;
242
+ }
243
+ if (!equals$1(a.args, b.args)) {
244
+ return false;
245
+ }
246
+ return true;
247
+ }
248
+ function addKeybindings(content, keybindings, formattingOptions) {
249
+ for (const keybinding of keybindings) {
250
+ content = edit(content, [-1], keybinding, formattingOptions);
251
+ }
252
+ return content;
253
+ }
254
+ function removeKeybindings(content, command, formattingOptions) {
255
+ const keybindings = parseKeybindings(content);
256
+ for (let index = keybindings.length - 1; index >= 0; index--) {
257
+ if (keybindings[index].command === command || keybindings[index].command === `-${command}`) {
258
+ content = edit(content, [index], undefined, formattingOptions);
259
+ }
260
+ }
261
+ return content;
262
+ }
263
+ function updateKeybindings(content, command, keybindings, formattingOptions) {
264
+ const allKeybindings = parseKeybindings(content);
265
+ const location = allKeybindings.findIndex(keybinding => keybinding.command === command || keybinding.command === `-${command}`);
266
+ for (let index = allKeybindings.length - 1; index >= 0; index--) {
267
+ if (allKeybindings[index].command === command || allKeybindings[index].command === `-${command}`) {
268
+ content = edit(content, [index], undefined, formattingOptions);
269
+ }
270
+ }
271
+ for (let index = keybindings.length - 1; index >= 0; index--) {
272
+ content = edit(content, [location], keybindings[index], formattingOptions);
273
+ }
274
+ return content;
275
+ }
276
+
277
+ export { merge };
@@ -0,0 +1,328 @@
1
+ import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
2
+ import { isNonEmptyArray } from 'vscode/vscode/vs/base/common/arrays';
3
+ import { VSBuffer } from 'vscode/vscode/vs/base/common/buffer';
4
+ import { Event } from 'vscode/vscode/vs/base/common/event';
5
+ import { parse } from 'vscode/vscode/vs/base/common/json';
6
+ import { OS } from 'vscode/vscode/vs/base/common/platform';
7
+ import { isUndefined } from 'vscode/vscode/vs/base/common/types';
8
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
9
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
10
+ import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment.service';
11
+ import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
12
+ import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
13
+ import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
14
+ import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity.service';
15
+ import { IUserDataProfilesService } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfile.service';
16
+ import { AbstractJsonFileSynchroniser, AbstractInitializer } from 'vscode/vscode/vs/platform/userDataSync/common/abstractSynchronizer';
17
+ import { merge } from './keybindingsMerge.js';
18
+ import { USER_DATA_SYNC_SCHEME, UserDataSyncError, CONFIG_SYNC_KEYBINDINGS_PER_PLATFORM } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSync';
19
+ import { IUserDataSyncStoreService, IUserDataSyncLocalStoreService, IUserDataSyncLogService, IUserDataSyncEnablementService, IUserDataSyncUtilService } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSync.service';
20
+
21
+ const _moduleId = "vs/platform/userDataSync/common/keybindingsSync";
22
+ function getKeybindingsContentFromSyncContent(syncContent, platformSpecific, logService) {
23
+ try {
24
+ const parsed = JSON.parse(syncContent);
25
+ if (!platformSpecific) {
26
+ return isUndefined(parsed.all) ? null : parsed.all;
27
+ }
28
+ switch (OS) {
29
+ case 2 :
30
+ return isUndefined(parsed.mac) ? null : parsed.mac;
31
+ case 3 :
32
+ return isUndefined(parsed.linux) ? null : parsed.linux;
33
+ case 1 :
34
+ return isUndefined(parsed.windows) ? null : parsed.windows;
35
+ }
36
+ }
37
+ catch (e) {
38
+ logService.error(e);
39
+ return null;
40
+ }
41
+ }
42
+ let KeybindingsSynchroniser = class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser {
43
+ constructor(profile, collection, userDataSyncStoreService, userDataSyncLocalStoreService, logService, configurationService, userDataSyncEnablementService, fileService, environmentService, storageService, userDataSyncUtilService, telemetryService, uriIdentityService) {
44
+ super(profile.keybindingsResource, { syncResource: "keybindings" , profile }, collection, fileService, environmentService, storageService, userDataSyncStoreService, userDataSyncLocalStoreService, userDataSyncEnablementService, telemetryService, logService, userDataSyncUtilService, configurationService, uriIdentityService);
45
+ this.version = 2;
46
+ this.previewResource = this.extUri.joinPath(this.syncPreviewFolder, 'keybindings.json');
47
+ this.baseResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' });
48
+ this.localResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' });
49
+ this.remoteResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' });
50
+ this.acceptedResource = this.previewResource.with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' });
51
+ this._register(Event.filter(configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('settingsSync.keybindingsPerPlatform'))(() => this.triggerLocalChange()));
52
+ }
53
+ async generateSyncPreview(remoteUserData, lastSyncUserData, isRemoteDataFromCurrentMachine, userDataSyncConfiguration) {
54
+ const remoteContent = remoteUserData.syncData ? getKeybindingsContentFromSyncContent(remoteUserData.syncData.content, userDataSyncConfiguration.keybindingsPerPlatform ?? this.syncKeybindingsPerPlatform(), this.logService) : null;
55
+ lastSyncUserData = lastSyncUserData === null && isRemoteDataFromCurrentMachine ? remoteUserData : lastSyncUserData;
56
+ const lastSyncContent = lastSyncUserData ? this.getKeybindingsContentFromLastSyncUserData(lastSyncUserData) : null;
57
+ const fileContent = await this.getLocalFileContent();
58
+ const formattingOptions = await this.getFormattingOptions();
59
+ let mergedContent = null;
60
+ let hasLocalChanged = false;
61
+ let hasRemoteChanged = false;
62
+ let hasConflicts = false;
63
+ if (remoteContent) {
64
+ let localContent = fileContent ? ( fileContent.value.toString()) : '[]';
65
+ localContent = localContent || '[]';
66
+ if (this.hasErrors(localContent, true)) {
67
+ throw ( new UserDataSyncError(localizeWithPath(
68
+ _moduleId,
69
+ 0,
70
+ "Unable to sync keybindings because the content in the file is not valid. Please open the file and correct it."
71
+ ), "LocalInvalidContent" , this.resource));
72
+ }
73
+ if (!lastSyncContent
74
+ || lastSyncContent !== localContent
75
+ || lastSyncContent !== remoteContent
76
+ ) {
77
+ this.logService.trace(`${this.syncResourceLogLabel}: Merging remote keybindings with local keybindings...`);
78
+ const result = await merge(localContent, remoteContent, lastSyncContent, formattingOptions, this.userDataSyncUtilService);
79
+ if (result.hasChanges) {
80
+ mergedContent = result.mergeContent;
81
+ hasConflicts = result.hasConflicts;
82
+ hasLocalChanged = hasConflicts || result.mergeContent !== localContent;
83
+ hasRemoteChanged = hasConflicts || result.mergeContent !== remoteContent;
84
+ }
85
+ }
86
+ }
87
+ else if (fileContent) {
88
+ this.logService.trace(`${this.syncResourceLogLabel}: Remote keybindings does not exist. Synchronizing keybindings for the first time.`);
89
+ mergedContent = ( fileContent.value.toString());
90
+ hasRemoteChanged = true;
91
+ }
92
+ const previewResult = {
93
+ content: hasConflicts ? lastSyncContent : mergedContent,
94
+ localChange: hasLocalChanged ? fileContent ? 2 : 1 : 0 ,
95
+ remoteChange: hasRemoteChanged ? 2 : 0 ,
96
+ hasConflicts
97
+ };
98
+ const localContent = fileContent ? ( fileContent.value.toString()) : null;
99
+ return [{
100
+ fileContent,
101
+ baseResource: this.baseResource,
102
+ baseContent: lastSyncContent,
103
+ localResource: this.localResource,
104
+ localContent,
105
+ localChange: previewResult.localChange,
106
+ remoteResource: this.remoteResource,
107
+ remoteContent,
108
+ remoteChange: previewResult.remoteChange,
109
+ previewResource: this.previewResource,
110
+ previewResult,
111
+ acceptedResource: this.acceptedResource,
112
+ }];
113
+ }
114
+ async hasRemoteChanged(lastSyncUserData) {
115
+ const lastSyncContent = this.getKeybindingsContentFromLastSyncUserData(lastSyncUserData);
116
+ if (lastSyncContent === null) {
117
+ return true;
118
+ }
119
+ const fileContent = await this.getLocalFileContent();
120
+ const localContent = fileContent ? ( fileContent.value.toString()) : '';
121
+ const formattingOptions = await this.getFormattingOptions();
122
+ const result = await merge(localContent || '[]', lastSyncContent, lastSyncContent, formattingOptions, this.userDataSyncUtilService);
123
+ return result.hasConflicts || result.mergeContent !== lastSyncContent;
124
+ }
125
+ async getMergeResult(resourcePreview, token) {
126
+ return resourcePreview.previewResult;
127
+ }
128
+ async getAcceptResult(resourcePreview, resource, content, token) {
129
+ if (this.extUri.isEqual(resource, this.localResource)) {
130
+ return {
131
+ content: resourcePreview.fileContent ? ( resourcePreview.fileContent.value.toString()) : null,
132
+ localChange: 0 ,
133
+ remoteChange: 2 ,
134
+ };
135
+ }
136
+ if (this.extUri.isEqual(resource, this.remoteResource)) {
137
+ return {
138
+ content: resourcePreview.remoteContent,
139
+ localChange: 2 ,
140
+ remoteChange: 0 ,
141
+ };
142
+ }
143
+ if (this.extUri.isEqual(resource, this.previewResource)) {
144
+ if (content === undefined) {
145
+ return {
146
+ content: resourcePreview.previewResult.content,
147
+ localChange: resourcePreview.previewResult.localChange,
148
+ remoteChange: resourcePreview.previewResult.remoteChange,
149
+ };
150
+ }
151
+ else {
152
+ return {
153
+ content,
154
+ localChange: 2 ,
155
+ remoteChange: 2 ,
156
+ };
157
+ }
158
+ }
159
+ throw ( new Error(`Invalid Resource: ${( resource.toString())}`));
160
+ }
161
+ async applyResult(remoteUserData, lastSyncUserData, resourcePreviews, force) {
162
+ const { fileContent } = resourcePreviews[0][0];
163
+ let { content, localChange, remoteChange } = resourcePreviews[0][1];
164
+ if (localChange === 0 && remoteChange === 0 ) {
165
+ this.logService.info(`${this.syncResourceLogLabel}: No changes found during synchronizing keybindings.`);
166
+ }
167
+ if (content !== null) {
168
+ content = content.trim();
169
+ content = content || '[]';
170
+ if (this.hasErrors(content, true)) {
171
+ throw ( new UserDataSyncError(localizeWithPath(
172
+ _moduleId,
173
+ 0,
174
+ "Unable to sync keybindings because the content in the file is not valid. Please open the file and correct it."
175
+ ), "LocalInvalidContent" , this.resource));
176
+ }
177
+ }
178
+ if (localChange !== 0 ) {
179
+ this.logService.trace(`${this.syncResourceLogLabel}: Updating local keybindings...`);
180
+ if (fileContent) {
181
+ await this.backupLocal(this.toSyncContent(( fileContent.value.toString())));
182
+ }
183
+ await this.updateLocalFileContent(content || '[]', fileContent, force);
184
+ this.logService.info(`${this.syncResourceLogLabel}: Updated local keybindings`);
185
+ }
186
+ if (remoteChange !== 0 ) {
187
+ this.logService.trace(`${this.syncResourceLogLabel}: Updating remote keybindings...`);
188
+ const remoteContents = this.toSyncContent(content || '[]', remoteUserData.syncData?.content);
189
+ remoteUserData = await this.updateRemoteUserData(remoteContents, force ? null : remoteUserData.ref);
190
+ this.logService.info(`${this.syncResourceLogLabel}: Updated remote keybindings`);
191
+ }
192
+ try {
193
+ await this.fileService.del(this.previewResource);
194
+ }
195
+ catch (e) { }
196
+ if (lastSyncUserData?.ref !== remoteUserData.ref) {
197
+ this.logService.trace(`${this.syncResourceLogLabel}: Updating last synchronized keybindings...`);
198
+ await this.updateLastSyncUserData(remoteUserData, { platformSpecific: this.syncKeybindingsPerPlatform() });
199
+ this.logService.info(`${this.syncResourceLogLabel}: Updated last synchronized keybindings`);
200
+ }
201
+ }
202
+ async hasLocalData() {
203
+ try {
204
+ const localFileContent = await this.getLocalFileContent();
205
+ if (localFileContent) {
206
+ const keybindings = parse(( localFileContent.value.toString()));
207
+ if (isNonEmptyArray(keybindings)) {
208
+ return true;
209
+ }
210
+ }
211
+ }
212
+ catch (error) {
213
+ if (error.fileOperationResult !== 1 ) {
214
+ return true;
215
+ }
216
+ }
217
+ return false;
218
+ }
219
+ async resolveContent(uri) {
220
+ if (this.extUri.isEqual(this.remoteResource, uri)
221
+ || this.extUri.isEqual(this.baseResource, uri)
222
+ || this.extUri.isEqual(this.localResource, uri)
223
+ || this.extUri.isEqual(this.acceptedResource, uri)) {
224
+ return this.resolvePreviewContent(uri);
225
+ }
226
+ return null;
227
+ }
228
+ getKeybindingsContentFromLastSyncUserData(lastSyncUserData) {
229
+ if (!lastSyncUserData.syncData) {
230
+ return null;
231
+ }
232
+ if (lastSyncUserData.platformSpecific !== undefined && lastSyncUserData.platformSpecific !== this.syncKeybindingsPerPlatform()) {
233
+ return null;
234
+ }
235
+ return getKeybindingsContentFromSyncContent(lastSyncUserData.syncData.content, this.syncKeybindingsPerPlatform(), this.logService);
236
+ }
237
+ toSyncContent(keybindingsContent, syncContent) {
238
+ let parsed = {};
239
+ try {
240
+ parsed = JSON.parse(syncContent || '{}');
241
+ }
242
+ catch (e) {
243
+ this.logService.error(e);
244
+ }
245
+ if (this.syncKeybindingsPerPlatform()) {
246
+ delete parsed.all;
247
+ }
248
+ else {
249
+ parsed.all = keybindingsContent;
250
+ }
251
+ switch (OS) {
252
+ case 2 :
253
+ parsed.mac = keybindingsContent;
254
+ break;
255
+ case 3 :
256
+ parsed.linux = keybindingsContent;
257
+ break;
258
+ case 1 :
259
+ parsed.windows = keybindingsContent;
260
+ break;
261
+ }
262
+ return JSON.stringify(parsed);
263
+ }
264
+ syncKeybindingsPerPlatform() {
265
+ return !!this.configurationService.getValue(CONFIG_SYNC_KEYBINDINGS_PER_PLATFORM);
266
+ }
267
+ };
268
+ KeybindingsSynchroniser = ( __decorate([
269
+ ( __param(2, IUserDataSyncStoreService)),
270
+ ( __param(3, IUserDataSyncLocalStoreService)),
271
+ ( __param(4, IUserDataSyncLogService)),
272
+ ( __param(5, IConfigurationService)),
273
+ ( __param(6, IUserDataSyncEnablementService)),
274
+ ( __param(7, IFileService)),
275
+ ( __param(8, IEnvironmentService)),
276
+ ( __param(9, IStorageService)),
277
+ ( __param(10, IUserDataSyncUtilService)),
278
+ ( __param(11, ITelemetryService)),
279
+ ( __param(12, IUriIdentityService))
280
+ ], KeybindingsSynchroniser));
281
+ let KeybindingsInitializer = class KeybindingsInitializer extends AbstractInitializer {
282
+ constructor(fileService, userDataProfilesService, environmentService, logService, storageService, uriIdentityService) {
283
+ super("keybindings" , userDataProfilesService, environmentService, logService, fileService, storageService, uriIdentityService);
284
+ }
285
+ async doInitialize(remoteUserData) {
286
+ const keybindingsContent = remoteUserData.syncData ? this.getKeybindingsContentFromSyncContent(remoteUserData.syncData.content) : null;
287
+ if (!keybindingsContent) {
288
+ this.logService.info('Skipping initializing keybindings because remote keybindings does not exist.');
289
+ return;
290
+ }
291
+ const isEmpty = await this.isEmpty();
292
+ if (!isEmpty) {
293
+ this.logService.info('Skipping initializing keybindings because local keybindings exist.');
294
+ return;
295
+ }
296
+ await this.fileService.writeFile(this.userDataProfilesService.defaultProfile.keybindingsResource, VSBuffer.fromString(keybindingsContent));
297
+ await this.updateLastSyncUserData(remoteUserData);
298
+ }
299
+ async isEmpty() {
300
+ try {
301
+ const fileContent = await this.fileService.readFile(this.userDataProfilesService.defaultProfile.settingsResource);
302
+ const keybindings = parse(( fileContent.value.toString()));
303
+ return !isNonEmptyArray(keybindings);
304
+ }
305
+ catch (error) {
306
+ return error.fileOperationResult === 1 ;
307
+ }
308
+ }
309
+ getKeybindingsContentFromSyncContent(syncContent) {
310
+ try {
311
+ return getKeybindingsContentFromSyncContent(syncContent, true, this.logService);
312
+ }
313
+ catch (e) {
314
+ this.logService.error(e);
315
+ return null;
316
+ }
317
+ }
318
+ };
319
+ KeybindingsInitializer = ( __decorate([
320
+ ( __param(0, IFileService)),
321
+ ( __param(1, IUserDataProfilesService)),
322
+ ( __param(2, IEnvironmentService)),
323
+ ( __param(3, IUserDataSyncLogService)),
324
+ ( __param(4, IStorageService)),
325
+ ( __param(5, IUriIdentityService))
326
+ ], KeybindingsInitializer));
327
+
328
+ export { KeybindingsInitializer, KeybindingsSynchroniser, getKeybindingsContentFromSyncContent };