Skip to content

Commit f337499

Browse files
committed
monokai test
1 parent fb7cc04 commit f337499

3 files changed

Lines changed: 46 additions & 16 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export function getTokenStyleRegistry(): ITokenStyleRegistry {
243243

244244

245245
export const comments = registerTokenStyle('comments', { scopesToProbe: ['comment'], dark: null, light: null, hc: null }, nls.localize('comments', "Token style for comments."));
246-
export const strings = registerTokenStyle('strings', { scopesToProbe: ['strings'], dark: null, light: null, hc: null }, nls.localize('strings', "Token style for strings."));
246+
export const strings = registerTokenStyle('strings', { scopesToProbe: ['string'], dark: null, light: null, hc: null }, nls.localize('strings', "Token style for strings."));
247247
export const keywords = registerTokenStyle('keywords', { scopesToProbe: ['keyword.control', 'storage', 'storage.type'], dark: null, light: null, hc: null }, nls.localize('keywords', "Token style for keywords."));
248248
export const numbers = registerTokenStyle('numbers', { scopesToProbe: ['constant.numeric'], dark: null, light: null, hc: null }, nls.localize('numbers', "Token style for numbers."));
249249
export const types = registerTokenStyle('types', { scopesToProbe: ['entity.name.type', 'entity.name.class', 'support.type', 'support.class'], dark: null, light: null, hc: null }, nls.localize('types', "Token style for types."));

src/vs/workbench/services/themes/common/colorThemeData.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ColorThemeData implements IColorTheme {
5757
private colorMap: IColorMap = {};
5858
private customColorMap: IColorMap = {};
5959

60-
private tokenStyleMap: ITokenStyleMap | undefined;
60+
private tokenStyleMap: ITokenStyleMap = {};
6161

6262
private themeTokenScopeMatchers: Matcher<ProbeScope>[] | undefined;
6363
private customTokenScopeMatchers: Matcher<ProbeScope>[] | undefined;
@@ -116,24 +116,17 @@ export class ColorThemeData implements IColorTheme {
116116
return color;
117117
}
118118

119-
public getTokenStyle(tokenStyleId: TokenStyleIdentifier): TokenStyle | undefined {
120-
if (!this.tokenStyleMap) {
121-
this.tokenStyleMap = this.initTokenStyleMap();
122-
}
119+
public getTokenStyle(tokenStyleId: TokenStyleIdentifier, useDefault?: boolean): TokenStyle | undefined {
123120
let style: TokenStyle | undefined = this.tokenStyleMap[tokenStyleId];
124121
if (style) {
125122
return style;
126123
}
127-
if (types.isUndefined(style)) {
128-
style = this.getDefaultTokenStyle(style);
124+
if (useDefault !== false && types.isUndefined(style)) {
125+
style = this.getDefaultTokenStyle(tokenStyleId);
129126
}
130127
return style;
131128
}
132129

133-
private initTokenStyleMap(): ITokenStyleMap {
134-
return {};
135-
}
136-
137130
public getDefault(colorId: ColorIdentifier): Color | undefined {
138131
return colorRegistry.resolveDefaultColor(colorId, this);
139132
}

src/vs/workbench/services/themes/test/electron-browser/tokenStyleResolving.test.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
import { ColorThemeData } from 'vs/workbench/services/themes/common/colorThemeData';
77
import * as assert from 'assert';
88
import { ITokenColorCustomizations } from 'vs/workbench/services/themes/common/workbenchThemeService';
9-
import { TokenStyle, TokenStyleBits } from 'vs/platform/theme/common/tokenStyleRegistry';
9+
import { TokenStyle, TokenStyleBits, comments, variables, types, functions, keywords, numbers, strings } from 'vs/platform/theme/common/tokenStyleRegistry';
1010
import { Color } from 'vs/base/common/color';
1111
import { isString } from 'vs/base/common/types';
12+
import { FileService } from 'vs/platform/files/common/fileService';
13+
import { NullLogService } from 'vs/platform/log/common/log';
14+
import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider';
15+
import { Schemas } from 'vs/base/common/network';
16+
import { URI } from 'vs/base/common/uri';
17+
import { getPathFromAmdModule } from 'vs/base/common/amd';
1218

1319
function ts(foreground: string | undefined, styleFlags: number | undefined): TokenStyle {
1420
const foregroundColor = isString(foreground) ? Color.fromHex(foreground) : undefined;
@@ -24,14 +30,45 @@ function assertTokenStyle(expected: TokenStyle | undefined | null, actual: Token
2430
}
2531

2632

33+
2734
suite('Themes - TokenStyleResolving', () => {
35+
const fileService = new FileService(new NullLogService());
36+
const diskFileSystemProvider = new DiskFileSystemProvider(new NullLogService());
37+
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
38+
39+
40+
test('color defaults - monokai', async () => {
41+
const themeData = ColorThemeData.createUnloadedTheme('foo');
42+
const themeLocation = getPathFromAmdModule(require, '../../../../../../../extensions/theme-monokai/themes/monokai-color-theme.json');
43+
themeData.location = URI.file(themeLocation);
44+
await themeData.ensureLoaded(fileService);
45+
46+
assert.equal(themeData.isLoaded, true);
47+
48+
let tokenStyle;
2849

29-
// const fileService = new FileService(new NullLogService());
30-
// const diskFileSystemProvider = new DiskFileSystemProvider(new NullLogService());
31-
// fileService.registerProvider(Schemas.file, diskFileSystemProvider);
50+
tokenStyle = themeData.getTokenStyle(comments);
51+
assertTokenStyle(tokenStyle, ts('#75715E', 0));
3252

53+
tokenStyle = themeData.getTokenStyle(variables);
54+
assertTokenStyle(tokenStyle, ts('#F8F8F2', 0));
3355

56+
tokenStyle = themeData.getTokenStyle(types);
57+
assertTokenStyle(tokenStyle, ts('#A6E22E', TokenStyleBits.UNDERLINE));
3458

59+
tokenStyle = themeData.getTokenStyle(functions);
60+
assertTokenStyle(tokenStyle, ts('#A6E22E', 0));
61+
62+
tokenStyle = themeData.getTokenStyle(strings);
63+
assertTokenStyle(tokenStyle, ts('#E6DB74', 0));
64+
65+
tokenStyle = themeData.getTokenStyle(numbers);
66+
assertTokenStyle(tokenStyle, ts('#AE81FF', 0));
67+
68+
tokenStyle = themeData.getTokenStyle(keywords);
69+
assertTokenStyle(tokenStyle, ts('#F92672', 0));
70+
71+
});
3572

3673
test('resolve resource', async () => {
3774
const themeData = ColorThemeData.createLoadedEmptyTheme('test', 'test');

0 commit comments

Comments
 (0)