Skip to content

Commit

Permalink
feat: add singular generate_symbol_page fn (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Feb 22, 2024
1 parent 1dbf67d commit 85f03de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod types;
mod usage;
mod util;

pub use pages::generate_symbol_page;
pub use pages::generate_symbol_pages_for_module;
pub use render_context::RenderContext;
pub use search::generate_search_index;
Expand Down
60 changes: 57 additions & 3 deletions src/html/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub fn generate_symbol_pages_for_module(
) -> Vec<(BreadcrumbsCtx, SidepanelCtx, SymbolGroupCtx)> {
let name_partitions = partition_nodes_by_name(doc_nodes);

generate_symbol_pages(
generate_symbol_pages_inner(
ctx,
doc_nodes,
partitions_for_nodes,
Expand All @@ -186,7 +186,61 @@ pub fn generate_symbol_pages_for_module(
)
}

fn generate_symbol_pages(
pub fn generate_symbol_page(
ctx: &GenerateCtx,
current_specifier: &ModuleSpecifier,
short_path: &ShortPath,
partitions_for_nodes: &IndexMap<String, Vec<DocNodeWithContext>>,
doc_nodes_for_module: &[DocNode],
name: &str,
) -> Option<(BreadcrumbsCtx, SidepanelCtx, SymbolGroupCtx)> {
let mut name_parts = name.split('.').peekable();

let mut doc_nodes = doc_nodes_for_module;

let mut namespace_paths = vec![];

let doc_nodes = loop {
let next_part = name_parts.next()?;
let mut nodes = doc_nodes.iter().filter(|node| {
if matches!(node.kind, DocNodeKind::ModuleDoc | DocNodeKind::Import)
|| node.declaration_kind == crate::node::DeclarationKind::Private
{
return false;
}
node.name == next_part
});
if name_parts.peek().is_none() {
break nodes.cloned().collect::<Vec<_>>();
}
namespace_paths.push(next_part.to_string());
if let Some(namespace) =
nodes.find(|node| matches!(node.kind, DocNodeKind::Namespace))
{
let namespace = namespace.namespace_def.as_ref().unwrap();
doc_nodes = &namespace.elements;
} else {
return None;
}
};

let sidepanel_ctx =
SidepanelCtx::new(ctx, partitions_for_nodes, short_path, name);

let (breadcrumbs_ctx, symbol_group_ctx) = render_symbol_page(
ctx,
doc_nodes_for_module,
current_specifier,
short_path,
&namespace_paths,
name,
&doc_nodes,
);

Some((breadcrumbs_ctx, sidepanel_ctx, symbol_group_ctx))
}

fn generate_symbol_pages_inner(
ctx: &GenerateCtx,
doc_nodes_for_module: &[DocNode],
partitions_for_nodes: &IndexMap<String, Vec<DocNodeWithContext>>,
Expand Down Expand Up @@ -239,7 +293,7 @@ fn generate_symbol_pages(
ns_paths
};

let generated = generate_symbol_pages(
let generated = generate_symbol_pages_inner(
ctx,
doc_nodes_for_module,
partitions_for_nodes,
Expand Down

0 comments on commit 85f03de

Please sign in to comment.