Unnamed repository; edit this file 'description' to name the repository.
Move feature-doc generation to xtask codegen
Lukas Wirth 2024-07-07
parent 09932d9 · commit 986b9cf
-rw-r--r--Cargo.lock1
-rw-r--r--crates/parser/Cargo.toml1
-rw-r--r--xtask/src/codegen.rs2
-rw-r--r--xtask/src/codegen/feature_docs.rs (renamed from crates/rust-analyzer/tests/slow-tests/sourcegen.rs)20
-rw-r--r--xtask/src/flags.rs3
5 files changed, 17 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c63d659543..ca442542c8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1244,7 +1244,6 @@ dependencies = [
"expect-test",
"limit",
"ra-ap-rustc_lexer",
- "sourcegen",
"stdx",
"tracing",
]
diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml
index 1f84e3f3af..54b57c201b 100644
--- a/crates/parser/Cargo.toml
+++ b/crates/parser/Cargo.toml
@@ -21,7 +21,6 @@ tracing = { workspace = true, optional = true }
expect-test = "1.4.0"
stdx.workspace = true
-sourcegen.workspace = true
[features]
default = ["tracing"]
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 607cfdf83e..f164abdbb1 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -12,6 +12,7 @@ use crate::{
pub(crate) mod assists_doc_tests;
pub(crate) mod diagnostics_docs;
+mod feature_docs;
mod grammar;
mod lints;
mod parser_inline_tests;
@@ -32,6 +33,7 @@ impl flags::Codegen {
flags::CodegenType::DiagnosticsDocs => diagnostics_docs::generate(self.check),
flags::CodegenType::LintDefinitions => lints::generate(self.check),
flags::CodegenType::ParserTests => parser_inline_tests::generate(self.check),
+ flags::CodegenType::FeatureDocs => feature_docs::generate(self.check),
}
Ok(())
}
diff --git a/crates/rust-analyzer/tests/slow-tests/sourcegen.rs b/xtask/src/codegen/feature_docs.rs
index 2eafb0da69..0c0fa838dd 100644
--- a/crates/rust-analyzer/tests/slow-tests/sourcegen.rs
+++ b/xtask/src/codegen/feature_docs.rs
@@ -2,8 +2,12 @@
use std::{fmt, fs, io, path::PathBuf};
-#[test]
-fn sourcegen_feature_docs() {
+use crate::{
+ codegen::{list_rust_files, CommentBlock, Location},
+ project_root,
+};
+
+pub(crate) fn generate(_check: bool) {
let features = Feature::collect().unwrap();
let contents = features.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
let contents = format!(
@@ -13,23 +17,23 @@ fn sourcegen_feature_docs() {
",
contents.trim()
);
- let dst = sourcegen::project_root().join("docs/user/generated_features.adoc");
+ let dst = project_root().join("docs/user/generated_features.adoc");
fs::write(dst, contents).unwrap();
}
#[derive(Debug)]
struct Feature {
id: String,
- location: sourcegen::Location,
+ location: Location,
doc: String,
}
impl Feature {
fn collect() -> io::Result<Vec<Feature>> {
- let crates_dir = sourcegen::project_root().join("crates");
+ let crates_dir = project_root().join("crates");
let mut res = Vec::new();
- for path in sourcegen::list_rust_files(&crates_dir) {
+ for path in list_rust_files(&crates_dir) {
collect_file(&mut res, path)?;
}
res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
@@ -37,7 +41,7 @@ impl Feature {
fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> io::Result<()> {
let text = std::fs::read_to_string(&path)?;
- let comment_blocks = sourcegen::CommentBlock::extract("Feature", &text);
+ let comment_blocks = CommentBlock::extract("Feature", &text);
for block in comment_blocks {
let id = block.id;
@@ -45,7 +49,7 @@ impl Feature {
panic!("invalid feature name: {id:?}:\n {msg}")
}
let doc = block.contents.join("\n");
- let location = sourcegen::Location { file: path.clone(), line: block.line };
+ let location = Location { file: path.clone(), line: block.line };
acc.push(Feature { id, location, doc })
}
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs
index f99ee1abb2..9b3a2a034e 100644
--- a/xtask/src/flags.rs
+++ b/xtask/src/flags.rs
@@ -186,6 +186,7 @@ pub enum CodegenType {
DiagnosticsDocs,
LintDefinitions,
ParserTests,
+ FeatureDocs,
}
impl fmt::Display for CodegenType {
@@ -197,6 +198,7 @@ impl fmt::Display for CodegenType {
Self::DiagnosticsDocs => write!(f, "diagnostics-docs"),
Self::LintDefinitions => write!(f, "lint-definitions"),
Self::ParserTests => write!(f, "parser-tests"),
+ Self::FeatureDocs => write!(f, "feature-docs"),
}
}
}
@@ -211,6 +213,7 @@ impl FromStr for CodegenType {
"diagnostics-docs" => Ok(Self::DiagnosticsDocs),
"lint-definitions" => Ok(Self::LintDefinitions),
"parser-tests" => Ok(Self::ParserTests),
+ "feature-docs" => Ok(Self::FeatureDocs),
_ => Err("Invalid option".to_owned()),
}
}