Skip to content

Commit f682627

Browse files
bors[bot]lnicola
andauthored
Merge #7797
7797: Format generated lints and features manually r=matklad a=lnicola As `quote` and `rustfmt` leave them on a single line, which makes running `grep` in the repository quite annoying. Also removes a dead `gen_features.rs` file (`gen_lint_completions.rs` does the same thing). Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2 parents a8cf346 + 351670f commit f682627

File tree

3 files changed

+6411
-82
lines changed

3 files changed

+6411
-82
lines changed

crates/ide_completion/src/generated_lint_completions.rs

Lines changed: 6377 additions & 2 deletions
Large diffs are not rendered by default.

xtask/src/codegen/gen_features.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Generates descriptors structure for unstable feature from Unstable Book
2+
use std::fmt::Write;
23
use std::path::{Path, PathBuf};
34

4-
use quote::quote;
55
use walkdir::WalkDir;
66
use xshell::{cmd, read_file};
77

@@ -15,16 +15,13 @@ pub fn generate_lint_completions(mode: Mode) -> Result<()> {
1515
cmd!("git clone --depth=1 https://github.com/rust-lang/rust ./target/rust").run()?;
1616
}
1717

18-
let ts_features = generate_descriptor("./target/rust/src/doc/unstable-book/src".into())?;
19-
cmd!("curl http://rust-lang.github.io/rust-clippy/master/lints.json --output ./target/clippy_lints.json").run()?;
18+
let mut contents = String::from("use crate::completions::attribute::LintCompletion;\n\n");
19+
generate_descriptor(&mut contents, "./target/rust/src/doc/unstable-book/src".into())?;
20+
contents.push('\n');
2021

21-
let ts_clippy = generate_descriptor_clippy(&Path::new("./target/clippy_lints.json"))?;
22-
let ts = quote! {
23-
use crate::completions::attribute::LintCompletion;
24-
#ts_features
25-
#ts_clippy
26-
};
27-
let contents = reformat(ts.to_string().as_str())?;
22+
cmd!("curl http://rust-lang.github.io/rust-clippy/master/lints.json --output ./target/clippy_lints.json").run()?;
23+
generate_descriptor_clippy(&mut contents, &Path::new("./target/clippy_lints.json"))?;
24+
let contents = reformat(&contents)?;
2825

2926
let destination =
3027
project_root().join("crates/ide_completion/src/generated_lint_completions.rs");
@@ -34,30 +31,26 @@ pub fn generate_lint_completions(mode: Mode) -> Result<()> {
3431
Ok(())
3532
}
3633

37-
fn generate_descriptor(src_dir: PathBuf) -> Result<proc_macro2::TokenStream> {
38-
let definitions = ["language-features", "library-features"]
34+
fn generate_descriptor(buf: &mut String, src_dir: PathBuf) -> Result<()> {
35+
buf.push_str(r#"pub(super) const FEATURES: &[LintCompletion] = &["#);
36+
buf.push('\n');
37+
["language-features", "library-features"]
3938
.iter()
4039
.flat_map(|it| WalkDir::new(src_dir.join(it)))
4140
.filter_map(|e| e.ok())
4241
.filter(|entry| {
4342
// Get all `.md ` files
4443
entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md"
4544
})
46-
.map(|entry| {
45+
.for_each(|entry| {
4746
let path = entry.path();
4847
let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_");
4948
let doc = read_file(path).unwrap();
5049

51-
quote! { LintCompletion { label: #feature_ident, description: #doc } }
50+
push_lint_completion(buf, &feature_ident, &doc);
5251
});
53-
54-
let ts = quote! {
55-
pub(super) const FEATURES: &[LintCompletion] = &[
56-
#(#definitions),*
57-
];
58-
};
59-
60-
Ok(ts)
52+
buf.push_str("];\n");
53+
Ok(())
6154
}
6255

6356
#[derive(Default)]
@@ -66,7 +59,7 @@ struct ClippyLint {
6659
id: String,
6760
}
6861

69-
fn generate_descriptor_clippy(path: &Path) -> Result<proc_macro2::TokenStream> {
62+
fn generate_descriptor_clippy(buf: &mut String, path: &Path) -> Result<()> {
7063
let file_content = read_file(path)?;
7164
let mut clippy_lints: Vec<ClippyLint> = vec![];
7265

@@ -97,18 +90,27 @@ fn generate_descriptor_clippy(path: &Path) -> Result<proc_macro2::TokenStream> {
9790
}
9891
}
9992

100-
let definitions = clippy_lints.into_iter().map(|clippy_lint| {
93+
buf.push_str(r#"pub(super) const CLIPPY_LINTS: &[LintCompletion] = &["#);
94+
buf.push('\n');
95+
clippy_lints.into_iter().for_each(|clippy_lint| {
10196
let lint_ident = format!("clippy::{}", clippy_lint.id);
10297
let doc = clippy_lint.help;
103-
104-
quote! { LintCompletion { label: #lint_ident, description: #doc } }
98+
push_lint_completion(buf, &lint_ident, &doc);
10599
});
106100

107-
let ts = quote! {
108-
pub(super) const CLIPPY_LINTS: &[LintCompletion] = &[
109-
#(#definitions),*
110-
];
111-
};
101+
buf.push_str("];\n");
102+
103+
Ok(())
104+
}
112105

113-
Ok(ts)
106+
fn push_lint_completion(buf: &mut String, label: &str, description: &str) {
107+
writeln!(
108+
buf,
109+
r###" LintCompletion {{
110+
label: "{}",
111+
description: r##"{}"##
112+
}},"###,
113+
label, description
114+
)
115+
.unwrap();
114116
}

0 commit comments

Comments
 (0)