keybindingsMerge.ts ×12

Frontier kind: Code frontier

unlabeled · c_430a5afbb5df

54 tests · 21755 LOC · 133 files · introduces 0 tests · 57 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges57 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2964 ranges21755 lines · 133 files · Browse complete extent
All tests (intent)
54 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 57 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/userDataSync/common/keybindingsMerge.ts 53 introduced LOC · 12 ranges

Open complete file

29 }
30
31 > function parseKeybindings(content: string): IUserFriendlyKeybinding[] { keybindingsMerge.ts
32 > return parse(content) || [];
33 > }
34
35 > export async function merge(localContent: string, remoteContent: string, baseContent: string | null, formattingOptions: FormattingOptions, userDataSyncUtilService: IUserDataSyncUtilService): Promise<{ mergeContent: string; hasChanges: boolean; hasConflicts: boolean }> { keybindingsMerge.ts
36 > const local = parseKeybindings(localContent);
37 > const remote = parseKeybindings(remoteContent);
38 > const base = baseContent ? parseKeybindings(baseContent) : null;
39 >
40 > const userbindings: string[] = [...local, ...remote, ...(base || [])].map(keybinding => keybinding.key);
41 > const normalizedKeys = await userDataSyncUtilService.resolveUserBindings(userbindings);
42 > const keybindingsMergeResult = computeMergeResultByKeybinding(local, remote, base, normalizedKeys);
43 >
44 > if (!keybindingsMergeResult.hasLocalForwarded && !keybindingsMergeResult.hasRemoteForwarded) {
45 // No changes found between local and remote.
46 return { mergeContent: localContent, hasChanges: false, hasConflicts: false };
47 }
48
49 > if (!keybindingsMergeResult.hasLocalForwarded && keybindingsMergeResult.hasRemoteForwarded) { keybindingsMerge.ts
50 return { mergeContent: remoteContent, hasChanges: true, hasConflicts: false };
51 }
52
53 > if (keybindingsMergeResult.hasLocalForwarded && !keybindingsMergeResult.hasRemoteForwarded) { keybindingsMerge.ts
54 // Local has moved forward and remote has not. Return local.
55 return { mergeContent: localContent, hasChanges: true, hasConflicts: false };
59 const localByCommand = byCommand(local);
60 const remoteByCommand = byCommand(remote);
61 > const baseByCommand = base ? byCommand(base) : null; keybindingsMerge.ts
62 > const localToRemoteByCommand = compareByCommand(localByCommand, remoteByCommand, normalizedKeys);
63 > const baseToLocalByCommand = baseByCommand ? compareByCommand(baseByCommand, localByCommand, normalizedKeys) : { added: [...localByCommand.keys()].reduce((r, k) => { r.add(k); return r; }, new Set<string>()), removed: new Set<string>(), updated: new Set<string>() };
64 > const baseToRemoteByCommand = baseByCommand ? compareByCommand(baseByCommand, remoteByCommand, normalizedKeys) : { added: [...remoteByCommand.keys()].reduce((r, k) => { r.add(k); return r; }, new Set<string>()), removed: new Set<string>(), updated: new Set<string>() };
65 >
66 > const commandsMergeResult = computeMergeResult(localToRemoteByCommand, baseToLocalByCommand, baseToRemoteByCommand);
67 > let mergeContent = localContent;
68 >
69 > // Removed commands in Remote
70 > for (const command of commandsMergeResult.removed.values()) {
71 if (commandsMergeResult.conflicts.has(command)) {
72 continue;
197 }
198
199 > function computeMergeResultByKeybinding(local: IUserFriendlyKeybinding[], remote: IUserFriendlyKeybinding[], base: IUserFriendlyKeybinding[] | null, normalizedKeys: IStringDictionary<string>): IMergeResult { keybindingsMerge.ts
200 > const empty = new Set<string>();
201 > const localByKeybinding = byKeybinding(local, normalizedKeys);
202 > const remoteByKeybinding = byKeybinding(remote, normalizedKeys);
203 > const baseByKeybinding = base ? byKeybinding(base, normalizedKeys) : null;
204 >
205 > const localToRemoteByKeybinding = compareByKeybinding(localByKeybinding, remoteByKeybinding);
206 > if (localToRemoteByKeybinding.added.size === 0 && localToRemoteByKeybinding.removed.size === 0 && localToRemoteByKeybinding.updated.size === 0) {
207 return { hasLocalForwarded: false, hasRemoteForwarded: false, added: empty, removed: empty, updated: empty, conflicts: empty };
208 }
209
210 > const baseToLocalByKeybinding = baseByKeybinding ? compareByKeybinding(baseByKeybinding, localByKeybinding) : { added: [...localByKeybinding.keys()].reduce((r, k) => { r.add(k); return r; }, new Set<string>()), removed: new Set<string>(), updated: new Set<string>() }; keybindingsMerge.ts
211 > if (baseToLocalByKeybinding.added.size === 0 && baseToLocalByKeybinding.removed.size === 0 && baseToLocalByKeybinding.updated.size === 0) {
212 // Remote has moved forward and local has not.
213 return { hasLocalForwarded: false, hasRemoteForwarded: true, added: empty, removed: empty, updated: empty, conflicts: empty };
214 }
215
216 > const baseToRemoteByKeybinding = baseByKeybinding ? compareByKeybinding(baseByKeybinding, remoteByKeybinding) : { added: [...remoteByKeybinding.keys()].reduce((r, k) => { r.add(k); return r; }, new Set<string>()), removed: new Set<string>(), updated: new Set<string>() }; keybindingsMerge.ts
217 > if (baseToRemoteByKeybinding.added.size === 0 && baseToRemoteByKeybinding.removed.size === 0 && baseToRemoteByKeybinding.updated.size === 0) {
218 return { hasLocalForwarded: true, hasRemoteForwarded: false, added: empty, removed: empty, updated: empty, conflicts: empty };
219 }
223 }
224
225 > function byKeybinding(keybindings: IUserFriendlyKeybinding[], keys: IStringDictionary<string>) { keybindingsMerge.ts
226 > const map: Map<string, IUserFriendlyKeybinding[]> = new Map<string, IUserFriendlyKeybinding[]>();
227 > for (const keybinding of keybindings) {
228 const key = keys[keybinding.key];
229 let value = map.get(key);
235
236 }
237 > return map; keybindingsMerge.ts
238 > }
239
240 function byCommand(keybindings: IUserFriendlyKeybinding[]): Map<string, IUserFriendlyKeybinding[]> {
253
254
255 > function compareByKeybinding(from: Map<string, IUserFriendlyKeybinding[]>, to: Map<string, IUserFriendlyKeybinding[]>): ICompareResult { keybindingsMerge.ts
256 > const fromKeys = [...from.keys()];
257 > const toKeys = [...to.keys()];
258 > const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
259 > const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
260 > const updated: Set<string> = new Set<string>();
261 >
262 > for (const key of fromKeys) {
263 if (removed.has(key)) {
264 continue;
270 }
271 }
273 > return { added, removed, updated };
274 > }
275
276 function compareByCommand(from: Map<string, IUserFriendlyKeybinding[]>, to: Map<string, IUserFriendlyKeybinding[]>, normalizedKeys: IStringDictionary<string>): ICompareResult {
src/vs/platform/userDataSync/test/common/userDataSyncClient.ts 4 introduced LOC · 2 ranges

Open complete file

379
380 async resolveUserBindings(userbindings: string[]): Promise<IStringDictionary<string>> {
381 > const keys: IStringDictionary<string> = {}; userDataSyncClient.ts
382 > for (const keybinding of userbindings) {
383 keys[keybinding] = keybinding;
384 }
385 > return keys; userDataSyncClient.ts
386 > }
387
388 async resolveFormattingOptions(file?: URI): Promise<FormattingOptions> {