Move diagnostics docs generation into xtask/codegen
This commit is contained in:
parent
4e8cbf36a8
commit
0964374274
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -747,7 +747,6 @@ dependencies = [
|
|||||||
"itertools",
|
"itertools",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sourcegen",
|
|
||||||
"stdx",
|
"stdx",
|
||||||
"syntax",
|
"syntax",
|
||||||
"test-fixture",
|
"test-fixture",
|
||||||
|
@ -33,8 +33,5 @@ expect-test = "1.4.0"
|
|||||||
test-utils.workspace = true
|
test-utils.workspace = true
|
||||||
test-fixture.workspace = true
|
test-fixture.workspace = true
|
||||||
|
|
||||||
[features]
|
|
||||||
in-rust-tree = []
|
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
@ -33,10 +33,6 @@ expect-test = "1.4.0"
|
|||||||
# local deps
|
# local deps
|
||||||
test-utils.workspace = true
|
test-utils.workspace = true
|
||||||
test-fixture.workspace = true
|
test-fixture.workspace = true
|
||||||
sourcegen.workspace = true
|
|
||||||
|
|
||||||
[features]
|
|
||||||
in-rust-tree = []
|
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
@ -51,8 +51,5 @@ expect-test = "1.4.0"
|
|||||||
test-utils.workspace = true
|
test-utils.workspace = true
|
||||||
test-fixture.workspace = true
|
test-fixture.workspace = true
|
||||||
|
|
||||||
[features]
|
|
||||||
in-rust-tree = ["ide-assists/in-rust-tree", "ide-diagnostics/in-rust-tree"]
|
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
@ -85,7 +85,6 @@ force-always-assert = ["always-assert/force"]
|
|||||||
sysroot-abi = []
|
sysroot-abi = []
|
||||||
in-rust-tree = [
|
in-rust-tree = [
|
||||||
"sysroot-abi",
|
"sysroot-abi",
|
||||||
"ide/in-rust-tree",
|
|
||||||
"syntax/in-rust-tree",
|
"syntax/in-rust-tree",
|
||||||
"parser/in-rust-tree",
|
"parser/in-rust-tree",
|
||||||
"hir/in-rust-tree",
|
"hir/in-rust-tree",
|
||||||
|
@ -8,6 +8,7 @@ use xshell::{cmd, Shell};
|
|||||||
use crate::{flags, project_root};
|
use crate::{flags, project_root};
|
||||||
|
|
||||||
pub(crate) mod assists_doc_tests;
|
pub(crate) mod assists_doc_tests;
|
||||||
|
pub(crate) mod diagnostics_docs;
|
||||||
|
|
||||||
impl flags::Codegen {
|
impl flags::Codegen {
|
||||||
pub(crate) fn run(self, _sh: &Shell) -> anyhow::Result<()> {
|
pub(crate) fn run(self, _sh: &Shell) -> anyhow::Result<()> {
|
||||||
|
@ -2,22 +2,26 @@
|
|||||||
|
|
||||||
use std::{fmt, fs, io, path::PathBuf};
|
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 generate(check: bool) {
|
||||||
fn sourcegen_diagnostic_docs() {
|
|
||||||
let diagnostics = Diagnostic::collect().unwrap();
|
let diagnostics = Diagnostic::collect().unwrap();
|
||||||
let contents =
|
if !check {
|
||||||
diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
|
let contents =
|
||||||
let contents = sourcegen::add_preamble("sourcegen_diagnostic_docs", contents);
|
diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
|
||||||
let dst = project_root().join("docs/user/generated_diagnostic.adoc");
|
let contents = add_preamble("sourcegen_diagnostic_docs", contents);
|
||||||
fs::write(dst, contents).unwrap();
|
let dst = project_root().join("docs/user/generated_diagnostic.adoc");
|
||||||
|
fs::write(dst, contents).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Diagnostic {
|
struct Diagnostic {
|
||||||
id: String,
|
id: String,
|
||||||
location: sourcegen::Location,
|
location: Location,
|
||||||
doc: String,
|
doc: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +30,7 @@ impl Diagnostic {
|
|||||||
let handlers_dir = project_root().join("crates/ide-diagnostics/src/handlers");
|
let handlers_dir = project_root().join("crates/ide-diagnostics/src/handlers");
|
||||||
|
|
||||||
let mut res = Vec::new();
|
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)?;
|
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));
|
||||||
@ -34,7 +38,7 @@ impl Diagnostic {
|
|||||||
|
|
||||||
fn collect_file(acc: &mut Vec<Diagnostic>, path: PathBuf) -> io::Result<()> {
|
fn collect_file(acc: &mut Vec<Diagnostic>, path: PathBuf) -> io::Result<()> {
|
||||||
let text = fs::read_to_string(&path)?;
|
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 {
|
for block in comment_blocks {
|
||||||
let id = block.id;
|
let id = block.id;
|
||||||
@ -42,7 +46,7 @@ impl Diagnostic {
|
|||||||
panic!("invalid diagnostic name: {id:?}:\n {msg}")
|
panic!("invalid diagnostic 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(Diagnostic { id, location, doc })
|
acc.push(Diagnostic { id, location, doc })
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user