Skip to content

Commit 0c5d952

Browse files
committed
fixes
1 parent 9ea3e9f commit 0c5d952

10 files changed

Lines changed: 175 additions & 130 deletions

File tree

js/html_types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ export interface DocEntryCtx {
334334
source_href: string | null;
335335
diff_status?: DiffStatus;
336336
old_content?: string;
337-
js_doc_changed?: boolean;
338337
}
339338

340339
export interface ExampleCtx {

src/html/symbols/class.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn render_constructors(
183183
let diff_status =
184184
get_constructor_diff_status(constructor_changes, constructor);
185185

186-
let (old_content, js_doc_changed) =
186+
let (old_content, ctor_diff) =
187187
if matches!(diff_status, Some(DiffStatus::Modified)) {
188188
let param_count = constructor.params.len();
189189
let ctor_diff = constructor_changes.and_then(|cc| {
@@ -193,9 +193,7 @@ fn render_constructors(
193193
let old_content = ctor_diff.and_then(|cd| {
194194
render_old_class_constructor_summary(ctx, &constructor.params, cd)
195195
});
196-
let js_doc_changed =
197-
ctor_diff.and_then(|cd| cd.js_doc_change.as_ref().map(|_| true));
198-
(old_content, js_doc_changed)
196+
(old_content, ctor_diff)
199197
} else {
200198
(None, None)
201199
};
@@ -212,7 +210,7 @@ fn render_constructors(
212210
diff_status,
213211
old_content,
214212
None,
215-
js_doc_changed,
213+
ctor_diff.and_then(|cd| cd.js_doc_change.as_ref()),
216214
);
217215
entry.name_prefix = Some("new".into());
218216

@@ -623,7 +621,7 @@ fn render_class_accessor(
623621
let diff_status =
624622
get_method_diff_status(method_changes, name, getter_or_setter.kind);
625623

626-
let (old_content, old_tags, js_doc_changed) = if matches!(
624+
let (old_content, old_tags, any_diff) = if matches!(
627625
diff_status,
628626
Some(DiffStatus::Modified | DiffStatus::Renamed { .. })
629627
) {
@@ -658,10 +656,7 @@ fn render_class_accessor(
658656
)
659657
});
660658

661-
let js_doc_changed =
662-
any_diff.and_then(|md| md.js_doc_change.as_ref().map(|_| true));
663-
664-
(old_content, old_tags, js_doc_changed)
659+
(old_content, old_tags, any_diff)
665660
} else {
666661
(None, None, None)
667662
};
@@ -682,7 +677,7 @@ fn render_class_accessor(
682677
diff_status,
683678
old_content,
684679
old_tags,
685-
js_doc_changed,
680+
any_diff.and_then(|md| md.js_doc_change.as_ref()),
686681
)
687682
}
688683

@@ -717,7 +712,7 @@ fn render_class_method(
717712
let diff_status =
718713
get_method_diff_status(method_changes, &method.name, method.kind);
719714

720-
let (old_content, old_tags, js_doc_changed) = if matches!(
715+
let (old_content, old_tags, method_diff) = if matches!(
721716
diff_status,
722717
Some(DiffStatus::Modified | DiffStatus::Renamed { .. })
723718
) {
@@ -748,10 +743,7 @@ fn render_class_method(
748743
)
749744
});
750745

751-
let js_doc_changed =
752-
method_diff.and_then(|md| md.js_doc_change.as_ref().map(|_| true));
753-
754-
(old_content, old_tags, js_doc_changed)
746+
(old_content, old_tags, method_diff)
755747
} else {
756748
(None, None, None)
757749
};
@@ -777,7 +769,7 @@ fn render_class_method(
777769
diff_status,
778770
old_content,
779771
old_tags,
780-
js_doc_changed,
772+
method_diff.and_then(|md| md.js_doc_change.as_ref()),
781773
))
782774
}
783775

@@ -815,7 +807,7 @@ fn render_class_property(
815807
let diff_status = get_property_diff_status(property_changes, &property.name);
816808

817809
// For modified/renamed properties, render the old type and old tags
818-
let (old_content, old_tags, js_doc_changed) = if matches!(
810+
let (old_content, old_tags, prop_diff) = if matches!(
819811
diff_status,
820812
Some(DiffStatus::Modified | DiffStatus::Renamed { .. })
821813
) {
@@ -836,10 +828,7 @@ fn render_class_property(
836828
)
837829
});
838830

839-
let js_doc_changed =
840-
prop_diff.and_then(|pd| pd.js_doc_change.as_ref().map(|_| true));
841-
842-
(old_content, old_tags, js_doc_changed)
831+
(old_content, old_tags, prop_diff)
843832
} else {
844833
(None, None, None)
845834
};
@@ -860,7 +849,7 @@ fn render_class_property(
860849
diff_status,
861850
old_content,
862851
old_tags,
863-
js_doc_changed,
852+
prop_diff.and_then(|pd| pd.js_doc_change.as_ref()),
864853
)
865854
}
866855

src/html/symbols/enum.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) fn render_enum(
5959
None
6060
};
6161

62-
let (old_content, old_tags, js_doc_changed) =
62+
let (old_content, old_tags, member_diff) =
6363
if matches!(diff_status, Some(DiffStatus::Modified)) {
6464
let member_diff = enum_diff.and_then(|d| {
6565
d.modified_members.iter().find(|m| m.name == member.name)
@@ -69,9 +69,7 @@ pub(crate) fn render_enum(
6969
.map(|tc| format!(" = {}", render_type_def(render_ctx, &tc.old)));
7070
let old_tags =
7171
Some(super::compute_old_tags(&tags, None, None, None, None));
72-
let js_doc_changed =
73-
member_diff.and_then(|md| md.js_doc_change.as_ref().map(|_| true));
74-
(old_content, old_tags, js_doc_changed)
72+
(old_content, old_tags, member_diff)
7573
} else {
7674
(None, None, None)
7775
};
@@ -92,7 +90,7 @@ pub(crate) fn render_enum(
9290
diff_status,
9391
old_content,
9492
old_tags,
95-
js_doc_changed,
93+
member_diff.and_then(|md| md.js_doc_change.as_ref()),
9694
)
9795
})
9896
.collect::<Vec<DocEntryCtx>>();

src/html/symbols/function.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,15 @@ fn render_single_function(
500500
crate::html::diff::filter_sections_diff_only(&mut sections, &ctx.toc);
501501
}
502502

503-
// If there's a doc text change, re-render docs with inline diff
503+
// If there's a doc text change, re-render docs with inline diff;
504+
// otherwise in diff_only mode, hide the unchanged docs.
504505
if let Some(diff_docs) = render_overload_docs_with_diff(ctx, doc_node) {
505506
docs = Some(diff_docs);
507+
} else if ctx.ctx.diff_only
508+
&& !crate::html::diff::is_symbol_added(doc_node)
509+
&& !crate::html::diff::is_symbol_removed(doc_node)
510+
{
511+
docs = None;
506512
}
507513

508514
SymbolContentCtx {

src/html/symbols/interface.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,21 @@ pub(crate) fn render_call_signatures(
158158
None
159159
};
160160

161-
let (old_content, js_doc_changed) =
162-
if matches!(diff_status, Some(DiffStatus::Modified)) {
163-
let old_content = sig_diff.and_then(|sd| {
164-
super::function::render_old_function_summary(
165-
ctx,
166-
&call_signature.type_params,
167-
&call_signature.params,
168-
&call_signature.ts_type,
169-
sd.type_params_change.as_ref(),
170-
sd.params_change.as_ref(),
171-
sd.ts_type_change.as_ref(),
172-
)
173-
});
174-
let js_doc_changed =
175-
sig_diff.and_then(|sd| sd.js_doc_change.as_ref().map(|_| true));
176-
(old_content, js_doc_changed)
177-
} else {
178-
(None, None)
179-
};
161+
let old_content = if matches!(diff_status, Some(DiffStatus::Modified)) {
162+
sig_diff.and_then(|sd| {
163+
super::function::render_old_function_summary(
164+
ctx,
165+
&call_signature.type_params,
166+
&call_signature.params,
167+
&call_signature.ts_type,
168+
sd.type_params_change.as_ref(),
169+
sd.params_change.as_ref(),
170+
sd.ts_type_change.as_ref(),
171+
)
172+
})
173+
} else {
174+
None
175+
};
180176

181177
DocEntryCtx::new(
182178
ctx,
@@ -194,7 +190,7 @@ pub(crate) fn render_call_signatures(
194190
diff_status,
195191
old_content,
196192
old_tags,
197-
js_doc_changed,
193+
sig_diff.and_then(|sd| sd.js_doc_change.as_ref()),
198194
)
199195
})
200196
.collect::<Vec<DocEntryCtx>>();
@@ -311,7 +307,7 @@ pub(crate) fn render_properties(
311307
None
312308
};
313309

314-
let (old_content, old_tags, js_doc_changed) = if matches!(
310+
let (old_content, old_tags, prop_diff) = if matches!(
315311
diff_status,
316312
Some(DiffStatus::Modified | DiffStatus::Renamed { .. })
317313
) {
@@ -332,10 +328,7 @@ pub(crate) fn render_properties(
332328
)
333329
});
334330

335-
let js_doc_changed =
336-
prop_diff.and_then(|pd| pd.js_doc_change.as_ref().map(|_| true));
337-
338-
(old_content, old_tags, js_doc_changed)
331+
(old_content, old_tags, prop_diff)
339332
} else {
340333
(None, None, None)
341334
};
@@ -360,7 +353,7 @@ pub(crate) fn render_properties(
360353
diff_status,
361354
old_content,
362355
old_tags,
363-
js_doc_changed,
356+
prop_diff.and_then(|pd| pd.js_doc_change.as_ref()),
364357
)
365358
})
366359
.collect::<Vec<DocEntryCtx>>();
@@ -447,7 +440,7 @@ pub(crate) fn render_methods(
447440
None
448441
};
449442

450-
let (old_content, old_tags, js_doc_changed) = if matches!(
443+
let (old_content, old_tags, method_diff) = if matches!(
451444
diff_status,
452445
Some(DiffStatus::Modified | DiffStatus::Renamed { .. })
453446
) {
@@ -476,10 +469,7 @@ pub(crate) fn render_methods(
476469
)
477470
});
478471

479-
let js_doc_changed =
480-
method_diff.and_then(|md| md.js_doc_change.as_ref().map(|_| true));
481-
482-
(old_content, old_tags, js_doc_changed)
472+
(old_content, old_tags, method_diff)
483473
} else {
484474
(None, None, None)
485475
};
@@ -504,7 +494,7 @@ pub(crate) fn render_methods(
504494
diff_status,
505495
old_content,
506496
old_tags,
507-
js_doc_changed,
497+
method_diff.and_then(|md| md.js_doc_change.as_ref()),
508498
)
509499
})
510500
.collect::<Vec<DocEntryCtx>>();

src/html/symbols/mod.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -632,25 +632,33 @@ impl SymbolInnerCtx {
632632
crate::html::diff::filter_sections_diff_only(&mut sections, &ctx.toc);
633633
}
634634

635-
// If there's a doc text change, re-render docs with inline diff
636-
if let Some(diff_docs) = ctx.ctx.diff.as_ref().and_then(|diff_index| {
637-
let info = diff_index.get_node_diff(
638-
&doc_node.origin.specifier,
639-
doc_node.get_name(),
640-
doc_node.def.to_kind(),
641-
)?;
642-
let doc_change = info
635+
let doc_change = ctx.ctx.diff.as_ref().and_then(|diff_index| {
636+
diff_index
637+
.get_node_diff(
638+
&doc_node.origin.specifier,
639+
doc_node.get_name(),
640+
doc_node.def.to_kind(),
641+
)?
643642
.diff
644643
.as_ref()?
645644
.js_doc_changes
646645
.as_ref()?
647646
.doc_change
648-
.as_ref()?;
649-
let old_doc = doc_change.old.as_deref().unwrap_or_default();
647+
.as_ref()
648+
});
649+
if let Some(dc) = doc_change {
650+
let old_doc = dc.old.as_deref().unwrap_or_default();
650651
let new_doc = doc_node.js_doc.doc.as_deref().unwrap_or_default();
651-
crate::html::jsdoc::render_docs_with_diff(ctx, old_doc, new_doc)
652-
}) {
653-
docs = Some(diff_docs);
652+
if let Some(diff_docs) =
653+
crate::html::jsdoc::render_docs_with_diff(ctx, old_doc, new_doc)
654+
{
655+
docs = Some(diff_docs);
656+
}
657+
} else if ctx.ctx.diff_only
658+
&& !is_symbol_added(doc_node)
659+
&& !is_symbol_removed(doc_node)
660+
{
661+
docs = None;
654662
}
655663

656664
content_parts.push(SymbolInnerCtx::Other(SymbolContentCtx {

src/html/util.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::diff::JsDocDiff;
12
use crate::html::DiffStatus;
23
use crate::html::DocNodeKind;
34
use crate::html::DocNodeWithContext;
@@ -775,8 +776,6 @@ pub struct DocEntryCtx {
775776
pub diff_status: Option<DiffStatus>,
776777
#[serde(skip_serializing_if = "Option::is_none")]
777778
pub old_content: Option<String>,
778-
#[serde(skip_serializing_if = "Option::is_none")]
779-
pub js_doc_changed: Option<bool>,
780779
}
781780

782781
impl DocEntryCtx {
@@ -795,10 +794,17 @@ impl DocEntryCtx {
795794
diff_status: Option<DiffStatus>,
796795
old_content: Option<String>,
797796
old_tags: Option<IndexSet<Tag>>,
798-
js_doc_changed: Option<bool>,
797+
js_doc_diff: Option<&JsDocDiff>,
799798
) -> Self {
800-
let maybe_jsdoc =
801-
jsdoc.map(|doc| crate::html::jsdoc::render_markdown(ctx, doc, true));
799+
let maybe_jsdoc = if let Some(doc_change) =
800+
js_doc_diff.and_then(|d| d.doc_change.as_ref())
801+
{
802+
let old_doc = doc_change.old.as_deref().unwrap_or_default();
803+
let new_doc = jsdoc.unwrap_or_default();
804+
crate::html::jsdoc::render_docs_with_diff(ctx, old_doc, new_doc)
805+
} else {
806+
jsdoc.map(|doc| crate::html::jsdoc::render_markdown(ctx, doc, true))
807+
};
802808
let source_href = ctx.ctx.href_resolver.resolve_source(location);
803809

804810
DocEntryCtx {
@@ -812,7 +818,6 @@ impl DocEntryCtx {
812818
source_href,
813819
diff_status,
814820
old_content,
815-
js_doc_changed,
816821
}
817822
}
818823

0 commit comments

Comments
 (0)