aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/config.rs38
1 files changed, 21 insertions, 17 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 28e221271..25df13554 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -16,7 +16,6 @@ use ide_db::helpers::{
16 insert_use::{InsertUseConfig, MergeBehavior}, 16 insert_use::{InsertUseConfig, MergeBehavior},
17 SnippetCap, 17 SnippetCap,
18}; 18};
19use itertools::Itertools;
20use lsp_types::{ClientCapabilities, MarkupKind}; 19use lsp_types::{ClientCapabilities, MarkupKind};
21use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource}; 20use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource};
22use rustc_hash::FxHashSet; 21use rustc_hash::FxHashSet;
@@ -98,13 +97,15 @@ config_data! {
98 diagnostics_enableExperimental: bool = "true", 97 diagnostics_enableExperimental: bool = "true",
99 /// List of rust-analyzer diagnostics to disable. 98 /// List of rust-analyzer diagnostics to disable.
100 diagnostics_disabled: FxHashSet<String> = "[]", 99 diagnostics_disabled: FxHashSet<String> = "[]",
101 /// List of warnings that should be displayed with info severity.\n\nThe 100 /// List of warnings that should be displayed with info severity.
102 /// warnings will be indicated by a blue squiggly underline in code and 101 ///
103 /// a blue icon in the `Problems Panel`. 102 /// The warnings will be indicated by a blue squiggly underline in code
103 /// and a blue icon in the `Problems Panel`.
104 diagnostics_warningsAsHint: Vec<String> = "[]", 104 diagnostics_warningsAsHint: Vec<String> = "[]",
105 /// List of warnings that should be displayed with hint severity.\n\nThe 105 /// List of warnings that should be displayed with hint severity.
106 /// warnings will be indicated by faded text or three dots in code and 106 ///
107 /// will not show up in the `Problems Panel`. 107 /// The warnings will be indicated by faded text or three dots in code
108 /// and will not show up in the `Problems Panel`.
108 diagnostics_warningsAsInfo: Vec<String> = "[]", 109 diagnostics_warningsAsInfo: Vec<String> = "[]",
109 110
110 /// Controls file watching implementation. 111 /// Controls file watching implementation.
@@ -158,7 +159,9 @@ config_data! {
158 lens_references: bool = "false", 159 lens_references: bool = "false",
159 160
160 /// Disable project auto-discovery in favor of explicitly specified set 161 /// Disable project auto-discovery in favor of explicitly specified set
161 /// of projects.\n\nElements must be paths pointing to `Cargo.toml`, 162 /// of projects.
163 ///
164 /// Elements must be paths pointing to `Cargo.toml`,
162 /// `rust-project.json`, or JSON objects in `rust-project.json` format. 165 /// `rust-project.json`, or JSON objects in `rust-project.json` format.
163 linkedProjects: Vec<ManifestOrProjectJson> = "[]", 166 linkedProjects: Vec<ManifestOrProjectJson> = "[]",
164 167
@@ -177,7 +180,7 @@ config_data! {
177 /// Command to be executed instead of 'cargo' for runnables. 180 /// Command to be executed instead of 'cargo' for runnables.
178 runnables_overrideCargo: Option<String> = "null", 181 runnables_overrideCargo: Option<String> = "null",
179 /// Additional arguments to be passed to cargo for runnables such as 182 /// Additional arguments to be passed to cargo for runnables such as
180 /// tests or binaries.\nFor example, it may be `--release`. 183 /// tests or binaries. For example, it may be `--release`.
181 runnables_cargoExtraArgs: Vec<String> = "[]", 184 runnables_cargoExtraArgs: Vec<String> = "[]",
182 185
183 /// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private 186 /// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
@@ -765,7 +768,8 @@ fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json:
765} 768}
766 769
767fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json::Value { 770fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json::Value {
768 let doc = doc.iter().map(|it| it.trim()).join(" "); 771 let doc = doc_comment_to_string(doc);
772 let doc = doc.trim_end_matches('\n');
769 assert!( 773 assert!(
770 doc.ends_with('.') && doc.starts_with(char::is_uppercase), 774 doc.ends_with('.') && doc.starts_with(char::is_uppercase),
771 "bad docs for {}: {:?}", 775 "bad docs for {}: {:?}",
@@ -854,11 +858,16 @@ fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String {
854 .iter() 858 .iter()
855 .map(|(field, _ty, doc, default)| { 859 .map(|(field, _ty, doc, default)| {
856 let name = format!("rust-analyzer.{}", field.replace("_", ".")); 860 let name = format!("rust-analyzer.{}", field.replace("_", "."));
857 format!("[[{}]]{} (default: `{}`)::\n{}\n", name, name, default, doc.join(" ")) 861 let doc = doc_comment_to_string(*doc);
862 format!("[[{}]]{} (default: `{}`)::\n+\n--\n{}--\n", name, name, default, doc)
858 }) 863 })
859 .collect::<String>() 864 .collect::<String>()
860} 865}
861 866
867fn doc_comment_to_string(doc: &[&str]) -> String {
868 doc.iter().map(|it| it.strip_prefix(' ').unwrap_or(it)).map(|it| format!("{}\n", it)).collect()
869}
870
862#[cfg(test)] 871#[cfg(test)]
863mod tests { 872mod tests {
864 use std::fs; 873 use std::fs;
@@ -901,13 +910,8 @@ mod tests {
901 #[test] 910 #[test]
902 fn generate_config_documentation() { 911 fn generate_config_documentation() {
903 let docs_path = project_root().join("docs/user/generated_config.adoc"); 912 let docs_path = project_root().join("docs/user/generated_config.adoc");
904 let current = fs::read_to_string(&docs_path).unwrap();
905 let expected = ConfigData::manual(); 913 let expected = ConfigData::manual();
906 914 ensure_file_contents(&docs_path, &expected);
907 if remove_ws(&current) != remove_ws(&expected) {
908 fs::write(&docs_path, expected).unwrap();
909 panic!("updated config manual");
910 }
911 } 915 }
912 916
913 fn remove_ws(text: &str) -> String { 917 fn remove_ws(text: &str) -> String {