in patched-vscode/src/vs/platform/userDataSync/common/snippetsSync.ts [175:379]
private getResourcePreviews(snippetsMergeResult: ISnippetsMergeResult, localFileContent: IStringDictionary<IFileContent>, remoteSnippets: IStringDictionary<string>, baseSnippets: IStringDictionary<string>): ISnippetsResourcePreview[] {
const resourcePreviews: Map<string, ISnippetsResourcePreview> = new Map<string, ISnippetsResourcePreview>();
/* Snippets added remotely -> add locally */
for (const key of Object.keys(snippetsMergeResult.local.added)) {
const previewResult: IMergeResult = {
content: snippetsMergeResult.local.added[key],
hasConflicts: false,
localChange: Change.Added,
remoteChange: Change.None,
};
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: null,
fileContent: null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
localContent: null,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: remoteSnippets[key],
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
/* Snippets updated remotely -> update locally */
for (const key of Object.keys(snippetsMergeResult.local.updated)) {
const previewResult: IMergeResult = {
content: snippetsMergeResult.local.updated[key],
hasConflicts: false,
localChange: Change.Modified,
remoteChange: Change.None,
};
const localContent = localFileContent[key] ? localFileContent[key].value.toString() : null;
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: baseSnippets[key] ?? null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
fileContent: localFileContent[key],
localContent,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: remoteSnippets[key],
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
/* Snippets removed remotely -> remove locally */
for (const key of snippetsMergeResult.local.removed) {
const previewResult: IMergeResult = {
content: null,
hasConflicts: false,
localChange: Change.Deleted,
remoteChange: Change.None,
};
const localContent = localFileContent[key] ? localFileContent[key].value.toString() : null;
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: baseSnippets[key] ?? null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
fileContent: localFileContent[key],
localContent,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: null,
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
/* Snippets added locally -> add remotely */
for (const key of Object.keys(snippetsMergeResult.remote.added)) {
const previewResult: IMergeResult = {
content: snippetsMergeResult.remote.added[key],
hasConflicts: false,
localChange: Change.None,
remoteChange: Change.Added,
};
const localContent = localFileContent[key] ? localFileContent[key].value.toString() : null;
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: baseSnippets[key] ?? null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
fileContent: localFileContent[key],
localContent,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: null,
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
/* Snippets updated locally -> update remotely */
for (const key of Object.keys(snippetsMergeResult.remote.updated)) {
const previewResult: IMergeResult = {
content: snippetsMergeResult.remote.updated[key],
hasConflicts: false,
localChange: Change.None,
remoteChange: Change.Modified,
};
const localContent = localFileContent[key] ? localFileContent[key].value.toString() : null;
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: baseSnippets[key] ?? null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
fileContent: localFileContent[key],
localContent,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: remoteSnippets[key],
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
/* Snippets removed locally -> remove remotely */
for (const key of snippetsMergeResult.remote.removed) {
const previewResult: IMergeResult = {
content: null,
hasConflicts: false,
localChange: Change.None,
remoteChange: Change.Deleted,
};
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: baseSnippets[key] ?? null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
fileContent: null,
localContent: null,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: remoteSnippets[key],
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
/* Snippets with conflicts */
for (const key of snippetsMergeResult.conflicts) {
const previewResult: IMergeResult = {
content: baseSnippets[key] ?? null,
hasConflicts: true,
localChange: localFileContent[key] ? Change.Modified : Change.Added,
remoteChange: remoteSnippets[key] ? Change.Modified : Change.Added
};
const localContent = localFileContent[key] ? localFileContent[key].value.toString() : null;
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: baseSnippets[key] ?? null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
fileContent: localFileContent[key] || null,
localContent,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: remoteSnippets[key] || null,
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
/* Unmodified Snippets */
for (const key of Object.keys(localFileContent)) {
if (!resourcePreviews.has(key)) {
const previewResult: IMergeResult = {
content: localFileContent[key] ? localFileContent[key].value.toString() : null,
hasConflicts: false,
localChange: Change.None,
remoteChange: Change.None
};
const localContent = localFileContent[key] ? localFileContent[key].value.toString() : null;
resourcePreviews.set(key, {
baseResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'base' }),
baseContent: baseSnippets[key] ?? null,
localResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'local' }),
fileContent: localFileContent[key] || null,
localContent,
remoteResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'remote' }),
remoteContent: remoteSnippets[key] || null,
previewResource: this.extUri.joinPath(this.syncPreviewFolder, key),
previewResult,
localChange: previewResult.localChange,
remoteChange: previewResult.remoteChange,
acceptedResource: this.extUri.joinPath(this.syncPreviewFolder, key).with({ scheme: USER_DATA_SYNC_SCHEME, authority: 'accepted' })
});
}
}
return [...resourcePreviews.values()];
}