Move diagnostics docs generation into xtask/codegen

This commit is contained in:
Lukas Wirth 2024-03-04 16:49:03 +01:00
parent 4e8cbf36a8
commit 0964374274
7 changed files with 17 additions and 24 deletions

1
Cargo.lock generated
View file

@ -747,7 +747,6 @@ dependencies = [
"itertools",
"once_cell",
"serde_json",
"sourcegen",
"stdx",
"syntax",
"test-fixture",

View file

@ -33,8 +33,5 @@ expect-test = "1.4.0"
test-utils.workspace = true
test-fixture.workspace = true
[features]
in-rust-tree = []
[lints]
workspace = true

View file

@ -33,10 +33,6 @@ expect-test = "1.4.0"
# local deps
test-utils.workspace = true
test-fixture.workspace = true
sourcegen.workspace = true
[features]
in-rust-tree = []
[lints]
workspace = true

View file

@ -51,8 +51,5 @@ expect-test = "1.4.0"
test-utils.workspace = true
test-fixture.workspace = true
[features]
in-rust-tree = ["ide-assists/in-rust-tree", "ide-diagnostics/in-rust-tree"]
[lints]
workspace = true

View file

@ -85,7 +85,6 @@ force-always-assert = ["always-assert/force"]
sysroot-abi = []
in-rust-tree = [
"sysroot-abi",
"ide/in-rust-tree",
"syntax/in-rust-tree",
"parser/in-rust-tree",
"hir/in-rust-tree",

View file

@ -8,6 +8,7 @@ use xshell::{cmd, Shell};
use crate::{flags, project_root};
pub(crate) mod assists_doc_tests;
pub(crate) mod diagnostics_docs;
impl flags::Codegen {
pub(crate) fn run(self, _sh: &Shell) -> anyhow::Result<()> {

View file

@ -2,22 +2,26 @@
use std::{fmt, fs, io, path::PathBuf};
use sourcegen::project_root;
use crate::{
codegen::{add_preamble, list_rust_files, CommentBlock, Location},
project_root,
};
#[test]
fn sourcegen_diagnostic_docs() {
fn generate(check: bool) {
let diagnostics = Diagnostic::collect().unwrap();
let contents =
diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
let contents = sourcegen::add_preamble("sourcegen_diagnostic_docs", contents);
let dst = project_root().join("docs/user/generated_diagnostic.adoc");
fs::write(dst, contents).unwrap();
if !check {
let contents =
diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
let contents = add_preamble("sourcegen_diagnostic_docs", contents);
let dst = project_root().join("docs/user/generated_diagnostic.adoc");
fs::write(dst, contents).unwrap();
}
}
#[derive(Debug)]
struct Diagnostic {
id: String,
location: sourcegen::Location,
location: Location,
doc: String,
}
@ -26,7 +30,7 @@ impl Diagnostic {
let handlers_dir = project_root().join("crates/ide-diagnostics/src/handlers");
let mut res = Vec::new();
for path in sourcegen::list_rust_files(&handlers_dir) {
for path in list_rust_files(&handlers_dir) {
collect_file(&mut res, path)?;
}
res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
@ -34,7 +38,7 @@ impl Diagnostic {
fn collect_file(acc: &mut Vec<Diagnostic>, path: PathBuf) -> io::Result<()> {
let text = fs::read_to_string(&path)?;
let comment_blocks = sourcegen::CommentBlock::extract("Diagnostic", &text);
let comment_blocks = CommentBlock::extract("Diagnostic", &text);
for block in comment_blocks {
let id = block.id;
@ -42,7 +46,7 @@ impl Diagnostic {
panic!("invalid diagnostic 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(Diagnostic { id, location, doc })
}