diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/package-lock.json | 5 | ||||
-rw-r--r-- | editors/code/package.json | 31 | ||||
-rw-r--r-- | editors/code/src/color_theme.ts | 129 |
3 files changed, 28 insertions, 137 deletions
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 55ba5351d..71c627a2a 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json | |||
@@ -1066,11 +1066,6 @@ | |||
1066 | "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", | 1066 | "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", |
1067 | "dev": true | 1067 | "dev": true |
1068 | }, | 1068 | }, |
1069 | "jsonc-parser": { | ||
1070 | "version": "2.2.1", | ||
1071 | "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.2.1.tgz", | ||
1072 | "integrity": "sha512-o6/yDBYccGvTz1+QFevz6l6OBZ2+fMVu2JZ9CIhzsYRX4mjaK5IyX9eldUdCmga16zlgQxyrj5pt9kzuj2C02w==" | ||
1073 | }, | ||
1074 | "leven": { | 1069 | "leven": { |
1075 | "version": "3.1.0", | 1070 | "version": "3.1.0", |
1076 | "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", | 1071 | "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", |
diff --git a/editors/code/package.json b/editors/code/package.json index 7ef727b9d..6935fa7a5 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -33,7 +33,6 @@ | |||
33 | "fix": " tsfmt -r && eslint -c .eslintrc.js --ext ts ./src --fix" | 33 | "fix": " tsfmt -r && eslint -c .eslintrc.js --ext ts ./src --fix" |
34 | }, | 34 | }, |
35 | "dependencies": { | 35 | "dependencies": { |
36 | "jsonc-parser": "^2.2.1", | ||
37 | "node-fetch": "^2.6.0", | 36 | "node-fetch": "^2.6.0", |
38 | "vscode-languageclient": "7.0.0-next.1" | 37 | "vscode-languageclient": "7.0.0-next.1" |
39 | }, | 38 | }, |
@@ -233,6 +232,14 @@ | |||
233 | "default": false, | 232 | "default": false, |
234 | "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs" | 233 | "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs" |
235 | }, | 234 | }, |
235 | "rust-analyzer.cargo.target": { | ||
236 | "type": [ | ||
237 | "null", | ||
238 | "string" | ||
239 | ], | ||
240 | "default": null, | ||
241 | "description": "Specify the compilation target" | ||
242 | }, | ||
236 | "rust-analyzer.rustfmt.extraArgs": { | 243 | "rust-analyzer.rustfmt.extraArgs": { |
237 | "type": "array", | 244 | "type": "array", |
238 | "items": { | 245 | "items": { |
@@ -281,13 +288,18 @@ | |||
281 | "minItems": 1 | 288 | "minItems": 1 |
282 | }, | 289 | }, |
283 | "default": null, | 290 | "default": null, |
284 | "markdownDescription": "Advanced option, fully override the command rust-analyzer uses for checking. The command should include `--message=format=json` or similar option." | 291 | "markdownDescription": "Advanced option, fully override the command rust-analyzer uses for checking. The command should include `--message-format=json` or similar option." |
285 | }, | 292 | }, |
286 | "rust-analyzer.checkOnSave.allTargets": { | 293 | "rust-analyzer.checkOnSave.allTargets": { |
287 | "type": "boolean", | 294 | "type": "boolean", |
288 | "default": true, | 295 | "default": true, |
289 | "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)" | 296 | "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)" |
290 | }, | 297 | }, |
298 | "rust-analyzer.checkOnSave.allFeatures": { | ||
299 | "type": "boolean", | ||
300 | "default": true, | ||
301 | "markdownDescription": "Check with all features (will be passed as `--all-features`)" | ||
302 | }, | ||
291 | "rust-analyzer.inlayHints.typeHints": { | 303 | "rust-analyzer.inlayHints.typeHints": { |
292 | "type": "boolean", | 304 | "type": "boolean", |
293 | "default": true, | 305 | "default": true, |
@@ -393,7 +405,7 @@ | |||
393 | "ms-vscode.cpptools" | 405 | "ms-vscode.cpptools" |
394 | ], | 406 | ], |
395 | "default": "auto", | 407 | "default": "auto", |
396 | "description": "Preffered debug engine.", | 408 | "description": "Preferred debug engine.", |
397 | "markdownEnumDescriptions": [ | 409 | "markdownEnumDescriptions": [ |
398 | "First try to use [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb), if it's not installed try to use [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools).", | 410 | "First try to use [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb), if it's not installed try to use [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools).", |
399 | "Use [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)", | 411 | "Use [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)", |
@@ -534,6 +546,10 @@ | |||
534 | { | 546 | { |
535 | "id": "unresolvedReference", | 547 | "id": "unresolvedReference", |
536 | "description": "Style for names which can not be resolved due to compilation errors" | 548 | "description": "Style for names which can not be resolved due to compilation errors" |
549 | }, | ||
550 | { | ||
551 | "id": "formatSpecifier", | ||
552 | "description": "Style for {} placeholders in format strings" | ||
537 | } | 553 | } |
538 | ], | 554 | ], |
539 | "semanticTokenModifiers": [ | 555 | "semanticTokenModifiers": [ |
@@ -573,9 +589,18 @@ | |||
573 | "union": [ | 589 | "union": [ |
574 | "entity.name.union" | 590 | "entity.name.union" |
575 | ], | 591 | ], |
592 | "struct": [ | ||
593 | "entity.name.type.struct" | ||
594 | ], | ||
576 | "keyword.unsafe": [ | 595 | "keyword.unsafe": [ |
577 | "keyword.other.unsafe" | 596 | "keyword.other.unsafe" |
578 | ], | 597 | ], |
598 | "keyword": [ | ||
599 | "keyword" | ||
600 | ], | ||
601 | "keyword.controlFlow": [ | ||
602 | "keyword.control" | ||
603 | ], | ||
579 | "variable.constant": [ | 604 | "variable.constant": [ |
580 | "entity.name.constant" | 605 | "entity.name.constant" |
581 | ] | 606 | ] |
diff --git a/editors/code/src/color_theme.ts b/editors/code/src/color_theme.ts deleted file mode 100644 index 5b9327b28..000000000 --- a/editors/code/src/color_theme.ts +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
1 | import * as fs from 'fs'; | ||
2 | import * as jsonc from 'jsonc-parser'; | ||
3 | import * as path from 'path'; | ||
4 | import * as vscode from 'vscode'; | ||
5 | |||
6 | export interface TextMateRuleSettings { | ||
7 | foreground?: string; | ||
8 | background?: string; | ||
9 | fontStyle?: string; | ||
10 | } | ||
11 | |||
12 | export class ColorTheme { | ||
13 | private rules: Map<string, TextMateRuleSettings> = new Map(); | ||
14 | |||
15 | static load(): ColorTheme { | ||
16 | // Find out current color theme | ||
17 | const themeName = vscode.workspace | ||
18 | .getConfiguration('workbench') | ||
19 | .get('colorTheme'); | ||
20 | |||
21 | if (typeof themeName !== 'string') { | ||
22 | // console.warn('workbench.colorTheme is', themeName) | ||
23 | return new ColorTheme(); | ||
24 | } | ||
25 | return loadThemeNamed(themeName); | ||
26 | } | ||
27 | |||
28 | static fromRules(rules: TextMateRule[]): ColorTheme { | ||
29 | const res = new ColorTheme(); | ||
30 | for (const rule of rules) { | ||
31 | const scopes = typeof rule.scope === 'undefined' | ||
32 | ? [] | ||
33 | : typeof rule.scope === 'string' | ||
34 | ? [rule.scope] | ||
35 | : rule.scope; | ||
36 | |||
37 | for (const scope of scopes) { | ||
38 | res.rules.set(scope, rule.settings); | ||
39 | } | ||
40 | } | ||
41 | return res; | ||
42 | } | ||
43 | |||
44 | lookup(scopes: string[]): TextMateRuleSettings { | ||
45 | let res: TextMateRuleSettings = {}; | ||
46 | for (const scope of scopes) { | ||
47 | this.rules.forEach((value, key) => { | ||
48 | if (scope.startsWith(key)) { | ||
49 | res = mergeRuleSettings(res, value); | ||
50 | } | ||
51 | }); | ||
52 | } | ||
53 | return res; | ||
54 | } | ||
55 | |||
56 | mergeFrom(other: ColorTheme) { | ||
57 | other.rules.forEach((value, key) => { | ||
58 | const merged = mergeRuleSettings(this.rules.get(key), value); | ||
59 | this.rules.set(key, merged); | ||
60 | }); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | function loadThemeNamed(themeName: string): ColorTheme { | ||
65 | function isTheme(extension: vscode.Extension<unknown>): boolean { | ||
66 | return ( | ||
67 | extension.extensionKind === vscode.ExtensionKind.UI && | ||
68 | extension.packageJSON.contributes && | ||
69 | extension.packageJSON.contributes.themes | ||
70 | ); | ||
71 | } | ||
72 | |||
73 | const themePaths: string[] = vscode.extensions.all | ||
74 | .filter(isTheme) | ||
75 | .flatMap( | ||
76 | ext => ext.packageJSON.contributes.themes | ||
77 | .filter((it: any) => (it.id || it.label) === themeName) | ||
78 | .map((it: any) => path.join(ext.extensionPath, it.path)) | ||
79 | ); | ||
80 | |||
81 | const res = new ColorTheme(); | ||
82 | for (const themePath of themePaths) { | ||
83 | res.mergeFrom(loadThemeFile(themePath)); | ||
84 | } | ||
85 | |||
86 | const globalCustomizations: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations'); | ||
87 | res.mergeFrom(ColorTheme.fromRules(globalCustomizations?.textMateRules ?? [])); | ||
88 | |||
89 | const themeCustomizations: any = vscode.workspace.getConfiguration('editor.tokenColorCustomizations').get(`[${themeName}]`); | ||
90 | res.mergeFrom(ColorTheme.fromRules(themeCustomizations?.textMateRules ?? [])); | ||
91 | |||
92 | |||
93 | return res; | ||
94 | } | ||
95 | |||
96 | function loadThemeFile(themePath: string): ColorTheme { | ||
97 | let text; | ||
98 | try { | ||
99 | text = fs.readFileSync(themePath, 'utf8'); | ||
100 | } catch { | ||
101 | return new ColorTheme(); | ||
102 | } | ||
103 | const obj = jsonc.parse(text); | ||
104 | const tokenColors: TextMateRule[] = obj?.tokenColors ?? []; | ||
105 | const res = ColorTheme.fromRules(tokenColors); | ||
106 | |||
107 | for (const include of obj?.include ?? []) { | ||
108 | const includePath = path.join(path.dirname(themePath), include); | ||
109 | res.mergeFrom(loadThemeFile(includePath)); | ||
110 | } | ||
111 | |||
112 | return res; | ||
113 | } | ||
114 | |||
115 | interface TextMateRule { | ||
116 | scope: string | string[]; | ||
117 | settings: TextMateRuleSettings; | ||
118 | } | ||
119 | |||
120 | function mergeRuleSettings( | ||
121 | defaultSetting: TextMateRuleSettings | undefined, | ||
122 | override: TextMateRuleSettings, | ||
123 | ): TextMateRuleSettings { | ||
124 | return { | ||
125 | foreground: override.foreground ?? defaultSetting?.foreground, | ||
126 | background: override.background ?? defaultSetting?.background, | ||
127 | fontStyle: override.fontStyle ?? defaultSetting?.fontStyle, | ||
128 | }; | ||
129 | } | ||