Skip to content

Commit 2318949

Browse files
committed
Include all base classes
Resolves #2486
1 parent ece4f31 commit 2318949

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
- Added support for the `@class` tag. When added to a comment on a variable or function, TypeDoc will convert the member as a class, #2479.
77
Note: This should only be used on symbols which actually represent a class, but are not declared as a class for some reason.
88
- Added support for `@groupDescription` and `@categoryDescription` to provide a description of groups and categories, #2494.
9-
- Exposed `Context.getNodeComment` for plugin use, #2498.
9+
- API: Exposed `Context.getNodeComment` for plugin use, #2498.
1010

1111
## Bug Fixes
1212

1313
- Fixed an issue where a namespace would not be created for merged function-namespaces which are declared as variables, #2478.
1414
- A class which implements itself will no longer cause a crash when rendering HTML, #2495.
1515
- Variable functions which have construct signatures will no longer be converted as functions, ignoring the construct signatures.
16+
- The class hierarchy page will now include classes whose base class is not included in the documentation, #2486.
1617
- Fixed an issue where, if the index section was collapsed when loading the page, all content within it would be hidden until expanded, and a member visibility checkbox was changed.
17-
- `Context.programs` will no longer contain duplicates, #2498.
18+
- API: `Context.programs` will no longer contain duplicates, #2498.
1819

1920
## v0.25.7 (2024-01-08)
2021

src/lib/output/themes/default/DefaultTheme.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { PageEvent } from "../../events";
1616
import type { MarkedPlugin } from "../../plugins";
1717
import { DefaultThemeRenderContext } from "./DefaultThemeRenderContext";
1818
import { JSX } from "../../../utils";
19-
import { classNames, getDisplayName, toStyleClass } from "../lib";
19+
import { classNames, getDisplayName, getHierarchyRoots, toStyleClass } from "../lib";
2020

2121
/**
2222
* Defines a mapping of a {@link Models.Kind} to a template file.
@@ -155,7 +155,7 @@ export class DefaultTheme extends Theme {
155155
urls.push(new UrlMapping("index.html", project, this.indexTemplate));
156156
}
157157

158-
if (includeHierarchyPage(project)) {
158+
if (getHierarchyRoots(project).length) {
159159
urls.push(new UrlMapping("hierarchy.html", project, this.hierarchyTemplate));
160160
}
161161

@@ -465,17 +465,3 @@ function shouldShowGroups(reflection: Reflection, opts: { includeCategories: boo
465465
}
466466
return reflection.comment?.hasModifier("@showGroups") === true;
467467
}
468-
469-
function includeHierarchyPage(project: ProjectReflection) {
470-
for (const id in project.reflections) {
471-
const refl = project.reflections[id] as DeclarationReflection;
472-
473-
if (refl.kindOf(ReflectionKind.ClassOrInterface)) {
474-
// Keep this condition in sync with the one in hierarchy.tsx for determining roots
475-
if (!(refl.implementedTypes || refl.extendedTypes) && (refl.implementedBy || refl.extendedBy)) {
476-
return true;
477-
}
478-
}
479-
}
480-
return false;
481-
}

src/lib/output/themes/default/templates/hierarchy.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
22
import type { PageEvent } from "../../../events";
33
import { JSX } from "../../../../utils";
4-
import { ReflectionKind, type ProjectReflection, DeclarationReflection } from "../../../../models";
4+
import { getHierarchyRoots } from "../../lib";
5+
import type { DeclarationReflection, ProjectReflection } from "../../../../models";
56

67
function fullHierarchy(
78
context: DefaultThemeRenderContext,
@@ -34,15 +35,10 @@ function fullHierarchy(
3435
}
3536

3637
export function hierarchyTemplate(context: DefaultThemeRenderContext, props: PageEvent<ProjectReflection>) {
37-
// Keep this condition in sync with the one in DefaultTheme.tsx
38-
const roots = (props.project.getReflectionsByKind(ReflectionKind.ClassOrInterface) as DeclarationReflection[])
39-
.filter((refl) => !(refl.implementedTypes || refl.extendedTypes) && (refl.implementedBy || refl.extendedBy))
40-
.sort((a, b) => a.name.localeCompare(b.name));
41-
4238
return (
4339
<>
4440
<h2>Class Hierarchy</h2>
45-
{roots.map((root) => (
41+
{getHierarchyRoots(props.project).map((root) => (
4642
<ul class="tsd-full-hierarchy">{fullHierarchy(context, root)}</ul>
4743
))}
4844
</>

src/lib/output/themes/lib.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,34 @@ export function renderName(refl: Reflection) {
157157

158158
return wbr(refl.name);
159159
}
160+
161+
export function getHierarchyRoots(project: ProjectReflection): DeclarationReflection[] {
162+
const allClasses = project.getReflectionsByKind(ReflectionKind.ClassOrInterface) as DeclarationReflection[];
163+
164+
const roots = allClasses.filter((refl) => {
165+
// If nobody extends this class, there's no possible hierarchy to display.
166+
if (!refl.implementedBy && !refl.extendedBy) {
167+
return false;
168+
}
169+
170+
// If we don't extend anything, then we are a root
171+
if (!refl.implementedTypes && !refl.extendedTypes) {
172+
return true;
173+
}
174+
175+
// We might still be a root, if our extended/implemented types are not included
176+
// in the documentation.
177+
const types = [...(refl.implementedTypes || []), ...(refl.extendedTypes || [])];
178+
179+
return types.every(
180+
(type) =>
181+
!type.visit({
182+
reference(ref) {
183+
return ref.reflection !== undefined;
184+
},
185+
}),
186+
);
187+
});
188+
189+
return roots.sort((a, b) => a.name.localeCompare(b.name));
190+
}

0 commit comments

Comments
 (0)