提交 2fa3808c 编写于 作者: S Sandeep Somavarapu

#1587 Only support specific properties to override

- Introduced an internal boolean property 'overridable'
- Set this property to true while registering configuration
- Support inheriting this property from parent configuration node level
上级 385a2e54
......@@ -550,6 +550,7 @@ const editorConfiguration: IConfigurationNode = {
'order': 5,
'type': 'object',
'title': nls.localize('editorConfigurationTitle', "Editor"),
'overridable': true,
'properties': {
'editor.fontFamily': {
'type': 'string',
......
......@@ -43,18 +43,23 @@ export interface IConfigurationRegistry {
/**
* Returns all configurations settings of all configuration nodes contributed to this registry.
*/
getConfigurationProperties(): { [qualifiedKey: string]: IJSONSchema };
getConfigurationProperties(): { [qualifiedKey: string]: IConfigurationPropertySchema };
}
export interface IConfigurationPropertySchema extends IJSONSchema {
overridable?: boolean;
}
export interface IConfigurationNode {
id?: string;
order?: number;
type?: string | string[];
title?: string;
description?: string;
properties?: { [path: string]: IJSONSchema; };
properties?: { [path: string]: IConfigurationPropertySchema; };
allOf?: IConfigurationNode[];
overridable?: boolean;
}
const schemaId = 'vscode://schemas/settings';
......@@ -95,7 +100,8 @@ class ConfigurationRegistry implements IConfigurationRegistry {
this._onDidRegisterConfiguration.fire(this);
}
private registerProperties(configuration: IConfigurationNode) {
private registerProperties(configuration: IConfigurationNode, overridable: boolean = false) {
overridable = configuration.overridable || overridable;
let properties = configuration.properties;
if (properties) {
for (let key in properties) {
......@@ -105,6 +111,10 @@ class ConfigurationRegistry implements IConfigurationRegistry {
if (types.isUndefined(defaultValue)) {
property.default = getDefaultValue(property.type);
}
// Inherit overridable property from parent
if (overridable) {
property.overridable = true;
}
// add to properties map
this.configurationProperties[key] = properties[key];
}
......@@ -112,7 +122,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
let subNodes = configuration.allOf;
if (subNodes) {
for (let node of subNodes) {
this.registerProperties(node);
this.registerProperties(node, overridable);
}
}
}
......@@ -121,7 +131,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
return this.configurationContributors;
}
getConfigurationProperties(): { [qualifiedKey: string]: IJSONSchema } {
getConfigurationProperties(): { [qualifiedKey: string]: IConfigurationPropertySchema } {
return this.configurationProperties;
}
......@@ -154,20 +164,33 @@ class ConfigurationRegistry implements IConfigurationRegistry {
if (!patternProperties.properties) {
patternProperties.properties = {};
}
if (configuration.properties) {
for (const key in configuration.properties) {
patternProperties.properties[key] = this.getConfigurationProperties()[key];
}
this.update(configuration, patternProperties);
}
}
}
private update(configuration: IConfigurationNode, overridePropertiesSchema: IJSONSchema): void {
let properties = configuration.properties;
if (properties) {
for (let key in properties) {
if (properties[key].overridable) {
overridePropertiesSchema.properties[key] = this.getConfigurationProperties()[key];
}
}
}
let subNodes = configuration.allOf;
if (subNodes) {
subNodes.forEach(subNode => this.update(subNode, overridePropertiesSchema));
}
}
private registerOverrideSettingsConfiguration(): void {
const properties = {
'[]': {
type: 'object',
description: nls.localize('overrideSettings.description', "Configure settings to be overridden for a set of language identifiers.")
description: nls.localize('overrideSettings.description', "Configure settings to be overridden for a set of language identifiers."),
additionalProperties: false,
errorMessage: 'Unknown configuration setting'
}
};
this.registerConfiguration({
......
......@@ -212,10 +212,18 @@ export class ConfigModel<T> implements IConfigModel<T> {
this._parseErrors = [e];
}
this._contents = toValuesTree(this._raw, message => console.error(`Conflict in settings file ${this.name}: ${message}`));
const configurationProperties = Registry.as<IConfigurationRegistry>(Extensions.Configuration).getConfigurationProperties();
this._overrides = overrides ? overrides.map<IOverrides<T>>(override => {
// Filter unknown and non-overridable properties
const raw = {};
for (const key in override.raw) {
if (configurationProperties[key] && configurationProperties[key].overridable) {
raw[key] = override.raw[key];
}
}
return {
identifiers: override.identifiers,
contents: <T>toValuesTree(override.raw, message => console.error(`Conflict in settings file ${this.name}: ${message}`))
contents: <T>toValuesTree(raw, message => console.error(`Conflict in settings file ${this.name}: ${message}`))
};
}) : null;
}
......
......@@ -261,7 +261,8 @@ configurationRegistry.registerConfiguration({
'editor.formatOnSave': {
'type': 'boolean',
'default': false,
'description': nls.localize('formatOnSave', "Format a file on save. A formatter must be available, the file must not be auto-saved, and editor must not be shutting down.")
'description': nls.localize('formatOnSave', "Format a file on save. A formatter must be available, the file must not be auto-saved, and editor must not be shutting down."),
'overridable': true
}
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册