mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +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",
|
"expect-test",
|
||||||
"limit",
|
"limit",
|
||||||
"ra-ap-rustc_lexer",
|
"ra-ap-rustc_lexer",
|
||||||
"sourcegen",
|
|
||||||
"stdx",
|
"stdx",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
|
@ -21,7 +21,6 @@ tracing = { workspace = true, optional = true }
|
||||||
expect-test = "1.4.0"
|
expect-test = "1.4.0"
|
||||||
|
|
||||||
stdx.workspace = true
|
stdx.workspace = true
|
||||||
sourcegen.workspace = true
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["tracing"]
|
default = ["tracing"]
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) mod assists_doc_tests;
|
pub(crate) mod assists_doc_tests;
|
||||||
pub(crate) mod diagnostics_docs;
|
pub(crate) mod diagnostics_docs;
|
||||||
|
mod feature_docs;
|
||||||
mod grammar;
|
mod grammar;
|
||||||
mod lints;
|
mod lints;
|
||||||
mod parser_inline_tests;
|
mod parser_inline_tests;
|
||||||
|
@ -32,6 +33,7 @@ impl flags::Codegen {
|
||||||
flags::CodegenType::DiagnosticsDocs => diagnostics_docs::generate(self.check),
|
flags::CodegenType::DiagnosticsDocs => diagnostics_docs::generate(self.check),
|
||||||
flags::CodegenType::LintDefinitions => lints::generate(self.check),
|
flags::CodegenType::LintDefinitions => lints::generate(self.check),
|
||||||
flags::CodegenType::ParserTests => parser_inline_tests::generate(self.check),
|
flags::CodegenType::ParserTests => parser_inline_tests::generate(self.check),
|
||||||
|
flags::CodegenType::FeatureDocs => feature_docs::generate(self.check),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
use std::{fmt, fs, io, path::PathBuf};
|
use std::{fmt, fs, io, path::PathBuf};
|
||||||
|
|
||||||
#[test]
|
use crate::{
|
||||||
fn sourcegen_feature_docs() {
|
codegen::{list_rust_files, CommentBlock, Location},
|
||||||
|
project_root,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub(crate) fn generate(_check: bool) {
|
||||||
let features = Feature::collect().unwrap();
|
let features = Feature::collect().unwrap();
|
||||||
let contents = features.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
|
let contents = features.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
|
||||||
let contents = format!(
|
let contents = format!(
|
||||||
|
@ -13,23 +17,23 @@ fn sourcegen_feature_docs() {
|
||||||
",
|
",
|
||||||
contents.trim()
|
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();
|
fs::write(dst, contents).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Feature {
|
struct Feature {
|
||||||
id: String,
|
id: String,
|
||||||
location: sourcegen::Location,
|
location: Location,
|
||||||
doc: String,
|
doc: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Feature {
|
impl Feature {
|
||||||
fn collect() -> io::Result<Vec<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();
|
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)?;
|
collect_file(&mut res, path)?;
|
||||||
}
|
}
|
||||||
res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
|
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<()> {
|
fn collect_file(acc: &mut Vec<Feature>, path: PathBuf) -> io::Result<()> {
|
||||||
let text = std::fs::read_to_string(&path)?;
|
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 {
|
for block in comment_blocks {
|
||||||
let id = block.id;
|
let id = block.id;
|
||||||
|
@ -45,7 +49,7 @@ impl Feature {
|
||||||
panic!("invalid feature name: {id:?}:\n {msg}")
|
panic!("invalid feature name: {id:?}:\n {msg}")
|
||||||
}
|
}
|
||||||
let doc = block.contents.join("\n");
|
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 })
|
acc.push(Feature { id, location, doc })
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,7 @@ pub enum CodegenType {
|
||||||
DiagnosticsDocs,
|
DiagnosticsDocs,
|
||||||
LintDefinitions,
|
LintDefinitions,
|
||||||
ParserTests,
|
ParserTests,
|
||||||
|
FeatureDocs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for CodegenType {
|
impl fmt::Display for CodegenType {
|
||||||
|
@ -197,6 +198,7 @@ impl fmt::Display for CodegenType {
|
||||||
Self::DiagnosticsDocs => write!(f, "diagnostics-docs"),
|
Self::DiagnosticsDocs => write!(f, "diagnostics-docs"),
|
||||||
Self::LintDefinitions => write!(f, "lint-definitions"),
|
Self::LintDefinitions => write!(f, "lint-definitions"),
|
||||||
Self::ParserTests => write!(f, "parser-tests"),
|
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),
|
"diagnostics-docs" => Ok(Self::DiagnosticsDocs),
|
||||||
"lint-definitions" => Ok(Self::LintDefinitions),
|
"lint-definitions" => Ok(Self::LintDefinitions),
|
||||||
"parser-tests" => Ok(Self::ParserTests),
|
"parser-tests" => Ok(Self::ParserTests),
|
||||||
|
"feature-docs" => Ok(Self::FeatureDocs),
|
||||||
_ => Err("Invalid option".to_owned()),
|
_ => Err("Invalid option".to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue