Skip to content

Commit

Permalink
Correctly handle null default values for objects
Browse files Browse the repository at this point in the history
Fixes #101637
  • Loading branch information
Aditya Thakral committed Jul 5, 2020
1 parent fff64d5 commit e4dffcf
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/vs/workbench/contrib/preferences/browser/settingsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,17 @@ function getObjectValueType(schema: IJSONSchema): ObjectValue['type'] {
}

function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectDataItem[] {
const elementDefaultValue: Record<string, unknown> = typeof element.defaultValue === 'object'
? element.defaultValue ?? {}
: {};

const elementScopeValue: Record<string, unknown> = typeof element.scopeValue === 'object'
? element.scopeValue ?? {}
: {};

const data = element.isConfigured ?
{ ...element.defaultValue, ...element.scopeValue } :
element.defaultValue;
{ ...elementDefaultValue, ...elementScopeValue } :
elementDefaultValue;

const { objectProperties, objectPatternProperties, objectAdditionalProperties } = element.setting;
const patternsAndSchemas = Object
Expand All @@ -129,7 +137,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData

return Object.keys(data).map(key => {
if (isDefined(objectProperties) && key in objectProperties) {
const defaultValue = element.defaultValue[key];
const defaultValue = elementDefaultValue[key];
const valueEnumOptions = getEnumOptionsFromSchema(objectProperties[key]);

return {
Expand All @@ -144,7 +152,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData
options: valueEnumOptions,
},
removable: isUndefinedOrNull(defaultValue),
};
} as IObjectDataItem;
}

const schema = patternsAndSchemas.find(({ pattern }) => pattern.test(key))?.schema;
Expand All @@ -159,7 +167,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData
options: valueEnumOptions,
},
removable: true,
};
} as IObjectDataItem;
}

return {
Expand All @@ -170,7 +178,7 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData
options: additionalValueEnums,
},
removable: true,
};
} as IObjectDataItem;
});
}

Expand Down Expand Up @@ -1055,8 +1063,14 @@ export class SettingObjectRenderer extends AbstractSettingRenderer implements IT

private onDidChangeObject(template: ISettingObjectItemTemplate, e: ISettingListChangeEvent<IObjectDataItem>): void {
if (template.context) {
const defaultValue: Record<string, unknown> = template.context.defaultValue;
const scopeValue: Record<string, unknown> = template.context.scopeValue;
const defaultValue: Record<string, unknown> = typeof template.context.defaultValue === 'object'
? template.context.defaultValue ?? {}
: {};

const scopeValue: Record<string, unknown> = typeof template.context.scopeValue === 'object'
? template.context.scopeValue ?? {}
: {};

const newValue: Record<string, unknown> = {};
let newItems: IObjectDataItem[] = [];

Expand Down

0 comments on commit e4dffcf

Please sign in to comment.