Skip to content

Commit b36286d

Browse files
authored
Fix property undefined bug (microsoft#217800)
* fix property undefined bug * only set source of overrides
1 parent ca8cb6f commit b36286d

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/vs/platform/configuration/common/configurationRegistry.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,31 +406,41 @@ class ConfigurationRegistry implements IConfigurationRegistry {
406406
this.defaultLanguageConfigurationOverridesNode.properties![key] = property;
407407
} else {
408408
const property = this.configurationProperties[key];
409-
let defaultValue = overrides[key];
410-
let defaultValueSource: ConfigurationDefaultValueSource | undefined = source;
409+
410+
const existingDefaultOverride = this.configurationDefaultsOverrides.get(key);
411+
let existingDefaultValue = existingDefaultOverride?.value ?? property?.defaultDefaultValue;
412+
413+
let newDefaultValue = overrides[key];
414+
let newDefaultValueSource: ConfigurationDefaultValueSource | undefined = source;
415+
416+
const isObjectSetting = types.isObject(newDefaultValue) && (
417+
property !== undefined && property.type === 'object' ||
418+
property === undefined && (types.isUndefined(existingDefaultValue) || types.isObject(existingDefaultValue)));
411419

412420
// If the default value is an object, merge the objects and store the source of each keys
413-
if (property.type === 'object' && types.isObject(overrides[key])) {
414-
const objectDefaults = this.configurationDefaultsOverrides.get(key);
415-
const existingDefaultValue = objectDefaults?.value ?? property.defaultDefaultValue ?? {};
416-
defaultValue = { ...existingDefaultValue, ...overrides[key] };
421+
if (isObjectSetting) {
422+
if (!types.isObject(existingDefaultValue)) {
423+
existingDefaultValue = {};
424+
}
425+
426+
newDefaultValue = { ...existingDefaultValue, ...newDefaultValue };
417427

418-
defaultValueSource = objectDefaults?.source ?? new Map<string, ConfigurationDefaultSource>();
419-
if (!(defaultValueSource instanceof Map)) {
428+
newDefaultValueSource = existingDefaultOverride?.source ?? new Map<string, ConfigurationDefaultSource>();
429+
if (!(newDefaultValueSource instanceof Map)) {
420430
console.error('defaultValueSource is not a Map');
421431
continue;
422432
}
423433

424-
for (const objectKey in overrides[key]) {
434+
for (const overrideObjectKey in overrides[key]) {
425435
if (source) {
426-
defaultValueSource.set(objectKey, source);
436+
newDefaultValueSource.set(overrideObjectKey, source);
427437
} else {
428-
defaultValueSource.delete(objectKey);
438+
newDefaultValueSource.delete(overrideObjectKey);
429439
}
430440
}
431441
}
432442

433-
this.configurationDefaultsOverrides.set(key, { value: defaultValue, source: defaultValueSource });
443+
this.configurationDefaultsOverrides.set(key, { value: newDefaultValue, source: newDefaultValueSource });
434444

435445
if (property) {
436446
this.updatePropertyDefaultValue(key, property);

0 commit comments

Comments
 (0)