Skip to content

Commit 1cca1fa

Browse files
bors[bot]Veykril
andauthored
Merge #10525
10525: Regenerate lints and features r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 098284a + 22f471d commit 1cca1fa

File tree

7 files changed

+458
-184
lines changed

7 files changed

+458
-184
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide_completion/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ mod pattern;
1717
mod predicate;
1818
mod proc_macros;
1919
mod record;
20-
mod sourcegen;
2120
mod type_pos;
2221
mod use_tree;
2322
mod visibility;

crates/ide_db/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ limit = { path = "../limit", version = "0.0.0" }
3131

3232
[dev-dependencies]
3333
test_utils = { path = "../test_utils" }
34+
sourcegen = { path = "../sourcegen" }
35+
xshell = "0.1"
3436
expect-test = "1.2.0-pre.1"

crates/ide_db/src/helpers/generated_lints.rs

Lines changed: 430 additions & 160 deletions
Large diffs are not rendered by default.

crates/ide_db/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
44
55
mod apply_change;
6+
67
pub mod assists;
78
pub mod label;
89
pub mod line_index;
@@ -161,3 +162,8 @@ pub enum SymbolKind {
161162
ValueParam,
162163
Variant,
163164
}
165+
166+
#[cfg(test)]
167+
mod tests {
168+
mod sourcegen_lints;
169+
}

crates/ide_completion/src/tests/sourcegen.rs renamed to crates/ide_db/src/tests/sourcegen_lints.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ fn sourcegen_lint_completions() {
1515
cmd!("git clone --depth=1 https://github.com/rust-lang/rust {rust_repo}").run().unwrap();
1616
}
1717

18-
let mut contents = r"
18+
let mut contents = String::from(
19+
r"
1920
pub struct Lint {
2021
pub label: &'static str,
2122
pub description: &'static str,
2223
}
23-
"
24-
.to_string();
24+
",
25+
);
26+
2527
generate_lint_descriptor(&mut contents);
2628
contents.push('\n');
2729

@@ -34,8 +36,7 @@ pub struct Lint {
3436
.unwrap();
3537
generate_descriptor_clippy(&mut contents, &lints_json);
3638

37-
let contents =
38-
sourcegen::add_preamble("sourcegen_lint_completions", sourcegen::reformat(contents));
39+
let contents = sourcegen::add_preamble("sourcegen_lints", sourcegen::reformat(contents));
3940

4041
let destination = project_root().join("crates/ide_db/src/helpers/generated_lints.rs");
4142
sourcegen::ensure_file_contents(destination.as_path(), &contents);
@@ -117,29 +118,23 @@ fn generate_descriptor_clippy(buf: &mut String, path: &Path) {
117118
let mut clippy_lints: Vec<ClippyLint> = Vec::new();
118119

119120
for line in file_content.lines().map(|line| line.trim()) {
120-
if line.starts_with(r#""id":"#) {
121+
if let Some(line) = line.strip_prefix(r#""id": ""#) {
121122
let clippy_lint = ClippyLint {
122-
id: line
123-
.strip_prefix(r#""id": ""#)
124-
.expect("should be prefixed by id")
125-
.strip_suffix(r#"","#)
126-
.expect("should be suffixed by comma")
127-
.into(),
123+
id: line.strip_suffix(r#"","#).expect("should be suffixed by comma").into(),
128124
help: String::new(),
129125
};
130126
clippy_lints.push(clippy_lint)
131-
} else if line.starts_with(r#""What it does":"#) {
132-
// Typical line to strip: "What is doest": "Here is my useful content",
133-
let prefix_to_strip = r#""What it does": ""#;
134-
let suffix_to_strip = r#"","#;
127+
} else if let Some(line) = line.strip_prefix(r#""docs": ""#) {
128+
let prefix_to_strip = r#" ### What it does"#;
129+
// FIXME: replace unwrap_or with expect again, currently there is one lint that uses a different format in the json...
130+
let line = line.strip_prefix(prefix_to_strip).unwrap_or(line);
131+
// Only take the description, any more than this is a lot of additional data we would embed into the exe
132+
// which seems unnecessary
133+
let up_to = line.find(r#"###"#).expect("no second section found?");
134+
let line = &line[..up_to];
135135

136136
let clippy_lint = clippy_lints.last_mut().expect("clippy lint must already exist");
137-
clippy_lint.help = line
138-
.strip_prefix(prefix_to_strip)
139-
.expect("should be prefixed by what it does")
140-
.strip_suffix(suffix_to_strip)
141-
.map(unescape)
142-
.expect("should be suffixed by comma");
137+
clippy_lint.help = unescape(line).trim().to_string();
143138
}
144139
}
145140
clippy_lints.sort_by(|lint, lint2| lint.id.cmp(&lint2.id));

crates/rust-analyzer/tests/slow-tests/tidy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ fn check_test_attrs(path: &Path, text: &str) {
342342
// :(
343343
"hir_def/src/nameres/collector.rs",
344344
// Long sourcegen test to generate lint completions.
345-
"ide_completion/src/tests/sourcegen.rs",
345+
"ide_db/src/tests/sourcegen_lints.rs",
346346
// Obviously needs ignore.
347347
"ide_assists/src/handlers/toggle_ignore.rs",
348348
// See above.

0 commit comments

Comments
 (0)