|
1 | 1 | use anyhow::{bail, Result};
|
2 |
| -use rustdoc_types::{Crate, Impl, ItemEnum, Path}; |
| 2 | +use rustdoc_types::{Crate, Impl, ItemEnum, Path, Type}; |
3 | 3 | use std::{
|
4 | 4 | fs::File,
|
5 | 5 | io::{stdout, IsTerminal},
|
@@ -35,33 +35,49 @@ pub async fn codegen(args: &CodegenArgs) -> Result<()> {
|
35 | 35 | let target_directory = graph.workspace().target_directory().as_std_path();
|
36 | 36 | let json_path = target_directory
|
37 | 37 | .join("doc")
|
38 |
| - .join(format!("{}.json", lib.name().replace("-", "_"))); |
| 38 | + .join(format!("{}.json", lib.name().replace('-', "_"))); |
39 | 39 |
|
40 |
| - let rustdoc: Crate = spawn_blocking(move || { |
41 |
| - let file = File::open(&json_path)?; |
| 40 | + let crate_: Crate = spawn_blocking(move || { |
| 41 | + let file = File::open(json_path)?; |
42 | 42 | let crate_: Crate = serde_json::from_reader(file)?;
|
43 | 43 | Ok::<rustdoc_types::Crate, anyhow::Error>(crate_)
|
44 | 44 | })
|
45 | 45 | .await??;
|
46 | 46 |
|
47 |
| - if let Some(name) = rustdoc.index.iter().find_map(|(_k, v)| { |
| 47 | + if let Some((id, items)) = crate_.index.iter().find_map(|(_k, v)| { |
48 | 48 | if let ItemEnum::Impl(Impl {
|
49 | 49 | trait_: Some(rustdoc_types::Path {
|
50 | 50 | name: trait_name, ..
|
51 | 51 | }),
|
52 |
| - for_: rustdoc_types::Type::ResolvedPath(Path { name, .. }), |
| 52 | + for_: rustdoc_types::Type::ResolvedPath(Path { id, .. }), |
| 53 | + items, |
53 | 54 | ..
|
54 | 55 | }) = &v.inner
|
55 | 56 | {
|
56 |
| - (trait_name == &"App".to_string()).then(|| name) |
| 57 | + (trait_name.as_str() == "App").then_some((id, items)) |
57 | 58 | } else {
|
58 | 59 | None
|
59 | 60 | }
|
60 | 61 | }) {
|
61 | 62 | println!(
|
62 |
| - "The struct that implements crux_core::App is called {:?}", |
63 |
| - name |
| 63 | + "The struct that implements crux_core::App is {}", |
| 64 | + crate_.paths[id].path.join("::") |
64 | 65 | );
|
| 66 | + |
| 67 | + for item in items { |
| 68 | + let assoc = &crate_.index[item]; |
| 69 | + for name in &["Event", "ViewModel", "Capabilities"] { |
| 70 | + if assoc.name == Some(name.to_string()) { |
| 71 | + if let ItemEnum::AssocType { |
| 72 | + default: Some(Type::ResolvedPath(path)), |
| 73 | + .. |
| 74 | + } = &assoc.inner |
| 75 | + { |
| 76 | + println!("{name} type is {}", crate_.paths[&path.id].path.join("::")) |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + } |
65 | 81 | }
|
66 | 82 |
|
67 | 83 | Ok(())
|
|
0 commit comments