Skip to content

Commit

Permalink
#51935 fix overrides keys in configuration model while merging
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Nov 15, 2021
1 parent 4dde912 commit de269bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/vs/platform/configuration/common/configurationModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export class ConfigurationModel implements IConfigurationModel {
const [override] = overrides.filter(o => arrays.equals(o.identifiers, otherOverride.identifiers));
if (override) {
this.mergeContents(override.contents, otherOverride.contents);
override.keys.push(...otherOverride.keys);
override.keys = arrays.distinct(override.keys);
} else {
overrides.push(objects.deepClone(otherOverride));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ suite('ConfigurationModel', () => {
let result = base.merge(add);

assert.deepStrictEqual(result.contents, { 'a': { 'b': 2 } });
assert.deepStrictEqual(result.overrides, [{ identifiers: ['c'], contents: { 'a': 2, 'b': 2 }, keys: ['a'] }]);
assert.deepStrictEqual(result.overrides, [{ identifiers: ['c'], contents: { 'a': 2, 'b': 2 }, keys: ['a', 'b'] }]);
assert.deepStrictEqual(result.override('c').contents, { 'a': 2, 'b': 2 });
assert.deepStrictEqual(result.keys, ['a.b']);
});
Expand Down Expand Up @@ -260,6 +260,21 @@ suite('ConfigurationModel', () => {

assert.deepStrictEqual(testObject.getKeysForOverrideIdentifier('x'), ['a', 'b']);
});

test('Test merge when configuration models have multiple identifiers', () => {
const testObject = new ConfigurationModel({ 'a': 1, 'c': 1 }, ['a', 'c'], [{ identifiers: ['y'], contents: { 'c': 1 }, keys: ['c'] }, { identifiers: ['x', 'y'], contents: { 'a': 2 }, keys: ['a'] }]);
const target = new ConfigurationModel({ 'a': 2, 'b': 1 }, ['a', 'b'], [{ identifiers: ['x'], contents: { 'a': 3, 'b': 2 }, keys: ['a', 'b'] }, { identifiers: ['x', 'y'], contents: { 'b': 3 }, keys: ['b'] }]);

const actual = testObject.merge(target);

assert.deepStrictEqual(actual.contents, { 'a': 2, 'c': 1, 'b': 1 });
assert.deepStrictEqual(actual.keys, ['a', 'c', 'b']);
assert.deepStrictEqual(actual.overrides, [
{ identifiers: ['y'], contents: { 'c': 1 }, keys: ['c'] },
{ identifiers: ['x', 'y'], contents: { 'a': 2, 'b': 3 }, keys: ['a', 'b'] },
{ identifiers: ['x'], contents: { 'a': 3, 'b': 2 }, keys: ['a', 'b'] },
]);
});
});

suite('CustomConfigurationModel', () => {
Expand Down

0 comments on commit de269bb

Please sign in to comment.