src/vs/platform/userDataSync/common/snippetsMerge.ts
177 LOC · 167 covered · 10 uncovered · 58 ranges · 621 concepts · 31 introducers · 369 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
snippetsMerge.ts ×3
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IStringDictionary } from '../../../base/common/collections.js';
export interface IMergeResult {
local: {
added: IStringDictionary<string>;
updated: IStringDictionary<string>;
removed: string[];
};
remote: {
added: IStringDictionary<string>;
updated: IStringDictionary<string>;
removed: string[];
};
conflicts: string[];
}
export function merge(local: IStringDictionary<string>, remote: IStringDictionary<string> | null, base: IStringDictionary<string> | null): IMergeResult {
const localUpdated: IStringDictionary<string> = {};
const localRemoved: Set<string> = new Set<string>();
if (!remote) {
local: { added: localAdded, updated: localUpdated, removed: [...localRemoved.values()] },
remote: { added: local, updated: {}, removed: [] },
conflicts: []
};
}
const localToRemote = compare(local, remote);
if (localToRemote.added.size === 0 && localToRemote.removed.size === 0 && localToRemote.updated.size === 0) {
snippetsMerge.ts ×2
return {
local: { added: localAdded, updated: localUpdated, removed: [...localRemoved.values()] },
remote: { added: {}, updated: {}, removed: [] },
conflicts: []
};
}
const baseToLocal = compare(base, local);
const baseToRemote = compare(base, remote);
const remoteAdded: IStringDictionary<string> = {};
const remoteUpdated: IStringDictionary<string> = {};
const remoteRemoved: Set<string> = new Set<string>();
const conflicts: Set<string> = new Set<string>();
// Removed snippets in Local
for (const key of baseToLocal.removed.values()) {
if (baseToRemote.updated.has(key)) {
localAdded[key] = remote[key];
}
else {
remoteRemoved.add(key);
}
// Removed snippets in Remote
for (const key of baseToRemote.removed.values()) {
continue;
}
if (baseToLocal.updated.has(key)) {
}
else {
localRemoved.add(key);
}
// Updated snippets in Local
for (const key of baseToLocal.updated.values()) {
}
if (baseToRemote.updated.has(key)) {
if (localToRemote.updated.has(key)) {
conflicts.add(key);
}
remoteUpdated[key] = local[key];
}
// Updated snippets in Remote
for (const key of baseToRemote.updated.values()) {
}
if (baseToLocal.updated.has(key)) {
// Has different value
if (localToRemote.updated.has(key)) {
conflicts.add(key);
}
}
// Added snippets in Local
for (const key of baseToLocal.added.values()) {
continue;
}
if (baseToRemote.added.has(key)) {
if (localToRemote.updated.has(key)) {
}
}
// Added snippets in remote
for (const key of baseToRemote.added.values()) {
}
if (baseToLocal.added.has(key)) {
if (localToRemote.updated.has(key)) {
conflicts.add(key);
}
}
return {
local: { added: localAdded, removed: [...localRemoved.values()], updated: localUpdated },
remote: { added: remoteAdded, removed: [...remoteRemoved.values()], updated: remoteUpdated },
conflicts: [...conflicts.values()],
};
}
function compare(from: IStringDictionary<string> | null, to: IStringDictionary<string> | null): { added: Set<string>; removed: Set<string>; updated: Set<string> } {
snippetsMerge.ts ×2
const fromKeys = from ? Object.keys(from) : [];
const toKeys = to ? Object.keys(to) : [];
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
const updated: Set<string> = new Set<string>();
for (const key of fromKeys) {
}
const toSnippet = to![key];
if (fromSnippet !== toSnippet) {
}
return { added, removed, updated };
}
export function areSame(a: IStringDictionary<string>, b: IStringDictionary<string>): boolean {
return added.size === 0 && removed.size === 0 && updated.size === 0;
}