From 423f89b0fd5973650c3fc2000a8427c377af4c88 Mon Sep 17 00:00:00 2001 From: Christopher-Robin Ebbinghaus Date: Tue, 19 Oct 2021 12:41:56 +1100 Subject: [PATCH] Split keys into seperate languages --- .../configuration/common/configuration.ts | 15 +++++++--- .../common/configurationModels.ts | 29 ++++++++++++------- .../common/configurationRegistry.ts | 6 ++-- .../browser/preferencesRenderers.ts | 8 +++-- .../common/configurationModels.ts | 7 +++-- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/vs/platform/configuration/common/configuration.ts b/src/vs/platform/configuration/common/configuration.ts index 2711e370a19e8..8ed7960ddf430 100644 --- a/src/vs/platform/configuration/common/configuration.ts +++ b/src/vs/platform/configuration/common/configuration.ts @@ -189,7 +189,9 @@ export function compare(from: IConfigurationModel | undefined, to: IConfiguratio for (const key of added) { const override = toOverridesByIdentifier[key]; if (override) { - overrides.push([overrideIdentifierFromKey(key), override.keys]); + for (let identifier of overrideIdentifierFromKey(key)) { + overrides.push([identifier, override.keys]); + } } } } @@ -197,7 +199,9 @@ export function compare(from: IConfigurationModel | undefined, to: IConfiguratio for (const key of removed) { const override = fromOverridesByIdentifier[key]; if (override) { - overrides.push([overrideIdentifierFromKey(key), override.keys]); + for (let identifier of overrideIdentifierFromKey(key)) { + overrides.push([identifier, override.keys]); + } } } } @@ -208,7 +212,10 @@ export function compare(from: IConfigurationModel | undefined, to: IConfiguratio const toOverride = toOverridesByIdentifier[key]; if (fromOverride && toOverride) { const result = compare({ contents: fromOverride.contents, keys: fromOverride.keys, overrides: [] }, { contents: toOverride.contents, keys: toOverride.keys, overrides: [] }); - overrides.push([overrideIdentifierFromKey(key), [...result.added, ...result.removed, ...result.updated]]); + + for (let identifier of overrideIdentifierFromKey(key)) { + overrides.push([identifier, [...result.added, ...result.removed, ...result.updated]]); + } } } } @@ -225,7 +232,7 @@ export function toOverrides(raw: any, conflictReporter: (message: string) => voi overrideRaw[keyInOverrideRaw] = raw[key][keyInOverrideRaw]; } overrides.push({ - identifiers: [overrideIdentifierFromKey(key).trim()], + identifiers: overrideIdentifierFromKey(key), keys: Object.keys(overrideRaw), contents: toValuesTree(overrideRaw, conflictReporter) }); diff --git a/src/vs/platform/configuration/common/configurationModels.ts b/src/vs/platform/configuration/common/configurationModels.ts index ae155ae126f75..ea49d1d658aae 100644 --- a/src/vs/platform/configuration/common/configurationModels.ts +++ b/src/vs/platform/configuration/common/configurationModels.ts @@ -214,7 +214,7 @@ export class DefaultConfigurationModel extends ConfigurationModel { for (const key of Object.keys(contents)) { if (OVERRIDE_PROPERTY_PATTERN.test(key)) { overrides.push({ - identifiers: [overrideIdentifierFromKey(key).trim()], + identifiers: overrideIdentifierFromKey(key), keys: Object.keys(contents[key]), contents: toValuesTree(contents[key], message => console.error(`Conflict in default settings file: ${message}`)), }); @@ -543,19 +543,26 @@ export class Configuration { } compareAndUpdateDefaultConfiguration(defaults: ConfigurationModel, keys: string[]): IConfigurationChange { + const overrides: [string, string[]][] = keys .filter(key => OVERRIDE_PROPERTY_PATTERN.test(key)) .map(key => { - const overrideIdentifier = overrideIdentifierFromKey(key); - const fromKeys = this._defaultConfiguration.getKeysForOverrideIdentifier(overrideIdentifier); - const toKeys = defaults.getKeysForOverrideIdentifier(overrideIdentifier); - const keys = [ - ...toKeys.filter(key => fromKeys.indexOf(key) === -1), - ...fromKeys.filter(key => toKeys.indexOf(key) === -1), - ...fromKeys.filter(key => !objects.equals(this._defaultConfiguration.override(overrideIdentifier).getValue(key), defaults.override(overrideIdentifier).getValue(key))) - ]; - return [overrideIdentifier, keys]; - }); + const result: [string, string[]][] = []; + const overrideIdentifiers = overrideIdentifierFromKey(key); + + for (let overrideIdentifier of overrideIdentifiers) { + const fromKeys = this._defaultConfiguration.getKeysForOverrideIdentifier(overrideIdentifier); + const toKeys = defaults.getKeysForOverrideIdentifier(overrideIdentifier); + const keys = [ + ...toKeys.filter(key => fromKeys.indexOf(key) === -1), + ...fromKeys.filter(key => toKeys.indexOf(key) === -1), + ...fromKeys.filter(key => !objects.equals(this._defaultConfiguration.override(overrideIdentifier).getValue(key), defaults.override(overrideIdentifier).getValue(key))) + ]; + result.push([overrideIdentifier, keys]); + } + return result; + }).flat(); + this.updateDefaultConfiguration(defaults); return { keys, overrides }; } diff --git a/src/vs/platform/configuration/common/configurationRegistry.ts b/src/vs/platform/configuration/common/configurationRegistry.ts index 9a8a259e797a7..cbdb7e7f56b64 100644 --- a/src/vs/platform/configuration/common/configurationRegistry.ts +++ b/src/vs/platform/configuration/common/configurationRegistry.ts @@ -259,7 +259,7 @@ class ConfigurationRegistry implements IConfigurationRegistry { description: nls.localize('defaultLanguageConfiguration.description', "Configure settings to be overridden for {0} language.", key), $ref: resourceLanguageSettingsSchemaId }; - overrideIdentifiers.push(overrideIdentifierFromKey(key)); + overrideIdentifiers.push.apply(overrideIdentifiers, overrideIdentifierFromKey(key)); this.configurationProperties[key] = property; this.defaultLanguageConfigurationOverridesNode.properties![key] = property; } else { @@ -508,8 +508,8 @@ class ConfigurationRegistry implements IConfigurationRegistry { const OVERRIDE_PROPERTY = '\\[.*\\]$'; export const OVERRIDE_PROPERTY_PATTERN = new RegExp(OVERRIDE_PROPERTY); -export function overrideIdentifierFromKey(key: string): string { - return key.substring(1, key.length - 1); +export function overrideIdentifierFromKey(key: string): string[] { + return key.replace(/\[|\]|\s/g, '').split(','); } export function getDefaultValue(type: string | string[] | undefined): any { diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts index 234adcce45925..7daf733454f1c 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts @@ -76,10 +76,12 @@ export class UserSettingsRenderer extends Disposable implements IPreferencesRend } updatePreference(key: string, value: any, source: IIndexedSetting): void { - const overrideIdentifier = source.overrideOf ? overrideIdentifierFromKey(source.overrideOf.key) : null; + const overrideIdentifiers = source.overrideOf ? overrideIdentifierFromKey(source.overrideOf.key) : []; const resource = this.preferencesModel.uri; - this.configurationService.updateValue(key, value, { overrideIdentifier, resource }, this.preferencesModel.configurationTarget) - .then(() => this.onSettingUpdated(source)); + + for (let overrideIdentifier of overrideIdentifiers) + this.configurationService.updateValue(key, value, { overrideIdentifier, resource }, this.preferencesModel.configurationTarget) + .then(() => this.onSettingUpdated(source)); } private onModelChanged(): void { diff --git a/src/vs/workbench/services/configuration/common/configurationModels.ts b/src/vs/workbench/services/configuration/common/configurationModels.ts index 412065dd3b28d..224eba591a0e0 100644 --- a/src/vs/workbench/services/configuration/common/configurationModels.ts +++ b/src/vs/workbench/services/configuration/common/configurationModels.ts @@ -156,8 +156,11 @@ export class Configuration extends BaseConfiguration { const overrides: [string, string[]][] = []; for (const key of keys) { if (OVERRIDE_PROPERTY_PATTERN.test(key)) { - const overrideIdentifier = overrideIdentifierFromKey(key); - overrides.push([overrideIdentifier, compare(this.getAllKeysForOverrideIdentifier(overrideIdentifier), other.getAllKeysForOverrideIdentifier(overrideIdentifier), overrideIdentifier)]); + const overrideIdentifiesr = overrideIdentifierFromKey(key); + + for (let overrideIdentifier of overrideIdentifiesr) { + overrides.push([overrideIdentifier, compare(this.getAllKeysForOverrideIdentifier(overrideIdentifier), other.getAllKeysForOverrideIdentifier(overrideIdentifier), overrideIdentifier)]); + } } } return { keys, overrides };