Skip to content

Commit c7d948f

Browse files
crowlKatsclaude
andcommitted
fix: skip references when counting total symbols in TopSymbolsCtx
The total_symbols count was massively inflated because flatten_namespace resolves references (re-exports), causing the same symbol to be counted once per module that re-exports it. Instead, count symbols by walking namespace children directly and skipping reference nodes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2fee83a commit c7d948f

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

src/html/util.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,41 @@ pub struct TopSymbolsCtx {
854854

855855
impl TopSymbolsCtx {
856856
pub fn new(ctx: &RenderContext) -> Option<Self> {
857+
fn count_symbols(
858+
ctx: &GenerateCtx,
859+
nodes: &[DocNodeWithContext],
860+
) -> usize {
861+
let mut count = 0;
862+
for node in nodes {
863+
if node.is_internal(ctx) {
864+
continue;
865+
}
866+
if node
867+
.declarations
868+
.iter()
869+
.any(|d| d.reference_def().is_some())
870+
{
871+
continue;
872+
}
873+
count += 1;
874+
if let Some(children) = &node.namespace_children {
875+
count += count_symbols(ctx, children);
876+
}
877+
}
878+
count
879+
}
880+
881+
let total_symbols: usize = ctx
882+
.ctx
883+
.doc_nodes
884+
.values()
885+
.map(|nodes| count_symbols(ctx.ctx, nodes))
886+
.sum();
887+
888+
if total_symbols == 0 {
889+
return None;
890+
}
891+
857892
let symbols = ctx
858893
.ctx
859894
.doc_nodes
@@ -864,12 +899,6 @@ impl TopSymbolsCtx {
864899
.filter(|node| !node.is_internal(ctx.ctx))
865900
.collect::<Vec<_>>();
866901

867-
if symbols.is_empty() {
868-
return None;
869-
}
870-
871-
let total_symbols = symbols.len();
872-
873902
let symbols = symbols
874903
.into_iter()
875904
.take(5)

0 commit comments

Comments
 (0)