Skip to content

Commit 8c84658

Browse files
committed
Allow themes to be defined in JSON
1 parent 2fbdbe8 commit 8c84658

6 files changed

Lines changed: 143 additions & 215 deletions

File tree

extensions/theme-colorful-defaults/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
{
1212
"label": "Dark+ (default dark)",
1313
"uiTheme": "vs-dark",
14-
"path": "./themes/dark_plus.tmTheme"
14+
"path": "./themes/dark_plus.json"
1515
},
1616
{
1717
"label": "Light+ (default light)",
1818
"uiTheme": "vs",
19-
"path": "./themes/light_plus.tmTheme"
19+
"path": "./themes/light_plus.json"
2020
}
2121
]
2222
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "Dark+",
3+
"settings": [
4+
{
5+
"name": "Types declaration and references",
6+
"scope": ["meta.type.name", "meta.return.type", "meta.return-type", "meta.cast", "meta.type.annotation",
7+
"support.type", "entity.name.class", "entity.name.type", "storage.type.cs", "storage.type.java"],
8+
"settings": {
9+
"foreground": "#4EC9B0"
10+
}
11+
},
12+
{
13+
"name": "Function declarations",
14+
"scope": ["entity.name.function", "entity.method.name"],
15+
"settings": {
16+
"foreground": "#DCDCAA"
17+
}
18+
},
19+
{
20+
"name": "Control flow keywords",
21+
"scope": "keyword.control",
22+
"settings": {
23+
"foreground": "#C586C0"
24+
}
25+
},
26+
{
27+
"name": "Variable and parameter name",
28+
"scope": ["meta.parameter.type.variable", "variable.parameter", "variable", "variable.name"],
29+
"settings": {
30+
"foreground": "#9CDCFE"
31+
}
32+
},
33+
{
34+
"name": "C includes",
35+
"scope": "keyword.control.import",
36+
"settings": {
37+
"foreground": "#569CD6"
38+
}
39+
},
40+
{
41+
"name": "CSS property value",
42+
"scope": ["css.support.property-value", "css.constant.rgb-value"],
43+
"settings": {
44+
"foreground": "#CE9178"
45+
}
46+
},
47+
{
48+
"name": "JSON keys",
49+
"scope": "support.type.property-name",
50+
"settings": {
51+
"foreground": "#9CDCFE"
52+
}
53+
},
54+
{
55+
"name": "LESS workaround",
56+
"scope": "keyword.control.less",
57+
"settings": {
58+
"foreground": "#D7BA7D"
59+
}
60+
}
61+
]
62+
}

extensions/theme-colorful-defaults/themes/dark_plus.tmTheme

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "Light+",
3+
"settings": [
4+
{
5+
"name": "Types declaration and references",
6+
"scope": ["meta.type.name", "meta.return.type", "meta.return-type", "meta.cast", "meta.type.annotation",
7+
"support.type", "entity.name.class", "entity.name.type", "storage.type.cs", "storage.type.java"],
8+
"settings": {
9+
"foreground": "#267f99"
10+
}
11+
},
12+
{
13+
"name": "Function declarations",
14+
"scope": ["entity.name.function", "entity.method.name"],
15+
"settings": {
16+
"foreground": "#795E26"
17+
}
18+
},
19+
{
20+
"name": "Control flow keywords",
21+
"scope": "keyword.control",
22+
"settings": {
23+
"foreground": "#AF00DB"
24+
}
25+
},
26+
{
27+
"name": "Parameter name",
28+
"scope": ["meta.parameter.type.variable", "variable.parameter", "variable", "variable.name"],
29+
"settings": {
30+
"foreground": "#001080"
31+
}
32+
},
33+
{
34+
"name": "C includes must match meta.preprocessor",
35+
"scope": "keyword.control.import",
36+
"settings": {
37+
"foreground": "#0000FF"
38+
}
39+
},
40+
{
41+
"name": "CSS keys",
42+
"scope": ["support.type.property-name.css", "support.type.property-name.less", "support.type.property-name.sass"],
43+
"settings": {
44+
"foreground": "#FF0000"
45+
}
46+
},
47+
{
48+
"name": "JSON keys",
49+
"scope": "support.type.property-name",
50+
"settings": {
51+
"foreground": "#0451A5"
52+
}
53+
},
54+
{
55+
"name": "LESS workaround",
56+
"scope": "keyword.control.less",
57+
"settings": {
58+
"foreground": "#800000"
59+
}
60+
}
61+
]
62+
}

extensions/theme-colorful-defaults/themes/light_plus.tmTheme

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/vs/workbench/services/themes/node/themeService.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import {TPromise} from 'vs/base/common/winjs.base';
88
import nls = require('vs/nls');
99
import Paths = require('vs/base/common/paths');
10+
import Json = require('vs/base/common/json');
1011
import Themes = require('vs/platform/theme/common/themes');
1112
import {IThemeExtensionPoint} from 'vs/platform/theme/common/themeExtensionPoint';
1213
import {IExtensionService} from 'vs/platform/extensions/common/extensions';
@@ -130,11 +131,21 @@ function applyTheme(theme: IThemeData): TPromise<boolean> {
130131
}
131132

132133
return pfs.readFile(theme.path).then(content => {
133-
let parseResult = plist.parse(content.toString());
134-
if (parseResult.errors && parseResult.errors.length) {
135-
return TPromise.wrapError(new Error(nls.localize('error.cannotparse', "Problems parsing plist file: {0}", parseResult.errors.join(', '))));
134+
let contentValue: any;
135+
if (Paths.extname(theme.path) === '.json') {
136+
let errors: string[] = [];
137+
contentValue = Json.parse(content.toString(), errors);
138+
if (errors.length > 0) {
139+
return TPromise.wrapError(new Error(nls.localize('error.cannotparsejson', "Problems parsing json file: {0}", errors.join(', '))));
140+
}
141+
} else {
142+
let parseResult = plist.parse(content.toString());
143+
if (parseResult.errors && parseResult.errors.length) {
144+
return TPromise.wrapError(new Error(nls.localize('error.cannotparse', "Problems parsing plist file: {0}", parseResult.errors.join(', '))));
145+
}
146+
contentValue = parseResult.value;
136147
}
137-
let styleSheetContent = _processThemeObject(theme.id, parseResult.value);
148+
let styleSheetContent = _processThemeObject(theme.id, contentValue);
138149
theme.styleSheetContent = styleSheetContent;
139150
_applyRules(styleSheetContent);
140151
return true;
@@ -163,10 +174,10 @@ function _processThemeObject(themeId: string, themeDocument: any): string {
163174
if (index === 0 && !s.scope) {
164175
editorSettings = s.settings;
165176
} else {
166-
let scope: string = s.scope;
177+
let scope: string | string[] = s.scope;
167178
let settings: string = s.settings;
168179
if (scope && settings) {
169-
let rules = scope.split(',');
180+
let rules = Array.isArray(scope) ? <string[]> scope : scope.split(',');
170181
let statements = _settingsToStatements(settings);
171182
rules.forEach(rule => {
172183
rule = rule.trim().replace(/ /g, '.'); // until we have scope hierarchy in the editor dom: replace spaces with .

0 commit comments

Comments
 (0)