Skip to content
Merged
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
59 changes: 40 additions & 19 deletions src/html/partition.rs
Original file line number Diff line number Diff line change
@@ -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<T> = IndexMap<T, Vec<DocNodeWithContext>>;

Expand All @@ -26,6 +28,7 @@ where
doc_nodes: Box<dyn Iterator<Item = Cow<'a, DocNodeWithContext>> + 'a>,
flatten_namespaces: bool,
process: &F,
visited_refs: &mut HashSet<Location>,
) where
F: Fn(&mut IndexMap<T, Vec<DocNodeWithContext>>, &DocNodeWithContext),
{
Expand All @@ -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;
}
Expand All @@ -78,6 +86,7 @@ where
Box::new(doc_nodes),
flatten_namespaces,
process,
&mut HashSet::new(),
);

partitions
Expand Down Expand Up @@ -214,6 +223,7 @@ pub fn flatten_namespace<'a>(
out: &mut Vec<Cow<'a, DocNodeWithContext>>,
parent_node: Option<&DocNodeWithContext>,
doc_nodes: Box<dyn Iterator<Item = Cow<'a, DocNodeWithContext>> + 'a>,
visited_refs: &mut HashSet<Location>,
) {
let nodes: Vec<_> = doc_nodes.collect();

Expand All @@ -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;
}
Expand All @@ -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
}