Skip to content

Commit 0964374

Browse files
committed
Move diagnostics docs generation into xtask/codegen
1 parent 4e8cbf3 commit 0964374

File tree

7 files changed

+17
-24
lines changed

7 files changed

+17
-24
lines changed

Cargo.lock

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

crates/ide-assists/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@ expect-test = "1.4.0"
3333
test-utils.workspace = true
3434
test-fixture.workspace = true
3535

36-
[features]
37-
in-rust-tree = []
38-
3936
[lints]
4037
workspace = true

crates/ide-diagnostics/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ expect-test = "1.4.0"
3333
# local deps
3434
test-utils.workspace = true
3535
test-fixture.workspace = true
36-
sourcegen.workspace = true
37-
38-
[features]
39-
in-rust-tree = []
4036

4137
[lints]
4238
workspace = true

crates/ide/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,5 @@ expect-test = "1.4.0"
5151
test-utils.workspace = true
5252
test-fixture.workspace = true
5353

54-
[features]
55-
in-rust-tree = ["ide-assists/in-rust-tree", "ide-diagnostics/in-rust-tree"]
56-
5754
[lints]
5855
workspace = true

crates/rust-analyzer/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ force-always-assert = ["always-assert/force"]
8585
sysroot-abi = []
8686
in-rust-tree = [
8787
"sysroot-abi",
88-
"ide/in-rust-tree",
8988
"syntax/in-rust-tree",
9089
"parser/in-rust-tree",
9190
"hir/in-rust-tree",

xtask/src/codegen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use xshell::{cmd, Shell};
88
use crate::{flags, project_root};
99

1010
pub(crate) mod assists_doc_tests;
11+
pub(crate) mod diagnostics_docs;
1112

1213
impl flags::Codegen {
1314
pub(crate) fn run(self, _sh: &Shell) -> anyhow::Result<()> {

crates/ide-diagnostics/src/tests/sourcegen.rs renamed to xtask/src/codegen/diagnostics_docs.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
33
use std::{fmt, fs, io, path::PathBuf};
44

5-
use sourcegen::project_root;
5+
use crate::{
6+
codegen::{add_preamble, list_rust_files, CommentBlock, Location},
7+
project_root,
8+
};
69

7-
#[test]
8-
fn sourcegen_diagnostic_docs() {
10+
fn generate(check: bool) {
911
let diagnostics = Diagnostic::collect().unwrap();
10-
let contents =
11-
diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
12-
let contents = sourcegen::add_preamble("sourcegen_diagnostic_docs", contents);
13-
let dst = project_root().join("docs/user/generated_diagnostic.adoc");
14-
fs::write(dst, contents).unwrap();
12+
if !check {
13+
let contents =
14+
diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
15+
let contents = add_preamble("sourcegen_diagnostic_docs", contents);
16+
let dst = project_root().join("docs/user/generated_diagnostic.adoc");
17+
fs::write(dst, contents).unwrap();
18+
}
1519
}
1620

1721
#[derive(Debug)]
1822
struct Diagnostic {
1923
id: String,
20-
location: sourcegen::Location,
24+
location: Location,
2125
doc: String,
2226
}
2327

@@ -26,23 +30,23 @@ impl Diagnostic {
2630
let handlers_dir = project_root().join("crates/ide-diagnostics/src/handlers");
2731

2832
let mut res = Vec::new();
29-
for path in sourcegen::list_rust_files(&handlers_dir) {
33+
for path in list_rust_files(&handlers_dir) {
3034
collect_file(&mut res, path)?;
3135
}
3236
res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
3337
return Ok(res);
3438

3539
fn collect_file(acc: &mut Vec<Diagnostic>, path: PathBuf) -> io::Result<()> {
3640
let text = fs::read_to_string(&path)?;
37-
let comment_blocks = sourcegen::CommentBlock::extract("Diagnostic", &text);
41+
let comment_blocks = CommentBlock::extract("Diagnostic", &text);
3842

3943
for block in comment_blocks {
4044
let id = block.id;
4145
if let Err(msg) = is_valid_diagnostic_name(&id) {
4246
panic!("invalid diagnostic name: {id:?}:\n {msg}")
4347
}
4448
let doc = block.contents.join("\n");
45-
let location = sourcegen::Location { file: path.clone(), line: block.line };
49+
let location = Location { file: path.clone(), line: block.line };
4650
acc.push(Diagnostic { id, location, doc })
4751
}
4852

0 commit comments

Comments
 (0)