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

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

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