提交 4aec98a3 编写于 作者: M Martin Aeschlimann

Code fails to start up with invalid tokenColorCustomizations. Fixes #43129

上级 7b707406
......@@ -133,7 +133,7 @@ export const tokenColorizationSettingSchema: IJSONSchema = {
description: nls.localize('schema.token.fontStyle', 'Font style of the rule: \'italic\', \'bold\' or \'underline\' or a combination. The empty string unsets inherited settings.'),
pattern: '^(\\s*\\b(italic|bold|underline))*\\s*$',
patternErrorMessage: nls.localize('schema.fontStyle.error', 'Font style must be \'italic\', \'bold\' or \'underline\' or a combination or the empty string.'),
defaultSnippets: [{ body: 'italic' }, { body: 'bold' }, { body: 'underline' }, { body: 'italic bold' }, { body: 'italic underline' }, { body: 'bold underline' }, { body: 'italic bold underline' }]
defaultSnippets: [{ label: nls.localize('schema.token.fontStyle.none', 'None (clear inherited style)'), bodyText: '""' }, { body: 'italic' }, { body: 'bold' }, { body: 'underline' }, { body: 'italic bold' }, { body: 'italic underline' }, { body: 'bold underline' }, { body: 'italic bold underline' }]
}
},
additionalProperties: false,
......@@ -176,8 +176,11 @@ export function tokenColorsSchema(description: string): IJSONSchema {
}
]
},
settings: tokenColorizationSettingSchema
settings: tokenColorizationSettingSchema,
},
required: [
'settings', 'scope'
],
additionalProperties: false
}
};
......
......@@ -81,11 +81,10 @@ export class ColorThemeData implements IColorTheme {
public setCustomColors(colors: IColorCustomizations) {
this.customColorMap = {};
this.overwriteCustomColors(colors);
if (`[${this.settingsId}]` in colors) {
const themeSpecificColors = (colors[`[${this.settingsId}]`] || {}) as IColorCustomizations;
if (types.isObject(themeSpecificColors)) {
this.overwriteCustomColors(themeSpecificColors);
}
const themeSpecificColors = colors[`[${this.settingsId}]`] as IColorCustomizations;
if (types.isObject(themeSpecificColors)) {
this.overwriteCustomColors(themeSpecificColors);
}
if (this.themeTokenColors && this.themeTokenColors.length) {
updateDefaultRuleSettings(this.themeTokenColors[0], this);
......@@ -103,43 +102,38 @@ export class ColorThemeData implements IColorTheme {
public setCustomTokenColors(customTokenColors: ITokenColorCustomizations) {
this.customTokenColors = [];
let customTokenColorsWithoutThemeSpecific: ITokenColorCustomizations = {};
for (let key in customTokenColors) {
if (key[0] !== '[') {
customTokenColorsWithoutThemeSpecific[key] = customTokenColors[key];
}
}
this.addCustomTokenColors(customTokenColorsWithoutThemeSpecific);
if (`[${this.settingsId}]` in customTokenColors) {
const themeSpecificTokenColors: ITokenColorCustomizations = customTokenColors[`[${this.settingsId}]`];
if (types.isObject(themeSpecificTokenColors)) {
this.addCustomTokenColors(themeSpecificTokenColors);
}
// first add the non-theme specific settings
this.addCustomTokenColors(customTokenColors);
// append theme specific settings. Last rules will win.
const themeSpecificTokenColors = customTokenColors[`[${this.settingsId}]`] as ITokenColorCustomizations;
if (types.isObject(themeSpecificTokenColors)) {
this.addCustomTokenColors(themeSpecificTokenColors);
}
}
private addCustomTokenColors(customTokenColors: ITokenColorCustomizations) {
let generalRules: ITokenColorizationRule[] = [];
Object.keys(tokenGroupToScopesMap).forEach(key => {
let value = customTokenColors[key];
// Put the general customizations such as comments, strings, etc. first so that
// they can be overridden by specific customizations like "string.interpolated"
for (let tokenGroup in tokenGroupToScopesMap) {
let value = customTokenColors[tokenGroup];
if (value) {
let settings = typeof value === 'string' ? { foreground: value } : value;
let scopes = tokenGroupToScopesMap[key];
let scopes = tokenGroupToScopesMap[tokenGroup];
for (let scope of scopes) {
generalRules.push({
scope,
settings
});
this.customTokenColors.push({ scope, settings });
}
}
});
const textMateRules: ITokenColorizationRule[] = customTokenColors.textMateRules || [];
}
// Put the general customizations such as comments, strings, etc. first so that
// they can be overridden by specific customizations like "string.interpolated"
this.customTokenColors = this.customTokenColors.concat(generalRules, textMateRules);
// specific customizations
if (Array.isArray(customTokenColors.textMateRules)) {
for (let rule of customTokenColors.textMateRules) {
if (rule.scope && rule.settings) {
this.customTokenColors.push(rule);
}
}
}
}
public ensureLoaded(themeService: WorkbenchThemeService): TPromise<void> {
......@@ -155,13 +149,13 @@ export class ColorThemeData implements IColorTheme {
}
/**
* Place the default settings first and add add the token-info rules
* Place the default settings first and add the token-info rules
*/
private sanitizeTokenColors() {
let hasDefaultTokens = false;
let updatedTokenColors: ITokenColorizationRule[] = [updateDefaultRuleSettings({ settings: {} }, this)];
this.tokenColors.forEach(rule => {
if (rule.scope) {
this.themeTokenColors.forEach(rule => {
if (rule.scope && rule.settings) {
if (rule.scope === 'token.info-token') {
hasDefaultTokens = true;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册