diff --git a/src/html/partition.rs b/src/html/partition.rs index bad777af8..c83d079f3 100644 --- a/src/html/partition.rs +++ b/src/html/partition.rs @@ -1,12 +1,14 @@ use super::DocNodeWithContext; use super::GenerateCtx; use crate::DeclarationDef; +use crate::Location; use crate::js_doc::JsDocTag; use indexmap::IndexMap; use std::borrow::Cow; use std::cell::RefCell; use std::cmp::Ordering; use std::collections::HashMap; +use std::collections::HashSet; pub type Partitions = IndexMap>; @@ -26,6 +28,7 @@ where doc_nodes: Box> + 'a>, flatten_namespaces: bool, process: &F, + visited_refs: &mut HashSet, ) where F: Fn(&mut IndexMap>, &DocNodeWithContext), { @@ -48,18 +51,23 @@ where ), true, process, + visited_refs, ); } if let Some(reference) = decl.reference_def() { - partitioner_inner( - ctx, - partitions, - parent_node, - Box::new(ctx.resolve_reference(parent_node, &reference.target)), - flatten_namespaces, - process, - ); + if visited_refs.insert(reference.target.clone()) { + partitioner_inner( + ctx, + partitions, + parent_node, + Box::new(ctx.resolve_reference(parent_node, &reference.target)), + flatten_namespaces, + process, + visited_refs, + ); + visited_refs.remove(&reference.target); + } // hack until reference nodes are separate from normal symbols continue 'outer; } @@ -78,6 +86,7 @@ where Box::new(doc_nodes), flatten_namespaces, process, + &mut HashSet::new(), ); partitions @@ -214,6 +223,7 @@ pub fn flatten_namespace<'a>( out: &mut Vec>, parent_node: Option<&DocNodeWithContext>, doc_nodes: Box> + 'a>, + visited_refs: &mut HashSet, ) { let nodes: Vec<_> = doc_nodes.collect(); @@ -232,20 +242,25 @@ pub fn flatten_namespace<'a>( out, Some(&**node), Box::new(children.into_iter().map(Cow::Owned)), + visited_refs, ); } if let Some(reference) = decl.reference_def() { - let resolved: Vec<_> = ctx - .resolve_reference(parent_node, &reference.target) - .map(|c| c.into_owned()) - .collect(); - partitioner_inner( - ctx, - out, - parent_node, - Box::new(resolved.into_iter().map(Cow::Owned)), - ); + if visited_refs.insert(reference.target.clone()) { + let resolved: Vec<_> = ctx + .resolve_reference(parent_node, &reference.target) + .map(|c| c.into_owned()) + .collect(); + partitioner_inner( + ctx, + out, + parent_node, + Box::new(resolved.into_iter().map(Cow::Owned)), + visited_refs, + ); + visited_refs.remove(&reference.target); + } // hack until reference nodes are separate from normal symbols continue 'outer; } @@ -257,7 +272,13 @@ pub fn flatten_namespace<'a>( let mut out = vec![]; - partitioner_inner(ctx, &mut out, None, Box::new(doc_nodes)); + partitioner_inner( + ctx, + &mut out, + None, + Box::new(doc_nodes), + &mut HashSet::new(), + ); out }