aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-01-26 13:03:24 +0000
committerAleksey Kladov <[email protected]>2021-01-26 13:22:24 +0000
commitc04b561e7e7d031d7e1be9307fb8d539765768ff (patch)
treeae162d1da52b375e1a1bf88f5de56b5021c38d79
parent21660f1d979be43af579277ef487118d68533d41 (diff)
Remove the need to manually sync config in package.json
-rw-r--r--crates/rust-analyzer/src/config.rs39
-rw-r--r--docs/user/generated_config.adoc8
-rw-r--r--editors/code/package.json12
3 files changed, 39 insertions, 20 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 247bfe71e..071fde64d 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -39,7 +39,7 @@ config_data! {
39 /// Automatically refresh project info via `cargo metadata` on 39 /// Automatically refresh project info via `cargo metadata` on
40 /// `Cargo.toml` changes. 40 /// `Cargo.toml` changes.
41 cargo_autoreload: bool = "true", 41 cargo_autoreload: bool = "true",
42 /// Activate all available features. 42 /// Activate all available features (`--all-features`).
43 cargo_allFeatures: bool = "false", 43 cargo_allFeatures: bool = "false",
44 /// List of features to activate. 44 /// List of features to activate.
45 cargo_features: Vec<String> = "[]", 45 cargo_features: Vec<String> = "[]",
@@ -55,10 +55,10 @@ config_data! {
55 55
56 /// Run specified `cargo check` command for diagnostics on save. 56 /// Run specified `cargo check` command for diagnostics on save.
57 checkOnSave_enable: bool = "true", 57 checkOnSave_enable: bool = "true",
58 /// Check with all features (will be passed as `--all-features`). 58 /// Check with all features (`--all-features`).
59 /// Defaults to `#rust-analyzer.cargo.allFeatures#`. 59 /// Defaults to `#rust-analyzer.cargo.allFeatures#`.
60 checkOnSave_allFeatures: Option<bool> = "null", 60 checkOnSave_allFeatures: Option<bool> = "null",
61 /// Check all targets and tests (will be passed as `--all-targets`). 61 /// Check all targets and tests (`--all-targets`).
62 checkOnSave_allTargets: bool = "true", 62 checkOnSave_allTargets: bool = "true",
63 /// Cargo command to use for `cargo check`. 63 /// Cargo command to use for `cargo check`.
64 checkOnSave_command: String = "\"check\"", 64 checkOnSave_command: String = "\"check\"",
@@ -156,7 +156,7 @@ config_data! {
156 /// `rust-project.json`, or JSON objects in `rust-project.json` format. 156 /// `rust-project.json`, or JSON objects in `rust-project.json` format.
157 linkedProjects: Vec<ManifestOrProjectJson> = "[]", 157 linkedProjects: Vec<ManifestOrProjectJson> = "[]",
158 158
159 /// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. 159 /// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
160 lruCapacity: Option<usize> = "null", 160 lruCapacity: Option<usize> = "null",
161 161
162 /// Whether to show `can't find Cargo.toml` error message. 162 /// Whether to show `can't find Cargo.toml` error message.
@@ -844,15 +844,32 @@ mod tests {
844 fn schema_in_sync_with_package_json() { 844 fn schema_in_sync_with_package_json() {
845 let s = Config::json_schema(); 845 let s = Config::json_schema();
846 let schema = format!("{:#}", s); 846 let schema = format!("{:#}", s);
847 let schema = schema.trim_start_matches('{').trim_end_matches('}'); 847 let mut schema = schema
848 848 .trim_start_matches('{')
849 let package_json = project_dir().join("editors/code/package.json"); 849 .trim_end_matches('}')
850 let package_json = fs::read_to_string(&package_json).unwrap(); 850 .replace(" ", " ")
851 851 .replace("\n", "\n ")
852 let p = remove_ws(&package_json); 852 .trim_start_matches('\n')
853 .trim_end()
854 .to_string();
855 schema.push_str(",\n");
856
857 let package_json_path = project_dir().join("editors/code/package.json");
858 let mut package_json = fs::read_to_string(&package_json_path).unwrap();
859
860 let start_marker = " \"$generated-start\": false,\n";
861 let end_marker = " \"$generated-end\": false\n";
862
863 let start = package_json.find(start_marker).unwrap() + start_marker.len();
864 let end = package_json.find(end_marker).unwrap();
865 let p = remove_ws(&package_json[start..end]);
853 let s = remove_ws(&schema); 866 let s = remove_ws(&schema);
854 867
855 assert!(p.contains(&s), "update config in package.json. New config:\n{:#}", schema); 868 if !p.contains(&s) {
869 package_json.replace_range(start..end, &schema);
870 fs::write(&package_json_path, &mut package_json).unwrap();
871 panic!("new config, updating package.json")
872 }
856 } 873 }
857 874
858 #[test] 875 #[test]
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 2f681b01a..1974082da 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -7,7 +7,7 @@
7[[rust-analyzer.cargo.autoreload]]rust-analyzer.cargo.autoreload (default: `true`):: 7[[rust-analyzer.cargo.autoreload]]rust-analyzer.cargo.autoreload (default: `true`)::
8 Automatically refresh project info via `cargo metadata` on `Cargo.toml` changes. 8 Automatically refresh project info via `cargo metadata` on `Cargo.toml` changes.
9[[rust-analyzer.cargo.allFeatures]]rust-analyzer.cargo.allFeatures (default: `false`):: 9[[rust-analyzer.cargo.allFeatures]]rust-analyzer.cargo.allFeatures (default: `false`)::
10 Activate all available features. 10 Activate all available features (`--all-features`).
11[[rust-analyzer.cargo.features]]rust-analyzer.cargo.features (default: `[]`):: 11[[rust-analyzer.cargo.features]]rust-analyzer.cargo.features (default: `[]`)::
12 List of features to activate. 12 List of features to activate.
13[[rust-analyzer.cargo.loadOutDirsFromCheck]]rust-analyzer.cargo.loadOutDirsFromCheck (default: `false`):: 13[[rust-analyzer.cargo.loadOutDirsFromCheck]]rust-analyzer.cargo.loadOutDirsFromCheck (default: `false`)::
@@ -21,9 +21,9 @@
21[[rust-analyzer.checkOnSave.enable]]rust-analyzer.checkOnSave.enable (default: `true`):: 21[[rust-analyzer.checkOnSave.enable]]rust-analyzer.checkOnSave.enable (default: `true`)::
22 Run specified `cargo check` command for diagnostics on save. 22 Run specified `cargo check` command for diagnostics on save.
23[[rust-analyzer.checkOnSave.allFeatures]]rust-analyzer.checkOnSave.allFeatures (default: `null`):: 23[[rust-analyzer.checkOnSave.allFeatures]]rust-analyzer.checkOnSave.allFeatures (default: `null`)::
24 Check with all features (will be passed as `--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`. 24 Check with all features (`--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`.
25[[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`):: 25[[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`)::
26 Check all targets and tests (will be passed as `--all-targets`). 26 Check all targets and tests (`--all-targets`).
27[[rust-analyzer.checkOnSave.command]]rust-analyzer.checkOnSave.command (default: `"check"`):: 27[[rust-analyzer.checkOnSave.command]]rust-analyzer.checkOnSave.command (default: `"check"`)::
28 Cargo command to use for `cargo check`. 28 Cargo command to use for `cargo check`.
29[[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`):: 29[[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`)::
@@ -91,7 +91,7 @@
91[[rust-analyzer.linkedProjects]]rust-analyzer.linkedProjects (default: `[]`):: 91[[rust-analyzer.linkedProjects]]rust-analyzer.linkedProjects (default: `[]`)::
92 Disable project auto-discovery in favor of explicitly specified set of projects.\n\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format. 92 Disable project auto-discovery in favor of explicitly specified set of projects.\n\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format.
93[[rust-analyzer.lruCapacity]]rust-analyzer.lruCapacity (default: `null`):: 93[[rust-analyzer.lruCapacity]]rust-analyzer.lruCapacity (default: `null`)::
94 Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. 94 Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
95[[rust-analyzer.notifications.cargoTomlNotFound]]rust-analyzer.notifications.cargoTomlNotFound (default: `true`):: 95[[rust-analyzer.notifications.cargoTomlNotFound]]rust-analyzer.notifications.cargoTomlNotFound (default: `true`)::
96 Whether to show `can't find Cargo.toml` error message. 96 Whether to show `can't find Cargo.toml` error message.
97[[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `false`):: 97[[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `false`)::
diff --git a/editors/code/package.json b/editors/code/package.json
index 2225cf1dd..ee54638f1 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -349,6 +349,7 @@
349 "default": {}, 349 "default": {},
350 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`" 350 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`"
351 }, 351 },
352 "$generated-start": false,
352 "rust-analyzer.assist.importMergeBehavior": { 353 "rust-analyzer.assist.importMergeBehavior": {
353 "markdownDescription": "The strategy to use when inserting new imports or merging imports.", 354 "markdownDescription": "The strategy to use when inserting new imports or merging imports.",
354 "default": "full", 355 "default": "full",
@@ -390,7 +391,7 @@
390 "type": "boolean" 391 "type": "boolean"
391 }, 392 },
392 "rust-analyzer.cargo.allFeatures": { 393 "rust-analyzer.cargo.allFeatures": {
393 "markdownDescription": "Activate all available features.", 394 "markdownDescription": "Activate all available features (`--all-features`).",
394 "default": false, 395 "default": false,
395 "type": "boolean" 396 "type": "boolean"
396 }, 397 },
@@ -431,7 +432,7 @@
431 "type": "boolean" 432 "type": "boolean"
432 }, 433 },
433 "rust-analyzer.checkOnSave.allFeatures": { 434 "rust-analyzer.checkOnSave.allFeatures": {
434 "markdownDescription": "Check with all features (will be passed as `--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`.", 435 "markdownDescription": "Check with all features (`--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`.",
435 "default": null, 436 "default": null,
436 "type": [ 437 "type": [
437 "null", 438 "null",
@@ -439,7 +440,7 @@
439 ] 440 ]
440 }, 441 },
441 "rust-analyzer.checkOnSave.allTargets": { 442 "rust-analyzer.checkOnSave.allTargets": {
442 "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`).", 443 "markdownDescription": "Check all targets and tests (`--all-targets`).",
443 "default": true, 444 "default": true,
444 "type": "boolean" 445 "type": "boolean"
445 }, 446 },
@@ -650,7 +651,7 @@
650 } 651 }
651 }, 652 },
652 "rust-analyzer.lruCapacity": { 653 "rust-analyzer.lruCapacity": {
653 "markdownDescription": "Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.", 654 "markdownDescription": "Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.",
654 "default": null, 655 "default": null,
655 "type": [ 656 "type": [
656 "null", 657 "null",
@@ -718,7 +719,8 @@
718 "items": { 719 "items": {
719 "type": "string" 720 "type": "string"
720 } 721 }
721 } 722 },
723 "$generated-end": false
722 } 724 }
723 }, 725 },
724 "problemPatterns": [ 726 "problemPatterns": [