aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/color_theme.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/color_theme.ts')
-rw-r--r--editors/code/src/color_theme.ts28
1 files changed, 15 insertions, 13 deletions
diff --git a/editors/code/src/color_theme.ts b/editors/code/src/color_theme.ts
index cbad47f35..a6957a76e 100644
--- a/editors/code/src/color_theme.ts
+++ b/editors/code/src/color_theme.ts
@@ -28,9 +28,12 @@ export class ColorTheme {
28 static fromRules(rules: TextMateRule[]): ColorTheme { 28 static fromRules(rules: TextMateRule[]): ColorTheme {
29 const res = new ColorTheme(); 29 const res = new ColorTheme();
30 for (const rule of rules) { 30 for (const rule of rules) {
31 const scopes = typeof rule.scope === 'string' 31 const scopes = typeof rule.scope === 'undefined'
32 ? [rule.scope] 32 ? []
33 : rule.scope; 33 : typeof rule.scope === 'string'
34 ? [rule.scope]
35 : rule.scope;
36
34 for (const scope of scopes) { 37 for (const scope of scopes) {
35 res.rules.set(scope, rule.settings); 38 res.rules.set(scope, rule.settings);
36 } 39 }
@@ -59,7 +62,7 @@ export class ColorTheme {
59} 62}
60 63
61function loadThemeNamed(themeName: string): ColorTheme { 64function loadThemeNamed(themeName: string): ColorTheme {
62 function isTheme(extension: vscode.Extension<any>): boolean { 65 function isTheme(extension: vscode.Extension<unknown>): boolean {
63 return ( 66 return (
64 extension.extensionKind === vscode.ExtensionKind.UI && 67 extension.extensionKind === vscode.ExtensionKind.UI &&
65 extension.packageJSON.contributes && 68 extension.packageJSON.contributes &&
@@ -67,13 +70,13 @@ function loadThemeNamed(themeName: string): ColorTheme {
67 ); 70 );
68 } 71 }
69 72
70 let themePaths = vscode.extensions.all 73 const themePaths: string[] = vscode.extensions.all
71 .filter(isTheme) 74 .filter(isTheme)
72 .flatMap(ext => { 75 .flatMap(
73 return ext.packageJSON.contributes.themes 76 ext => ext.packageJSON.contributes.themes
74 .filter((it: any) => (it.id || it.label) === themeName) 77 .filter((it: any) => (it.id || it.label) === themeName)
75 .map((it: any) => path.join(ext.extensionPath, it.path)); 78 .map((it: any) => path.join(ext.extensionPath, it.path))
76 }); 79 );
77 80
78 const res = new ColorTheme(); 81 const res = new ColorTheme();
79 for (const themePath of themePaths) { 82 for (const themePath of themePaths) {
@@ -94,13 +97,12 @@ function loadThemeFile(themePath: string): ColorTheme {
94 return new ColorTheme(); 97 return new ColorTheme();
95 } 98 }
96 const obj = jsonc.parse(text); 99 const obj = jsonc.parse(text);
97 const tokenColors = obj?.tokenColors ?? []; 100 const tokenColors: TextMateRule[] = obj?.tokenColors ?? [];
98 const res = ColorTheme.fromRules(tokenColors); 101 const res = ColorTheme.fromRules(tokenColors);
99 102
100 for (const include in obj?.include ?? []) { 103 for (const include of obj?.include ?? []) {
101 const includePath = path.join(path.dirname(themePath), include); 104 const includePath = path.join(path.dirname(themePath), include);
102 const tmp = loadThemeFile(includePath); 105 res.mergeFrom(loadThemeFile(includePath));
103 res.mergeFrom(tmp);
104 } 106 }
105 107
106 return res; 108 return res;