From b36286db80c68b7fdc6bfee2f55e0208c8833dfc Mon Sep 17 00:00:00 2001 From: Benjamin Christopher Simmonds <44439583+benibenj@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:16:20 +0200 Subject: [PATCH] Fix property undefined bug (#217800) * fix property undefined bug * only set source of overrides --- .../common/configurationRegistry.ts | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/vs/platform/configuration/common/configurationRegistry.ts b/src/vs/platform/configuration/common/configurationRegistry.ts index d7e9ae576b0bd..322e807f0a73a 100644 --- a/src/vs/platform/configuration/common/configurationRegistry.ts +++ b/src/vs/platform/configuration/common/configurationRegistry.ts @@ -406,31 +406,41 @@ class ConfigurationRegistry implements IConfigurationRegistry { this.defaultLanguageConfigurationOverridesNode.properties![key] = property; } else { const property = this.configurationProperties[key]; - let defaultValue = overrides[key]; - let defaultValueSource: ConfigurationDefaultValueSource | undefined = source; + + const existingDefaultOverride = this.configurationDefaultsOverrides.get(key); + let existingDefaultValue = existingDefaultOverride?.value ?? property?.defaultDefaultValue; + + let newDefaultValue = overrides[key]; + let newDefaultValueSource: ConfigurationDefaultValueSource | undefined = source; + + const isObjectSetting = types.isObject(newDefaultValue) && ( + property !== undefined && property.type === 'object' || + property === undefined && (types.isUndefined(existingDefaultValue) || types.isObject(existingDefaultValue))); // If the default value is an object, merge the objects and store the source of each keys - if (property.type === 'object' && types.isObject(overrides[key])) { - const objectDefaults = this.configurationDefaultsOverrides.get(key); - const existingDefaultValue = objectDefaults?.value ?? property.defaultDefaultValue ?? {}; - defaultValue = { ...existingDefaultValue, ...overrides[key] }; + if (isObjectSetting) { + if (!types.isObject(existingDefaultValue)) { + existingDefaultValue = {}; + } + + newDefaultValue = { ...existingDefaultValue, ...newDefaultValue }; - defaultValueSource = objectDefaults?.source ?? new Map(); - if (!(defaultValueSource instanceof Map)) { + newDefaultValueSource = existingDefaultOverride?.source ?? new Map(); + if (!(newDefaultValueSource instanceof Map)) { console.error('defaultValueSource is not a Map'); continue; } - for (const objectKey in overrides[key]) { + for (const overrideObjectKey in overrides[key]) { if (source) { - defaultValueSource.set(objectKey, source); + newDefaultValueSource.set(overrideObjectKey, source); } else { - defaultValueSource.delete(objectKey); + newDefaultValueSource.delete(overrideObjectKey); } } } - this.configurationDefaultsOverrides.set(key, { value: defaultValue, source: defaultValueSource }); + this.configurationDefaultsOverrides.set(key, { value: newDefaultValue, source: newDefaultValueSource }); if (property) { this.updatePropertyDefaultValue(key, property);