mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Move feature-doc generation to xtask codegen
This commit is contained in:
parent
09932d9cd4
commit
986b9cf022
5 changed files with 17 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1244,7 +1244,6 @@ dependencies = [
|
|||
"expect-test",
|
||||
"limit",
|
||||
"ra-ap-rustc_lexer",
|
||||
"sourcegen",
|
||||
"stdx",
|
||||
"tracing",
|
||||
]
|
||||
|
|
|
@ -21,7 +21,6 @@ tracing = { workspace = true, optional = true }
|
|||
expect-test = "1.4.0"
|
||||
|
||||
stdx.workspace = true
|
||||
sourcegen.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["tracing"]
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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 })
|
||||
}
|
||||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue