aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_flycheck/src/lib.rs7
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--editors/code/package-lock.json5
-rw-r--r--editors/code/package.json6
-rw-r--r--editors/code/src/color_theme.ts129
5 files changed, 13 insertions, 138 deletions
diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs
index b54a30ab8..f27252949 100644
--- a/crates/ra_flycheck/src/lib.rs
+++ b/crates/ra_flycheck/src/lib.rs
@@ -24,7 +24,7 @@ pub use crate::conv::url_from_path_with_drive_lowercasing;
24 24
25#[derive(Clone, Debug, PartialEq, Eq)] 25#[derive(Clone, Debug, PartialEq, Eq)]
26pub enum FlycheckConfig { 26pub enum FlycheckConfig {
27 CargoCommand { command: String, all_targets: bool, extra_args: Vec<String> }, 27 CargoCommand { command: String, all_targets: bool, all_features: bool, extra_args: Vec<String> },
28 CustomCommand { command: String, args: Vec<String> }, 28 CustomCommand { command: String, args: Vec<String> },
29} 29}
30 30
@@ -215,7 +215,7 @@ impl FlycheckThread {
215 self.check_process = None; 215 self.check_process = None;
216 216
217 let mut cmd = match &self.config { 217 let mut cmd = match &self.config {
218 FlycheckConfig::CargoCommand { command, all_targets, extra_args } => { 218 FlycheckConfig::CargoCommand { command, all_targets, all_features, extra_args } => {
219 let mut cmd = Command::new(cargo_binary()); 219 let mut cmd = Command::new(cargo_binary());
220 cmd.arg(command); 220 cmd.arg(command);
221 cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]); 221 cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]);
@@ -223,6 +223,9 @@ impl FlycheckThread {
223 if *all_targets { 223 if *all_targets {
224 cmd.arg("--all-targets"); 224 cmd.arg("--all-targets");
225 } 225 }
226 if *all_features {
227 cmd.arg("--all-features");
228 }
226 cmd.args(extra_args); 229 cmd.args(extra_args);
227 cmd 230 cmd
228 } 231 }
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 8d85c60cf..ccc38e3bb 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -89,6 +89,7 @@ impl Default for Config {
89 check: Some(FlycheckConfig::CargoCommand { 89 check: Some(FlycheckConfig::CargoCommand {
90 command: "check".to_string(), 90 command: "check".to_string(),
91 all_targets: true, 91 all_targets: true,
92 all_features: true,
92 extra_args: Vec::new(), 93 extra_args: Vec::new(),
93 }), 94 }),
94 95
@@ -173,12 +174,13 @@ impl Config {
173 } 174 }
174 // otherwise configure command customizations 175 // otherwise configure command customizations
175 _ => { 176 _ => {
176 if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets }) 177 if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets, all_features })
177 = &mut self.check 178 = &mut self.check
178 { 179 {
179 set(value, "/checkOnSave/extraArgs", extra_args); 180 set(value, "/checkOnSave/extraArgs", extra_args);
180 set(value, "/checkOnSave/command", command); 181 set(value, "/checkOnSave/command", command);
181 set(value, "/checkOnSave/allTargets", all_targets); 182 set(value, "/checkOnSave/allTargets", all_targets);
183 set(value, "/checkOnSave/allFeatures", all_features);
182 } 184 }
183 } 185 }
184 }; 186 };
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 a05a69752..eeb3d3513 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 },
@@ -296,6 +295,11 @@
296 "default": true, 295 "default": true,
297 "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`)"
298 }, 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 },
299 "rust-analyzer.inlayHints.typeHints": { 303 "rust-analyzer.inlayHints.typeHints": {
300 "type": "boolean", 304 "type": "boolean",
301 "default": true, 305 "default": true,
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 @@
1import * as fs from 'fs';
2import * as jsonc from 'jsonc-parser';
3import * as path from 'path';
4import * as vscode from 'vscode';
5
6export interface TextMateRuleSettings {
7 foreground?: string;
8 background?: string;
9 fontStyle?: string;
10}
11
12export 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
64function 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
96function 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
115interface TextMateRule {
116 scope: string | string[];
117 settings: TextMateRuleSettings;
118}
119
120function 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}