102
103
get tokenColors(): ITextMateThemingRule[] {
105
>
const result: ITextMateThemingRule[] = [];
106
>
107
>
// the default rule (scope empty) is always the first rule. Ignore all other default rules.
108
>
const foreground = this.getColor(editorForeground) || this.getDefault(editorForeground)!;
109
>
const background = this.getColor(editorBackground) || this.getDefault(editorBackground)!;
110
>
result.push({
111
>
settings: {
112
>
foreground: normalizeColor(foreground),
113
>
background: normalizeColor(background)
114
>
}
115
>
});
116
>
117
>
let hasDefaultTokens = false;
118
>
119
>
function addRule(rule: ITextMateThemingRule) {
120
>
if (rule.scope && rule.settings) {
121
>
if (rule.scope === 'token.info-token') {
122
>
hasDefaultTokens = true;
123
>
}
124
>
const ruleSettings = rule.settings;
125
>
result.push({
126
>
scope: rule.scope, settings: {
127
>
foreground: normalizeColor(ruleSettings.foreground),
128
>
background: normalizeColor(ruleSettings.background),
129
>
fontStyle: ruleSettings.fontStyle,
130
>
fontSize: ruleSettings.fontSize,
131
>
fontFamily: ruleSettings.fontFamily,
132
>
lineHeight: ruleSettings.lineHeight
133
>
}
134
>
});
135
>
}
136
>
}
137
>
138
>
this.themeTokenColors.forEach(addRule);
139
>
// Add the custom colors after the theme colors
140
>
// so that they will override them
141
>
this.customTokenColors.forEach(addRule);
142
>
143
>
if (!hasDefaultTokens) {
144
>
defaultThemeColors[this.type].forEach(addRule);
145
>
}
146
>
this.textMateThemingRules = result;
147
>
}
148
>
return this.textMateThemingRules;
149
>
}
150
151
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | undefined {
153
>
if (customColor instanceof Color) {
154
return customColor;
155
}
156
>
if (customColor === undefined) { /* !== DEFAULT_COLOR_CONFIG_VALUE */
colorThemeData.ts
157
>
const color = this.colorMap[colorId];
158
>
if (color !== undefined) {
159
return color;
160
}
162
>
if (useDefault !== false) {
163
>
return this.getDefault(colorId);
164
>
}
165
return undefined;
167
168
private getTokenStyle(type: string, modifiers: string[], language: string, useDefault = true, definitions: TokenStyleDefinitions = {}): TokenStyle | undefined {
170
>
foreground: undefined,
171
>
bold: undefined,
172
>
underline: undefined,
173
>
strikethrough: undefined,
174
>
italic: undefined
175
>
};
176
>
const score = {
177
>
foreground: -1,
178
>
bold: -1,
179
>
underline: -1,
180
>
strikethrough: -1,
181
>
italic: -1,
182
>
fontFamily: -1,
183
>
fontSize: -1,
184
>
lineHeight: -1
185
>
};
186
>
187
>
function _processStyle(matchScore: number, style: TokenStyle, definition: TokenStyleDefinition) {
188
>
if (style.foreground && score.foreground <= matchScore) {
189
>
score.foreground = matchScore;
190
>
result.foreground = style.foreground;
191
>
definitions.foreground = definition;
192
>
}
193
>
for (const p of ['bold', 'underline', 'strikethrough', 'italic']) {
194
>
const property = p as keyof TokenStyle;
195
>
const info = style[property];
196
>
if (info !== undefined) {
197
if (score[property] <= matchScore) {
198
score[property] = matchScore;