Skip to content

Commit

Permalink
Fix property undefined bug (#217800)
Browse files Browse the repository at this point in the history
* fix property undefined bug

* only set source of overrides
  • Loading branch information
benibenj committed Jun 25, 2024
1 parent ca8cb6f commit b36286d
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/vs/platform/configuration/common/configurationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ConfigurationDefaultSource>();
if (!(defaultValueSource instanceof Map)) {
newDefaultValueSource = existingDefaultOverride?.source ?? new Map<string, ConfigurationDefaultSource>();
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);
Expand Down

0 comments on commit b36286d

Please sign in to comment.