|
2 | 2 | //! and lints from rustc, rustdoc, and clippy. |
3 | 3 | use std::{borrow::Cow, fs, path::Path}; |
4 | 4 |
|
5 | | -use itertools::Itertools; |
6 | 5 | use stdx::format_to; |
7 | | -use test_utils::project_root; |
8 | 6 | use xshell::{cmd, Shell}; |
9 | 7 |
|
| 8 | +use crate::{ |
| 9 | + codegen::{add_preamble, ensure_file_contents, list_files, reformat}, |
| 10 | + project_root, |
| 11 | +}; |
| 12 | + |
10 | 13 | const DESTINATION: &str = "crates/ide-db/src/generated/lints.rs"; |
11 | 14 |
|
12 | | -/// This clones rustc repo, and so is not worth to keep up-to-date. We update |
13 | | -/// manually by un-ignoring the test from time to time. |
14 | | -#[test] |
15 | | -#[ignore] |
16 | | -fn sourcegen_lint_completions() { |
| 15 | +/// This clones rustc repo, and so is not worth to keep up-to-date on a constant basis. |
| 16 | +pub(crate) fn generate(check: bool) { |
17 | 17 | let sh = &Shell::new().unwrap(); |
18 | 18 |
|
19 | 19 | let rust_repo = project_root().join("./target/rust"); |
@@ -73,10 +73,10 @@ pub struct LintGroup { |
73 | 73 | .unwrap(); |
74 | 74 | generate_descriptor_clippy(&mut contents, &lints_json); |
75 | 75 |
|
76 | | - let contents = sourcegen::add_preamble("sourcegen_lints", sourcegen::reformat(contents)); |
| 76 | + let contents = add_preamble("sourcegen_lints", reformat(contents)); |
77 | 77 |
|
78 | 78 | let destination = project_root().join(DESTINATION); |
79 | | - sourcegen::ensure_file_contents(destination.as_path(), &contents); |
| 79 | + ensure_file_contents(destination.as_path(), &contents, check); |
80 | 80 | } |
81 | 81 |
|
82 | 82 | /// Parses the output of `rustdoc -Whelp` and prints `Lint` and `LintGroup` constants into `buf`. |
@@ -130,10 +130,9 @@ fn generate_lint_descriptor(sh: &Shell, buf: &mut String) { |
130 | 130 | ) |
131 | 131 | }); |
132 | 132 |
|
133 | | - let lints = lints |
134 | | - .chain(lint_groups) |
135 | | - .sorted_by(|(ident, ..), (ident2, ..)| ident.cmp(ident2)) |
136 | | - .collect::<Vec<_>>(); |
| 133 | + let mut lints = lints.chain(lint_groups).collect::<Vec<_>>(); |
| 134 | + lints.sort_by(|(ident, ..), (ident2, ..)| ident.cmp(ident2)); |
| 135 | + |
137 | 136 | for (name, description, ..) in &lints { |
138 | 137 | push_lint_completion(buf, &name.replace('-', "_"), description); |
139 | 138 | } |
@@ -177,10 +176,8 @@ fn generate_lint_descriptor(sh: &Shell, buf: &mut String) { |
177 | 176 | ) |
178 | 177 | }); |
179 | 178 |
|
180 | | - let lints_rustdoc = lints_rustdoc |
181 | | - .chain(lint_groups_rustdoc) |
182 | | - .sorted_by(|(ident, ..), (ident2, ..)| ident.cmp(ident2)) |
183 | | - .collect::<Vec<_>>(); |
| 179 | + let mut lints_rustdoc = lints_rustdoc.chain(lint_groups_rustdoc).collect::<Vec<_>>(); |
| 180 | + lints_rustdoc.sort_by(|(ident, ..), (ident2, ..)| ident.cmp(ident2)); |
184 | 181 |
|
185 | 182 | for (name, description, ..) in &lints_rustdoc { |
186 | 183 | push_lint_completion(buf, &name.replace('-', "_"), description) |
@@ -212,7 +209,7 @@ fn find_and_slice<'a>(i: &'a str, p: &str) -> &'a str { |
212 | 209 | fn generate_feature_descriptor(buf: &mut String, src_dir: &Path) { |
213 | 210 | let mut features = ["language-features", "library-features"] |
214 | 211 | .into_iter() |
215 | | - .flat_map(|it| sourcegen::list_files(&src_dir.join(it))) |
| 212 | + .flat_map(|it| list_files(&src_dir.join(it))) |
216 | 213 | // Get all `.md` files |
217 | 214 | .filter(|path| path.extension() == Some("md".as_ref())) |
218 | 215 | .map(|path| { |
@@ -302,7 +299,7 @@ fn generate_descriptor_clippy(buf: &mut String, path: &Path) { |
302 | 299 | let children = children.iter().map(|id| format!("clippy::{id}")).collect::<Vec<_>>(); |
303 | 300 | if !children.is_empty() { |
304 | 301 | let lint_ident = format!("clippy::{id}"); |
305 | | - let description = format!("lint group for: {}", children.iter().join(", ")); |
| 302 | + let description = format!("lint group for: {}", children.join(", ")); |
306 | 303 | push_lint_group(buf, &lint_ident, &description, &children); |
307 | 304 | } |
308 | 305 | } |
@@ -331,7 +328,10 @@ fn push_lint_group(buf: &mut String, label: &str, description: &str, children: & |
331 | 328 |
|
332 | 329 | push_lint_completion(buf, label, description); |
333 | 330 |
|
334 | | - let children = format!("&[{}]", children.iter().map(|it| format!("\"{it}\"")).join(", ")); |
| 331 | + let children = format!( |
| 332 | + "&[{}]", |
| 333 | + children.iter().map(|it| format!("\"{it}\"")).collect::<Vec<_>>().join(", ") |
| 334 | + ); |
335 | 335 | format_to!( |
336 | 336 | buf, |
337 | 337 | r###" |
|
0 commit comments