Skip to content

Commit 1d2efa9

Browse files
committed
workbench theme service: provide tokenColorMap
1 parent abce0e8 commit 1d2efa9

7 files changed

Lines changed: 220 additions & 116 deletions

File tree

src/vs/editor/standalone/browser/standaloneThemeServiceImpl.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
1414
import { Registry } from 'vs/platform/registry/common/platform';
1515
import { ColorIdentifier, Extensions, IColorRegistry } from 'vs/platform/theme/common/colorRegistry';
1616
import { Extensions as ThemingExtensions, ICssStyleCollector, IIconTheme, IThemingRegistry } from 'vs/platform/theme/common/themeService';
17-
import { TokenStyle, TokenClassification, ProbeScope } from 'vs/platform/theme/common/tokenClassificationRegistry';
1817

1918
const VS_THEME_NAME = 'vs';
2019
const VS_DARK_THEME_NAME = 'vs-dark';
@@ -130,14 +129,6 @@ class StandaloneTheme implements IStandaloneTheme {
130129
}
131130
return this._tokenTheme;
132131
}
133-
134-
getTokenStyle(classification: TokenClassification, useDefault?: boolean | undefined): TokenStyle | undefined {
135-
return undefined;
136-
}
137-
138-
resolveScopes(scopes: ProbeScope[]): TokenStyle | undefined {
139-
return undefined;
140-
}
141132
}
142133

143134
function isBuiltinTheme(themeName: string): themeName is BuiltinTheme {

src/vs/editor/standalone/test/browser/standaloneLanguages.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ suite('TokenizationSupport2Adapter', () => {
5454

5555
defines: (color: ColorIdentifier): boolean => {
5656
throw new Error('Not implemented');
57-
},
58-
59-
getTokenStyle: () => undefined,
60-
resolveScopes: () => undefined
61-
57+
}
6258
};
6359
}
60+
6461
public getIconTheme(): IIconTheme {
6562
return {
6663
hasFileIcons: false,

src/vs/platform/theme/common/themeService.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as platform from 'vs/platform/registry/common/platform';
1010
import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
1111
import { Event, Emitter } from 'vs/base/common/event';
1212
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
13-
import { TokenStyle, TokenClassification, ProbeScope } from 'vs/platform/theme/common/tokenClassificationRegistry';
1413

1514
export const IThemeService = createDecorator<IThemeService>('themeService');
1615

@@ -60,10 +59,6 @@ export interface ITheme {
6059
* default color will be used.
6160
*/
6261
defines(color: ColorIdentifier): boolean;
63-
64-
getTokenStyle(classification: TokenClassification, useDefault?: boolean): TokenStyle | undefined;
65-
66-
resolveScopes(scopes: ProbeScope[]): TokenStyle | undefined;
6762
}
6863

6964
export interface IIconTheme {

src/vs/platform/theme/common/tokenClassificationRegistry.ts

Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ export interface ITokenClassificationRegistry {
142142
getTokenModifiers(): TokenTypeOrModifierContribution[];
143143

144144
/**
145-
* Resolves a token classification against the given rules and default rules from the registry.
145+
* The styling rules to used when a schema does not define any styling rules.
146146
*/
147-
resolveTokenStyle(classification: TokenClassification, themingRules: TokenStylingRule[] | undefined, customThemingRules: TokenStylingRule[], theme: ITheme): TokenStyle | undefined;
147+
getTokenStylingDefaultRules(): TokenStylingDefaultRule[];
148148

149149
/**
150150
* JSON schema for an object to assign styling to token classifications
@@ -271,87 +271,13 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
271271
return Object.keys(this.tokenModifierById).map(id => this.tokenModifierById[id]);
272272
}
273273

274-
public resolveTokenStyle(classification: TokenClassification, themingRules: TokenStylingRule[] | undefined, customThemingRules: TokenStylingRule[], theme: ITheme): TokenStyle | undefined {
275-
let result: any = {
276-
foreground: undefined,
277-
bold: undefined,
278-
underline: undefined,
279-
italic: undefined
280-
};
281-
let score = {
282-
foreground: -1,
283-
bold: -1,
284-
underline: -1,
285-
italic: -1
286-
};
287-
288-
function _processStyle(matchScore: number, style: TokenStyle) {
289-
if (style.foreground && score.foreground <= matchScore) {
290-
score.foreground = matchScore;
291-
result.foreground = style.foreground;
292-
}
293-
for (let p of ['bold', 'underline', 'italic']) {
294-
const property = p as keyof TokenStyle;
295-
const info = style[property];
296-
if (info !== undefined) {
297-
if (score[property] <= matchScore) {
298-
score[property] = matchScore;
299-
result[property] = info;
300-
}
301-
}
302-
}
303-
}
304-
if (themingRules === undefined) {
305-
for (const rule of this.tokenStylingDefaultRules) {
306-
const matchScore = match(rule, classification);
307-
if (matchScore >= 0) {
308-
let style = theme.resolveScopes(rule.defaults.scopesToProbe);
309-
if (!style) {
310-
style = this.resolveTokenStyleValue(rule.defaults[theme.type], theme);
311-
}
312-
if (style) {
313-
_processStyle(matchScore, style);
314-
}
315-
}
316-
}
317-
} else {
318-
for (const rule of themingRules) {
319-
const matchScore = match(rule, classification);
320-
if (matchScore >= 0) {
321-
_processStyle(matchScore, rule.value);
322-
}
323-
}
324-
}
325-
for (const rule of customThemingRules) {
326-
const matchScore = match(rule, classification);
327-
if (matchScore >= 0) {
328-
_processStyle(matchScore, rule.value);
329-
}
330-
}
331-
return TokenStyle.fromData(result);
332-
}
333-
334-
/**
335-
* @param tokenStyleValue Resolve a tokenStyleValue in the context of a theme
336-
*/
337-
private resolveTokenStyleValue(tokenStyleValue: TokenStyleValue | null, theme: ITheme): TokenStyle | undefined {
338-
if (tokenStyleValue === null) {
339-
return undefined;
340-
} else if (typeof tokenStyleValue === 'string') {
341-
const classification = this.getTokenClassificationFromString(tokenStyleValue);
342-
if (classification) {
343-
return theme.getTokenStyle(classification);
344-
}
345-
} else if (typeof tokenStyleValue === 'object') {
346-
return tokenStyleValue;
347-
}
348-
return undefined;
349-
}
350-
351274
public getTokenStylingSchema(): IJSONSchema {
352275
return this.tokenStylingSchema;
353276
}
354277

278+
public getTokenStylingDefaultRules(): TokenStylingDefaultRule[] {
279+
return this.tokenStylingDefaultRules;
280+
}
355281

356282
public toString() {
357283
let sorter = (a: string, b: string) => {
@@ -368,7 +294,7 @@ class TokenClassificationRegistry implements ITokenClassificationRegistry {
368294

369295
}
370296

371-
function match(themeSelector: TokenStylingRule | TokenStylingDefaultRule, classification: TokenClassification): number {
297+
export function matchTokenStylingRule(themeSelector: TokenStylingRule | TokenStylingDefaultRule, classification: TokenClassification): number {
372298
const selectorType = themeSelector.classification.type;
373299
if (selectorType !== TOKEN_TYPE_WILDCARD_NUM && selectorType !== classification.type) {
374300
return -1;

src/vs/platform/theme/test/common/testThemeService.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import { Event, Emitter } from 'vs/base/common/event';
77
import { IThemeService, ITheme, DARK, IIconTheme } from 'vs/platform/theme/common/themeService';
88
import { Color } from 'vs/base/common/color';
9-
import { TokenStyle, TokenClassification, ProbeScope } from 'vs/platform/theme/common/tokenClassificationRegistry';
109

1110
export class TestTheme implements ITheme {
1211

@@ -24,14 +23,6 @@ export class TestTheme implements ITheme {
2423
defines(color: string): boolean {
2524
throw new Error('Method not implemented.');
2625
}
27-
28-
getTokenStyle(classification: TokenClassification, useDefault?: boolean | undefined): TokenStyle | undefined {
29-
throw new Error('Method not implemented.');
30-
}
31-
32-
resolveScopes(scopes: ProbeScope[]): TokenStyle | undefined {
33-
throw new Error('Method not implemented.');
34-
}
3526
}
3627

3728
export class TestIconTheme implements IIconTheme {

0 commit comments

Comments
 (0)