aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-12-09 12:07:37 +0000
committerAleksey Kladov <[email protected]>2020-12-09 12:31:10 +0000
commit0890512e1c898c9c4c271df12d43353f3b64daf3 (patch)
treee658d5553f1f116ab738326dd76b397a938f7e57 /crates
parentcd83ded8ee89e79d6b446518c3d74f6c18f8f5d9 (diff)
Include config into the manual
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/config.rs75
1 files changed, 57 insertions, 18 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 345a56978..bd41a971b 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -637,6 +637,17 @@ macro_rules! _config_data {
637 },)* 637 },)*
638 ]) 638 ])
639 } 639 }
640
641 #[cfg(test)]
642 fn manual() -> String {
643 manual(&[
644 $({
645 let field = stringify!($field);
646 let ty = stringify!($ty);
647 (field, ty, &[$($doc),*], $default)
648 },)*
649 ])
650 }
640 } 651 }
641 }; 652 };
642} 653}
@@ -753,26 +764,54 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
753 map.into() 764 map.into()
754} 765}
755 766
756#[test] 767#[cfg(test)]
757fn schema_in_sync_with_package_json() { 768fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String {
758 fn remove_ws(text: &str) -> String { 769 fields
759 text.replace(char::is_whitespace, "") 770 .iter()
760 } 771 .map(|(field, _ty, doc, default)| {
772 let name = field.replace("_", ".");
773 let name = format!("rust-analyzer.{} (default: `{}`)", name, default);
774 format!("{}::\n{}\n", name, doc.join(" "))
775 })
776 .collect::<String>()
777}
778
779#[cfg(test)]
780mod tests {
781 use std::fs;
782
783 use test_utils::project_dir;
784
785 use super::*;
761 786
762 let s = Config::json_schema(); 787 #[test]
763 let schema = format!("{:#}", s); 788 fn schema_in_sync_with_package_json() {
764 let schema = schema.trim_start_matches('{').trim_end_matches('}'); 789 let s = Config::json_schema();
790 let schema = format!("{:#}", s);
791 let schema = schema.trim_start_matches('{').trim_end_matches('}');
765 792
766 let package_json = std::env::current_dir() 793 let package_json = project_dir().join("editors/code/package.json");
767 .unwrap() 794 let package_json = fs::read_to_string(&package_json).unwrap();
768 .ancestors() 795
769 .nth(2) 796 let p = remove_ws(&package_json);
770 .unwrap() 797 let s = remove_ws(&schema);
771 .join("editors/code/package.json"); 798
772 let package_json = std::fs::read_to_string(&package_json).unwrap(); 799 assert!(p.contains(&s), "update config in package.json. New config:\n{:#}", schema);
800 }
773 801
774 let p = remove_ws(&package_json); 802 #[test]
775 let s = remove_ws(&schema); 803 fn schema_in_sync_with_docs() {
804 let docs_path = project_dir().join("docs/user/generated_config.adoc");
805 let current = fs::read_to_string(&docs_path).unwrap();
806 let expected = ConfigData::manual();
776 807
777 assert!(p.contains(&s), "update config in package.json. New config:\n{:#}", schema); 808 if remove_ws(&current) != remove_ws(&expected) {
809 fs::write(&docs_path, expected).unwrap();
810 panic!("updated config manual");
811 }
812 }
813
814 fn remove_ws(text: &str) -> String {
815 text.replace(char::is_whitespace, "")
816 }
778} 817}