Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overriding preferences #5149

Merged
merged 1 commit into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/plugin-ext/src/plugin/preference-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,14 @@ export class PreferenceRegistryExtImpl implements PreferenceRegistryExt {
return new ConfigurationModel(this.parseConfigurationData(data), Object.keys(data));
}

private readonly OVERRIDE_PROPERTY = '\\[(.*)\\]$';
private readonly OVERRIDE_PROPERTY_PATTERN = new RegExp(this.OVERRIDE_PROPERTY);

private parseConfigurationData(data: { [key: string]: any }): { [key: string]: any } {
return Object.keys(data).reduce((result: any, key: string) => {
const parts = key.split('.');
let branch = result;

for (let i = 0; i < parts.length; i++) {
if (i === parts.length - 1) {
branch[parts[i]] = data[key];
Expand All @@ -247,6 +251,16 @@ export class PreferenceRegistryExtImpl implements PreferenceRegistryExt {
branch[parts[i]] = {};
}
branch = branch[parts[i]];

// overridden properties should be transformed into
// "[overridden_identifier]" : {
// "property1" : "value1"
// "property2" : "value2"
// }
if (i === 0 && this.OVERRIDE_PROPERTY_PATTERN.test(parts[i])) {
branch[key.substring(parts[0].length + 1)] = data[key];
break;
}
}
return result;
}, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi
if (this.schemaProvider.testOverrideValue(preferenceName, preferenceValue)) {
// tslint:disable-next-line:forin
for (const overriddenPreferenceName in preferenceValue) {
const overriddeValue = preferenceValue[overriddenPreferenceName];
preferences[`${preferenceName}.${overriddenPreferenceName}`] = overriddeValue;
const overriddenValue = preferenceValue[overriddenPreferenceName];
preferences[`${preferenceName}.${overriddenPreferenceName}`] = overriddenValue;
}
} else {
preferences[preferenceName] = preferenceValue;
Expand Down