diff --git a/src/adapter/edges.rs b/src/adapter/edges.rs index 830d2a6..d53be9c 100644 --- a/src/adapter/edges.rs +++ b/src/adapter/edges.rs @@ -112,6 +112,8 @@ pub(super) fn resolve_importable_edge<'a, V: AsVertex> + 'a>( pub(super) fn resolve_item_edge<'a, V: AsVertex> + 'a>( contexts: ContextIterator<'a, V>, edge_name: &str, + current_crate: &'a IndexedCrate<'a>, + previous_crate: Option<&'a IndexedCrate<'a>>, ) -> ContextOutcomeIterator<'a, V, VertexIterator<'a, Vertex<'a>>> { match edge_name { "span" => resolve_neighbors_with(contexts, move |vertex| { @@ -132,6 +134,22 @@ pub(super) fn resolve_item_edge<'a, V: AsVertex> + 'a>( .map(move |attr| origin.make_attribute_vertex(Attribute::new(attr.as_str()))), ) }), + "link" => resolve_neighbors_with(contexts, move |vertex| { + let origin = vertex.origin; + let item = vertex.as_item().expect("vertex was not an Item"); + + let parent_crate = match origin { + Origin::CurrentCrate => current_crate, + Origin::PreviousCrate => previous_crate.expect("no baseline provided"), + }; + + Box::new( + item.links + .values() + .filter_map(move |id| parent_crate.inner.index.get(id)) + .map(move |item| origin.make_item_vertex(item)), + ) + }), _ => unreachable!("resolve_item_edge {edge_name}"), } } diff --git a/src/adapter/mod.rs b/src/adapter/mod.rs index 6f96c45..0b5285d 100644 --- a/src/adapter/mod.rs +++ b/src/adapter/mod.rs @@ -180,9 +180,14 @@ impl<'a> Adapter<'a> for RustdocAdapter<'a> { | "PlainVariant" | "TupleVariant" | "StructVariant" | "Trait" | "Function" | "Method" | "Impl" | "GlobalValue" | "Constant" | "Static" | "AssociatedType" | "AssociatedConstant" | "Module" - if matches!(edge_name.as_ref(), "span" | "attribute") => + if matches!(edge_name.as_ref(), "span" | "attribute" | "link") => { - edges::resolve_item_edge(contexts, edge_name) + edges::resolve_item_edge( + contexts, + edge_name, + self.current_crate, + self.previous_crate, + ) } "ImplOwner" | "Struct" | "Enum" if matches!(edge_name.as_ref(), "impl" | "inherent_impl") => diff --git a/src/rustdoc_schema.graphql b/src/rustdoc_schema.graphql index fc5c497..0724a76 100644 --- a/src/rustdoc_schema.graphql +++ b/src/rustdoc_schema.graphql @@ -89,6 +89,13 @@ interface Item { attribute: [Attribute!] span: Span + + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] } """ @@ -143,6 +150,13 @@ type Module implements Item & Importable { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -206,6 +220,13 @@ type Struct implements Item & Importable & ImplOwner { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -288,6 +309,13 @@ type StructField implements Item { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # own edges raw_type: RawType } @@ -345,6 +373,13 @@ type Enum implements Item & Importable & ImplOwner { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -427,6 +462,13 @@ interface Variant implements Item { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # own edges field: [StructField!] } @@ -481,6 +523,13 @@ type PlainVariant implements Item & Variant { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Variant field: [StructField!] } @@ -535,6 +584,13 @@ type TupleVariant implements Item & Variant { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Variant field: [StructField!] } @@ -589,6 +645,13 @@ type StructVariant implements Item & Variant { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Variant field: [StructField!] } @@ -660,6 +723,13 @@ interface ImplOwner implements Item & Importable { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -745,6 +815,13 @@ type Impl implements Item { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # own edges """ @@ -825,6 +902,13 @@ type Trait implements Item & Importable { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -1053,6 +1137,13 @@ type Function implements Item & FunctionLike & Importable { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from FunctionLike parameter: [FunctionParameter!] abi: FunctionAbi! @@ -1172,6 +1263,13 @@ interface GlobalValue implements Item & Importable { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -1284,6 +1382,13 @@ type Constant implements Item & Importable & GlobalValue { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -1342,6 +1447,13 @@ type Static implements Item & Importable & GlobalValue { span: Span attribute: [Attribute!] + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] + # edges from Importable importable_path: [ImportablePath!] canonical_path: Path @@ -1499,6 +1611,13 @@ type AssociatedType implements Item { # edges from Item span: Span attribute: [Attribute!] + + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] } """ @@ -1588,6 +1707,13 @@ type AssociatedConstant implements Item { # edges from Item span: Span attribute: [Attribute!] + + """ + Other items that this item's doc comment links to. + + Corresponds to the `links` field in rustdoc JSON. + """ + link: [Item!] } """