about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-07-07 08:58:51 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-07-07 09:00:18 +0200
commit2d14f47eb7ba10c740da2ae73a010ba19a826e27 (patch)
tree976b8d2723bda99b61a799b40a2c4cb653427802
parent4465fff75e2d4e74c5072c3ce834a6a94fad8421 (diff)
downloadrust-2d14f47eb7ba10c740da2ae73a010ba19a826e27.tar.gz
rust-2d14f47eb7ba10c740da2ae73a010ba19a826e27.zip
Move feature-doc generation to xtask codegen
-rw-r--r--src/tools/rust-analyzer/Cargo.lock1
-rw-r--r--src/tools/rust-analyzer/crates/parser/Cargo.toml1
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen.rs2
-rw-r--r--src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs (renamed from src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/sourcegen.rs)20
-rw-r--r--src/tools/rust-analyzer/xtask/src/flags.rs3
5 files changed, 17 insertions, 10 deletions
diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock
index c63d6595432..ca442542c8c 100644
--- a/src/tools/rust-analyzer/Cargo.lock
+++ b/src/tools/rust-analyzer/Cargo.lock
@@ -1244,7 +1244,6 @@ dependencies = [
  "expect-test",
  "limit",
  "ra-ap-rustc_lexer",
- "sourcegen",
  "stdx",
  "tracing",
 ]
diff --git a/src/tools/rust-analyzer/crates/parser/Cargo.toml b/src/tools/rust-analyzer/crates/parser/Cargo.toml
index 1f84e3f3af3..54b57c201be 100644
--- a/src/tools/rust-analyzer/crates/parser/Cargo.toml
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/xtask/src/codegen.rs b/src/tools/rust-analyzer/xtask/src/codegen.rs
index 607cfdf83e5..f164abdbb17 100644
--- a/src/tools/rust-analyzer/xtask/src/codegen.rs
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/sourcegen.rs b/src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs
index 2eafb0da692..0c0fa838dd3 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/sourcegen.rs
+++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/xtask/src/flags.rs b/src/tools/rust-analyzer/xtask/src/flags.rs
index f99ee1abb2a..9b3a2a034e1 100644
--- a/src/tools/rust-analyzer/xtask/src/flags.rs
+++ b/src/tools/rust-analyzer/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()),
         }
     }