diff --git a/src/commands/quickCommand.helpers.ts b/src/commands/quickCommand.helpers.ts index f4751e7..b2e7f85 100644 --- a/src/commands/quickCommand.helpers.ts +++ b/src/commands/quickCommand.helpers.ts @@ -1,5 +1,5 @@ 'use strict'; -import { intersectionWith } from 'lodash-es'; +import { Arrays } from '../system'; import { GitBranch, GitTag, Repository } from '../git/git'; import { BranchQuickPickItem, TagQuickPickItem } from '../quickpicks'; @@ -34,12 +34,12 @@ export async function getBranchesAndOrTags( ]); branches = GitBranch.sort( - intersectionWith(...branchesByRepo, ((b1: GitBranch, b2: GitBranch) => b1.name === b2.name) as any) + Arrays.intersection(...branchesByRepo, ((b1: GitBranch, b2: GitBranch) => b1.name === b2.name) as any) ); if (includeTags) { tags = GitTag.sort( - intersectionWith(...tagsByRepo!, ((t1: GitTag, t2: GitTag) => t1.name === t2.name) as any) + Arrays.intersection(...tagsByRepo!, ((t1: GitTag, t2: GitTag) => t1.name === t2.name) as any) ); } } diff --git a/src/configuration.ts b/src/configuration.ts index 26eff87..6181ee1 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -12,7 +12,7 @@ import { } from 'vscode'; import { Config } from './config'; import { extensionId } from './constants'; -import { Functions } from './system'; +import { Functions, Objects } from './system'; const emptyConfig: Config = new Proxy({} as Config, { get: function() { @@ -273,7 +273,7 @@ export class Configuration { return configuration.update( section, - value === inspect.defaultValue ? undefined : value, + Objects.areEquivalent(value, inspect.defaultValue) ? undefined : value, ConfigurationTarget.Global ); } diff --git a/src/system/array.ts b/src/system/array.ts index df0df8f..0443382 100644 --- a/src/system/array.ts +++ b/src/system/array.ts @@ -1,4 +1,5 @@ 'use strict'; +import { intersectionWith as _intersectionWith, isEqual as _isEqual, xor as _xor } from 'lodash-es'; export namespace Arrays { export function countUniques(source: T[], accessor: (item: T) => string): { [key: string]: number } { @@ -78,6 +79,13 @@ export namespace Arrays { }, new Map()); } + export const intersection = _intersectionWith; + export const isEqual = _isEqual; + + export function areEquivalent(value: T[], other: T[]) { + return _xor(value, other).length === 0; + } + export interface HierarchicalItem { name: string; relativePath: string; diff --git a/src/system/object.ts b/src/system/object.ts index 6dd091b..5978b40 100644 --- a/src/system/object.ts +++ b/src/system/object.ts @@ -1,4 +1,6 @@ 'use strict'; +import { isEqual as _isEqual } from 'lodash-es'; +import { Arrays } from './array'; export namespace Objects { export function entries(o: { [key: string]: T }): IterableIterator<[string, T]>; @@ -53,6 +55,17 @@ export namespace Objects { } } + export function isEqual(value: any, other: any) { + return _isEqual(value, other); + } + + export function areEquivalent(value: any, other: any) { + if (Array.isArray(value) && Array.isArray(other)) { + return Arrays.areEquivalent(value, other); + } + return isEqual(value, other); + } + export function paths(o: { [key: string]: any }, path?: string): string[] { const results = [];