Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link edge to Item that points to items linked in a doc-comment. #308

Open
wants to merge 1 commit into
base: rustdoc-v29
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/adapter/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub(super) fn resolve_importable_edge<'a, V: AsVertex<Vertex<'a>> + 'a>(
pub(super) fn resolve_item_edge<'a, V: AsVertex<Vertex<'a>> + '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| {
Expand All @@ -132,6 +134,22 @@ pub(super) fn resolve_item_edge<'a, V: AsVertex<Vertex<'a>> + '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}"),
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") =>
Expand Down
126 changes: 126 additions & 0 deletions src/rustdoc_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]
}

"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!]
}
Expand Down Expand Up @@ -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!]
}
Expand Down Expand Up @@ -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!]
}
Expand Down Expand Up @@ -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!]
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!]
}

"""
Expand Down Expand Up @@ -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!]
}

"""
Expand Down
Loading