From 2d14f47eb7ba10c740da2ae73a010ba19a826e27 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 7 Jul 2024 08:58:51 +0200 Subject: [PATCH] Move feature-doc generation to xtask codegen --- src/tools/rust-analyzer/Cargo.lock | 1 - .../rust-analyzer/crates/parser/Cargo.toml | 1 - src/tools/rust-analyzer/xtask/src/codegen.rs | 2 ++ .../src/codegen/feature_docs.rs} | 20 +++++++++++-------- src/tools/rust-analyzer/xtask/src/flags.rs | 3 +++ 5 files changed, 17 insertions(+), 10 deletions(-) rename src/tools/rust-analyzer/{crates/rust-analyzer/tests/slow-tests/sourcegen.rs => xtask/src/codegen/feature_docs.rs} (80%) diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index c63d65954328..ca442542c8cc 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 1f84e3f3af3f..54b57c201be9 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 607cfdf83e5f..f164abdbb17a 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 similarity index 80% rename from src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/sourcegen.rs rename to src/tools/rust-analyzer/xtask/src/codegen/feature_docs.rs index 2eafb0da6921..0c0fa838dd37 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::>().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> { - 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, 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 f99ee1abb2a1..9b3a2a034e1c 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()), } }