Skip to content

Commit 73ddbe2

Browse files
committed
Make it possible to link to a signature
Resolves #1326.
1 parent f06aaa9 commit 73ddbe2

File tree

10 files changed

+44
-22
lines changed

10 files changed

+44
-22
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"prettier.configPath": ".config/.prettierrc.json",
1111
"prettier.ignorePath": ".config/.prettierignore",
1212
"eslint.workingDirectories": [".", "./example"],
13-
"mochaExplorer.configFile": ".config/mocha.test-explorer.json"
13+
"mochaExplorer.configFile": ".config/mocha.test-explorer.json",
14+
"cSpell.words": ["tsbuildinfo"]
1415
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ These TODOs will be resolved before a full release. ([GitHub project](https://gi
3939
- TypeDoc will now render members marked with `@deprecated` with a line through their name, #1381.
4040
- TypeDoc will now warn if part of a comment will be overwritten due to use of `@inheritDoc` instead of silently dropping part of the comment.
4141
- Added support for inline `@inheritDoc` tags, #1480.
42+
- It is now possible to link directly to a specific overload, #1326.
4243

4344
### Bug Fixes
4445

src/lib/models/comments/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { Comment, CommentTag } from "./comment";
2-
export type { CommentDisplayPart } from "./comment";
2+
export type { CommentDisplayPart, InlineTagDisplayPart } from "./comment";

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ProjectReflection,
88
ContainerReflection,
99
DeclarationReflection,
10+
SignatureReflection,
1011
} from "../../../models";
1112
import { RenderTemplate, UrlMapping } from "../../models/UrlMapping";
1213
import { PageEvent, RendererEvent } from "../../events";
@@ -211,9 +212,14 @@ export class DefaultTheme extends Theme {
211212
reflection.hasOwnDocument = true;
212213
}
213214

214-
for (const child of reflection.children || []) {
215-
this.buildUrls(child, urls);
216-
}
215+
reflection.traverse((child) => {
216+
if (child instanceof DeclarationReflection) {
217+
this.buildUrls(child, urls);
218+
} else {
219+
DefaultTheme.applyAnchorUrl(child, reflection);
220+
}
221+
return true;
222+
});
217223
} else if (reflection.parent) {
218224
DefaultTheme.applyAnchorUrl(reflection, reflection.parent);
219225
}
@@ -233,6 +239,10 @@ export class DefaultTheme extends Theme {
233239
* @param container The nearest reflection having an own document.
234240
*/
235241
static applyAnchorUrl(reflection: Reflection, container: Reflection) {
242+
if (!(reflection instanceof DeclarationReflection) && !(reflection instanceof SignatureReflection)) {
243+
return;
244+
}
245+
236246
if (!reflection.url || !DefaultTheme.URL_PREFIX.test(reflection.url)) {
237247
const anchor = DefaultTheme.getUrl(reflection, container, ".");
238248

@@ -242,9 +252,7 @@ export class DefaultTheme extends Theme {
242252
}
243253

244254
reflection.traverse((child) => {
245-
if (child instanceof DeclarationReflection) {
246-
DefaultTheme.applyAnchorUrl(child, container);
247-
}
255+
DefaultTheme.applyAnchorUrl(child, container);
248256
return true;
249257
});
250258
}

src/lib/output/themes/default/assets/typedoc/components/Signature.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,24 @@ class SignatureGroup {
3131
*
3232
* @param className The class name to add.
3333
*/
34-
addClass(className: string): SignatureGroup {
34+
addClass(className: string) {
3535
this.signature.classList.add(className);
3636
this.description.classList.add(className);
37-
return this;
3837
}
3938

4039
/**
4140
* Remove the given class from all elements of the group.
4241
*
4342
* @param className The class name to remove.
4443
*/
45-
removeClass(className: string): SignatureGroup {
44+
removeClass(className: string) {
4645
this.signature.classList.remove(className);
4746
this.description.classList.remove(className);
48-
return this;
4947
}
5048
}
5149

5250
/**
53-
* Controls the tab like behaviour of methods and functions with multiple signatures.
51+
* Controls the tab like behavior of methods and functions with multiple signatures.
5452
*/
5553
export class Signature extends Component {
5654
/**
@@ -89,7 +87,7 @@ export class Signature extends Component {
8987
);
9088
});
9189
this.container.classList.add("active");
92-
this.setIndex(0);
90+
this.setIndex(this.inferIndexFromHash());
9391
}
9492
}
9593

@@ -107,9 +105,17 @@ export class Signature extends Component {
107105
if (this.index > -1) {
108106
const from = this.groups[this.index];
109107

110-
from.removeClass("current").addClass("fade-out");
108+
from.removeClass("current");
109+
from.addClass("fade-out");
111110
to.addClass("current");
112111
to.addClass("fade-in");
112+
113+
if (to.signature.id) {
114+
const target = new URL(location.href);
115+
target.hash = to.signature.id;
116+
history.replaceState({}, "", target);
117+
}
118+
113119
Viewport.instance.triggerResize();
114120

115121
setTimeout(() => {
@@ -154,4 +160,10 @@ export class Signature extends Component {
154160
}
155161
});
156162
}
163+
164+
private inferIndexFromHash() {
165+
const hash = location.hash.substring(1);
166+
const index = this.groups.findIndex((s) => s.signature.id === hash);
167+
return Math.max(0, index);
168+
}
157169
}

src/lib/output/themes/default/partials/member.getterSetter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export const memberGetterSetter = (context: DefaultThemeRenderContext, props: De
66
<>
77
<ul class={"tsd-signatures " + props.cssClasses}>
88
{!!props.getSignature && (
9-
<li class="tsd-signature">
9+
<li class="tsd-signature" id={props.getSignature.anchor}>
1010
<span class="tsd-signature-symbol">get</span> {props.name}
1111
{context.memberSignatureTitle(props.getSignature, {
1212
hideName: true,
1313
})}
1414
</li>
1515
)}
1616
{!!props.setSignature && (
17-
<li class="tsd-signature">
17+
<li class="tsd-signature" id={props.setSignature.anchor}>
1818
<span class="tsd-signature-symbol">set</span> {props.name}
1919
{context.memberSignatureTitle(props.setSignature, {
2020
hideName: true,

src/lib/output/themes/default/partials/member.signatures.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export const memberSignatures = (context: DefaultThemeRenderContext, props: Decl
66
<>
77
<ul class={"tsd-signatures " + props.cssClasses}>
88
{props.signatures?.map((item) => (
9-
<li class="tsd-signature">{context.memberSignatureTitle(item)}</li>
9+
<li class="tsd-signature" id={item.anchor}>
10+
{context.memberSignatureTitle(item)}
11+
</li>
1012
))}
1113
</ul>
1214

src/lib/output/themes/default/partials/parameter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const parameter = (context: DefaultThemeRenderContext, props: Declaration
1010
<li class="tsd-parameter-signature">
1111
<ul class={"tsd-signatures " + props.cssClasses}>
1212
{props.signatures.map((item) => (
13-
<li class="tsd-signature">
13+
<li class="tsd-signature" id={item.anchor}>
1414
{context.memberSignatureTitle(item, {
1515
hideName: true,
1616
})}

static/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ h4,
137137
h5,
138138
h6 {
139139
line-height: 1.2;
140-
141140
}
142141

143142
h1 {

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
"src/test/module",
5454
"src/test/packages",
5555
"src/test/slow/entry-points",
56-
"src/test/renderer/testProject",
57-
"src/codegen"
56+
"src/test/renderer/testProject"
5857
],
5958
// We use ts-node to support mocha runner directly on files
6059
"ts-node": {

0 commit comments

Comments
 (0)