Skip to content

Commit 5e0e530

Browse files
bors[bot]matklad
andauthored
Merge #7932
7932: Make code less surprising r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents ffba4c0 + 37b7b56 commit 5e0e530

File tree

3 files changed

+310
-98
lines changed

3 files changed

+310
-98
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use ide_db::helpers::{
1616
insert_use::{InsertUseConfig, MergeBehavior},
1717
SnippetCap,
1818
};
19-
use itertools::Itertools;
2019
use lsp_types::{ClientCapabilities, MarkupKind};
2120
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource};
2221
use rustc_hash::FxHashSet;
@@ -98,13 +97,15 @@ config_data! {
9897
diagnostics_enableExperimental: bool = "true",
9998
/// List of rust-analyzer diagnostics to disable.
10099
diagnostics_disabled: FxHashSet<String> = "[]",
101-
/// List of warnings that should be displayed with info severity.\n\nThe
102-
/// warnings will be indicated by a blue squiggly underline in code and
103-
/// a blue icon in the `Problems Panel`.
100+
/// List of warnings that should be displayed with info severity.
101+
///
102+
/// The warnings will be indicated by a blue squiggly underline in code
103+
/// and a blue icon in the `Problems Panel`.
104104
diagnostics_warningsAsHint: Vec<String> = "[]",
105-
/// List of warnings that should be displayed with hint severity.\n\nThe
106-
/// warnings will be indicated by faded text or three dots in code and
107-
/// will not show up in the `Problems Panel`.
105+
/// List of warnings that should be displayed with hint severity.
106+
///
107+
/// The warnings will be indicated by faded text or three dots in code
108+
/// and will not show up in the `Problems Panel`.
108109
diagnostics_warningsAsInfo: Vec<String> = "[]",
109110

110111
/// Controls file watching implementation.
@@ -158,7 +159,9 @@ config_data! {
158159
lens_references: bool = "false",
159160

160161
/// 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`,
162165
/// `rust-project.json`, or JSON objects in `rust-project.json` format.
163166
linkedProjects: Vec<ManifestOrProjectJson> = "[]",
164167

@@ -177,7 +180,7 @@ config_data! {
177180
/// Command to be executed instead of 'cargo' for runnables.
178181
runnables_overrideCargo: Option<String> = "null",
179182
/// 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`.
181184
runnables_cargoExtraArgs: Vec<String> = "[]",
182185

183186
/// 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:
765768
}
766769

767770
fn 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');
769773
assert!(
770774
doc.ends_with('.') && doc.starts_with(char::is_uppercase),
771775
"bad docs for {}: {:?}",
@@ -854,11 +858,16 @@ fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String {
854858
.iter()
855859
.map(|(field, _ty, doc, default)| {
856860
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)
858863
})
859864
.collect::<String>()
860865
}
861866

867+
fn 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+
862871
#[cfg(test)]
863872
mod tests {
864873
use std::fs;
@@ -901,13 +910,8 @@ mod tests {
901910
#[test]
902911
fn generate_config_documentation() {
903912
let docs_path = project_root().join("docs/user/generated_config.adoc");
904-
let current = fs::read_to_string(&docs_path).unwrap();
905913
let expected = ConfigData::manual();
906-
907-
if remove_ws(&current) != remove_ws(&expected) {
908-
fs::write(&docs_path, expected).unwrap();
909-
panic!("updated config manual");
910-
}
914+
ensure_file_contents(&docs_path, &expected);
911915
}
912916

913917
fn remove_ws(text: &str) -> String {

0 commit comments

Comments
 (0)