Skip to content

Commit 2d14f47

Browse files
committed
Move feature-doc generation to xtask codegen
1 parent 4465fff commit 2d14f47

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,6 @@ dependencies = [
12441244
"expect-test",
12451245
"limit",
12461246
"ra-ap-rustc_lexer",
1247-
"sourcegen",
12481247
"stdx",
12491248
"tracing",
12501249
]

src/tools/rust-analyzer/crates/parser/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ tracing = { workspace = true, optional = true }
2121
expect-test = "1.4.0"
2222

2323
stdx.workspace = true
24-
sourcegen.workspace = true
2524

2625
[features]
2726
default = ["tracing"]

src/tools/rust-analyzer/xtask/src/codegen.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212

1313
pub(crate) mod assists_doc_tests;
1414
pub(crate) mod diagnostics_docs;
15+
mod feature_docs;
1516
mod grammar;
1617
mod lints;
1718
mod parser_inline_tests;
@@ -32,6 +33,7 @@ impl flags::Codegen {
3233
flags::CodegenType::DiagnosticsDocs => diagnostics_docs::generate(self.check),
3334
flags::CodegenType::LintDefinitions => lints::generate(self.check),
3435
flags::CodegenType::ParserTests => parser_inline_tests::generate(self.check),
36+
flags::CodegenType::FeatureDocs => feature_docs::generate(self.check),
3537
}
3638
Ok(())
3739
}

src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/sourcegen.rs renamed to src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs

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

5-
#[test]
6-
fn sourcegen_feature_docs() {
5+
use crate::{
6+
codegen::{list_rust_files, CommentBlock, Location},
7+
project_root,
8+
};
9+
10+
pub(crate) fn generate(_check: bool) {
711
let features = Feature::collect().unwrap();
812
let contents = features.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
913
let contents = format!(
@@ -13,39 +17,39 @@ fn sourcegen_feature_docs() {
1317
",
1418
contents.trim()
1519
);
16-
let dst = sourcegen::project_root().join("docs/user/generated_features.adoc");
20+
let dst = project_root().join("docs/user/generated_features.adoc");
1721
fs::write(dst, contents).unwrap();
1822
}
1923

2024
#[derive(Debug)]
2125
struct Feature {
2226
id: String,
23-
location: sourcegen::Location,
27+
location: Location,
2428
doc: String,
2529
}
2630

2731
impl Feature {
2832
fn collect() -> io::Result<Vec<Feature>> {
29-
let crates_dir = sourcegen::project_root().join("crates");
33+
let crates_dir = project_root().join("crates");
3034

3135
let mut res = Vec::new();
32-
for path in sourcegen::list_rust_files(&crates_dir) {
36+
for path in list_rust_files(&crates_dir) {
3337
collect_file(&mut res, path)?;
3438
}
3539
res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
3640
return Ok(res);
3741

3842
fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> io::Result<()> {
3943
let text = std::fs::read_to_string(&path)?;
40-
let comment_blocks = sourcegen::CommentBlock::extract("Feature", &text);
44+
let comment_blocks = CommentBlock::extract("Feature", &text);
4145

4246
for block in comment_blocks {
4347
let id = block.id;
4448
if let Err(msg) = is_valid_feature_name(&id) {
4549
panic!("invalid feature name: {id:?}:\n {msg}")
4650
}
4751
let doc = block.contents.join("\n");
48-
let location = sourcegen::Location { file: path.clone(), line: block.line };
52+
let location = Location { file: path.clone(), line: block.line };
4953
acc.push(Feature { id, location, doc })
5054
}
5155

src/tools/rust-analyzer/xtask/src/flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ pub enum CodegenType {
186186
DiagnosticsDocs,
187187
LintDefinitions,
188188
ParserTests,
189+
FeatureDocs,
189190
}
190191

191192
impl fmt::Display for CodegenType {
@@ -197,6 +198,7 @@ impl fmt::Display for CodegenType {
197198
Self::DiagnosticsDocs => write!(f, "diagnostics-docs"),
198199
Self::LintDefinitions => write!(f, "lint-definitions"),
199200
Self::ParserTests => write!(f, "parser-tests"),
201+
Self::FeatureDocs => write!(f, "feature-docs"),
200202
}
201203
}
202204
}
@@ -211,6 +213,7 @@ impl FromStr for CodegenType {
211213
"diagnostics-docs" => Ok(Self::DiagnosticsDocs),
212214
"lint-definitions" => Ok(Self::LintDefinitions),
213215
"parser-tests" => Ok(Self::ParserTests),
216+
"feature-docs" => Ok(Self::FeatureDocs),
214217
_ => Err("Invalid option".to_owned()),
215218
}
216219
}

0 commit comments

Comments
 (0)