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

fix: show private symbols in dts files #693

Merged
merged 4 commits into from
Jan 27, 2025
Merged
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
2 changes: 1 addition & 1 deletion js/html_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface SymbolContentCtx {
}

export interface SectionCtx {
header: SectionHeaderCtx;
header: SectionHeaderCtx | null;
content: SectionContentCtx;
}

Expand Down
4 changes: 2 additions & 2 deletions src/html/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ impl ModuleDocCtx {
partitions_by_kind.into_iter().map(|(title, nodes)| {
(
render_ctx.clone(),
SectionHeaderCtx {
Some(SectionHeaderCtx {
title: title.clone(),
anchor: AnchorCtx { id: title },
href: None,
doc: None,
},
}),
nodes,
)
}),
Expand Down
5 changes: 3 additions & 2 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,9 @@ impl DocNodeWithContext {
ns_qualifiers
}

pub fn is_internal(&self) -> bool {
self.inner.declaration_kind == crate::node::DeclarationKind::Private
pub fn is_internal(&self, ctx: &GenerateCtx) -> bool {
(self.inner.declaration_kind == crate::node::DeclarationKind::Private
&& !matches!(ctx.file_mode, FileMode::SingleDts | FileMode::Dts))
Comment on lines +806 to +808
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the main fix

|| self
.js_doc
.tags
Expand Down
26 changes: 16 additions & 10 deletions src/html/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use super::ShortPath;
use super::SymbolGroupCtx;
use super::UrlResolveKind;
use std::borrow::Cow;
use std::cmp::Ordering;
use std::rc::Rc;

use super::FUSE_FILENAME;
Expand Down Expand Up @@ -103,7 +104,7 @@ impl CategoriesPanelCtx {
true,
)
})
.filter(|(_name, node)| !node[0].is_internal())
.filter(|(_name, node)| !node[0].is_internal(ctx.ctx))
.count();

let mut categories = ctx
Expand Down Expand Up @@ -145,7 +146,7 @@ impl CategoriesPanelCtx {
true,
)
})
.filter(|(_name, node)| !node[0].is_internal())
.filter(|(_name, node)| !node[0].is_internal(ctx.ctx))
.count();

let (_, nodes) = ctx.ctx.doc_nodes.first().unwrap();
Expand Down Expand Up @@ -274,21 +275,26 @@ impl IndexCtx {
render_ctx.toc.add_entry(1, title, &anchor);

util::SectionCtx {
header: SectionHeaderCtx {
header: Some(SectionHeaderCtx {
href: Some(ctx.resolve_path(
UrlResolveKind::Root,
short_path.as_resolve_kind(),
)),
title: title.to_string(),
anchor: AnchorCtx { id: anchor },
doc,
},
}),
content: util::SectionContentCtx::Empty,
}
})
.collect::<Vec<_>>();

sections.sort_by(|a, b| a.header.title.cmp(&b.header.title));
sections.sort_by(|a, b| match (&a.header, &b.header) {
(Some(x), Some(y)) => x.title.cmp(&y.title),
(None, Some(_)) => Ordering::Less,
(Some(_), None) => Ordering::Greater,
(None, None) => Ordering::Equal,
});

Some(SymbolContentCtx {
id: String::new(),
Expand Down Expand Up @@ -321,15 +327,15 @@ impl IndexCtx {
});

util::SectionCtx {
header: SectionHeaderCtx {
header: Some(SectionHeaderCtx {
href: Some(render_ctx.ctx.resolve_path(
render_ctx.get_current_resolve(),
UrlResolveKind::Category { category: &title },
)),
title,
anchor: AnchorCtx { id: anchor },
doc,
},
}),
content: util::SectionContentCtx::Empty,
}
})
Expand Down Expand Up @@ -394,12 +400,12 @@ impl IndexCtx {

(
render_ctx.clone(),
SectionHeaderCtx {
Some(SectionHeaderCtx {
anchor: AnchorCtx { id: title.clone() },
title,
href: None,
doc,
},
}),
nodes,
)
}),
Expand Down Expand Up @@ -463,7 +469,7 @@ impl AllSymbolsCtx {
partitions.into_iter().map(|(path, nodes)| {
let render_ctx =
RenderContext::new(ctx, &nodes, UrlResolveKind::AllSymbols);
let header = SectionHeaderCtx::new_for_namespace(&render_ctx, &path);
let header = SectionHeaderCtx::new_for_all_symbols(&render_ctx, &path);

(render_ctx, header, nodes)
}),
Expand Down
6 changes: 3 additions & 3 deletions src/html/symbols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl SymbolGroupCtx {
tags.insert(Tag::Permissions(permissions.into_iter().collect()));
}

if doc_nodes[0].is_internal() {
if doc_nodes[0].is_internal(ctx.ctx) {
tags.insert(Tag::Private);
}

Expand Down Expand Up @@ -341,12 +341,12 @@ impl SymbolInnerCtx {
|(title, nodes)| {
(
ctx.clone(),
crate::html::util::SectionHeaderCtx {
Some(crate::html::util::SectionHeaderCtx {
title: title.clone(),
anchor: AnchorCtx { id: title },
href: None,
doc: None,
},
}),
nodes,
)
},
Expand Down
15 changes: 11 additions & 4 deletions src/html/symbols/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use std::cmp::Ordering;

pub fn render_namespace<'a>(
partitions: impl Iterator<
Item = (RenderContext<'a>, SectionHeaderCtx, Vec<DocNodeWithContext>),
Item = (
RenderContext<'a>,
Option<SectionHeaderCtx>,
Vec<DocNodeWithContext>,
),
>,
) -> Vec<SectionCtx> {
partitions
Expand All @@ -22,7 +26,7 @@ pub fn render_namespace<'a>(

fn get_namespace_section_render_ctx(
ctx: &RenderContext,
header: SectionHeaderCtx,
header: Option<SectionHeaderCtx>,
doc_nodes: Vec<DocNodeWithContext>,
) -> SectionCtx {
let mut grouped_nodes = IndexMap::new();
Expand All @@ -37,7 +41,7 @@ fn get_namespace_section_render_ctx(
let nodes = grouped_nodes
.into_iter()
.filter_map(|(name, nodes)| {
if nodes[0].is_internal() {
if nodes[0].is_internal(ctx.ctx) {
None
} else {
Some(NamespaceNodeCtx::new(ctx, name, nodes))
Expand All @@ -47,7 +51,10 @@ fn get_namespace_section_render_ctx(

let mut section = SectionCtx::new(
ctx,
&header.title,
header
.as_ref()
.map(|header| header.title.as_str())
.unwrap_or_default(),
SectionContentCtx::NamespaceSection(nodes),
);
section.header = header;
Expand Down
30 changes: 16 additions & 14 deletions src/html/templates/section.hbs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<section class="section" id="{{header.anchor.id}}">
<div>
<h2 class="anchorable mb-1">
{{~> anchor header.anchor ~}}
<section class="section" {{#if header}} id="{{header.anchor.id}}"{{/if}}>
{{~#if header~}}
<div>
<h2 class="anchorable mb-1">
{{~> anchor header.anchor ~}}

{{~#if header.href~}}
<a href="{{header.href}}" class="contextLink">{{header.title}}</a>
{{~else~}}
{{header.title}}
{{~/if~}}
</h2>
{{~#if header.href~}}
<a href="{{header.href}}" class="contextLink">{{header.title}}</a>
{{~else~}}
{{header.title}}
{{~/if~}}
</h2>

{{~#if header.doc~}}
{{{header.doc}}} {{! markdown }}
{{~/if~}}
</div>
{{~#if header.doc~}}
{{{header.doc}}} {{! markdown }}
{{~/if~}}
</div>
{{~/if~}}

{{~#if (ne content.kind "empty")~}}
{{~#if (or (eq content.kind "namespace_section") (eq content.kind "see"))~}}
Expand Down
41 changes: 24 additions & 17 deletions src/html/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,14 @@ pub struct SectionHeaderCtx {
}

impl SectionHeaderCtx {
pub fn new_for_namespace(
pub fn new_for_all_symbols(
render_ctx: &RenderContext,
path: &ShortPath,
) -> Self {
) -> Option<Self> {
if render_ctx.ctx.file_mode == FileMode::SingleDts {
return None;
}

let module_doc_nodes = render_ctx.ctx.doc_nodes.get(path).unwrap();

let doc = module_doc_nodes
Expand All @@ -480,7 +484,7 @@ impl SectionHeaderCtx {

let title = path.display_name();

SectionHeaderCtx {
Some(SectionHeaderCtx {
title: title.to_string(),
anchor: AnchorCtx {
id: title.to_string(),
Expand All @@ -490,13 +494,13 @@ impl SectionHeaderCtx {
path.as_resolve_kind(),
)),
doc,
}
})
}
}

#[derive(Debug, Serialize, Clone)]
pub struct SectionCtx {
pub header: SectionHeaderCtx,
pub header: Option<SectionHeaderCtx>,
pub content: SectionContentCtx,
}

Expand All @@ -508,8 +512,19 @@ impl SectionCtx {
title: &str,
mut content: SectionContentCtx,
) -> Self {
let anchor = render_context.toc.anchorize(title);
render_context.toc.add_entry(1, title, &anchor);
let header = if !title.is_empty() {
let anchor = render_context.toc.anchorize(title);
render_context.toc.add_entry(1, title, &anchor);

Some(SectionHeaderCtx {
title: title.to_string(),
anchor: AnchorCtx { id: anchor },
href: None,
doc: None,
})
} else {
None
};

match &mut content {
SectionContentCtx::DocEntry(entries) => {
Expand Down Expand Up @@ -555,15 +570,7 @@ impl SectionCtx {
SectionContentCtx::Empty => {}
}

Self {
header: SectionHeaderCtx {
title: title.to_string(),
anchor: AnchorCtx { id: anchor },
href: None,
doc: None,
},
content,
}
Self { header, content }
}
}

Expand Down Expand Up @@ -699,7 +706,7 @@ impl TopSymbolsCtx {
true,
)
})
.filter(|(_name, node)| !node[0].is_internal())
.filter(|(_name, node)| !node[0].is_internal(ctx.ctx))
.collect::<Vec<_>>();

if partitions.is_empty() {
Expand Down
Loading
Loading