Skip to content

Commit ec9efa0

Browse files
committed
Fix source links for signatures
Closes TypeStrong#180 Closes TypeStrong#1996
1 parent 70ab81a commit ec9efa0

File tree

10 files changed

+59
-5
lines changed

10 files changed

+59
-5
lines changed

.config/typedoc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"MarkedPlugin"
1212
],
1313
"entryPoints": ["../src"],
14-
"entryPointStrategy": "Resolve",
14+
"entryPointStrategy": "resolve",
1515
"excludeExternals": true,
1616
"excludeInternal": false,
1717
"excludePrivate": true,

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
- Added support for `*.ghe.com` and `*.github.us` GitHub enterprise domains for source links, #2001.
66
- Expose `Converter.parseRawComment` for plugins to parse additional markdown files, #2004.
7+
- Added defined in links for classes, enums #180.
8+
9+
### Bug Fixes
10+
11+
- Fixed missing `sources` property on signature reflections #1996.
712

813
### Thanks!
914

src/lib/converter/converter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export class Converter extends ChildableComponent<
9494

9595
/**
9696
* Triggered when the converter has created a signature reflection.
97-
* The listener will be given {@link Context}, {@link SignatureReflection} | {@link ProjectReflection} and a `ts.Node?`
97+
* The listener will be given {@link Context}, {@link SignatureReflection} | {@link ProjectReflection} and
98+
* `ts.SignatureDeclaration | ts.IndexSignatureDeclaration | ts.JSDocSignature | undefined`
9899
* @event
99100
*/
100101
static readonly EVENT_CREATE_SIGNATURE = ConverterEvents.CREATE_SIGNATURE;

src/lib/converter/factories/signature.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function createSignature(
9898
break;
9999
}
100100

101-
context.trigger(ConverterEvents.CREATE_SIGNATURE, sigRef);
101+
context.trigger(ConverterEvents.CREATE_SIGNATURE, sigRef, declaration);
102102
}
103103

104104
function convertParameters(

src/lib/converter/plugins/SourcePlugin.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class SourcePlugin extends ConverterComponent {
5050
this.listenTo(this.owner, {
5151
[Converter.EVENT_END]: this.onEnd,
5252
[Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,
53-
[Converter.EVENT_CREATE_SIGNATURE]: this.onDeclaration,
53+
[Converter.EVENT_CREATE_SIGNATURE]: this.onSignature,
5454
[Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve,
5555
});
5656
}
@@ -101,6 +101,31 @@ export class SourcePlugin extends ConverterComponent {
101101
}
102102
}
103103

104+
private onSignature(
105+
_context: Context,
106+
reflection: Reflection,
107+
sig?:
108+
| ts.SignatureDeclaration
109+
| ts.IndexSignatureDeclaration
110+
| ts.JSDocSignature
111+
) {
112+
if (this.disableSources || !sig) return;
113+
114+
const sourceFile = sig.getSourceFile();
115+
const fileName = sourceFile.fileName;
116+
this.fileNames.add(fileName);
117+
118+
const position = ts.getLineAndCharacterOfPosition(
119+
sourceFile,
120+
sig.getStart()
121+
);
122+
123+
reflection.sources ||= [];
124+
reflection.sources.push(
125+
new SourceReference(fileName, position.line + 1, position.character)
126+
);
127+
}
128+
104129
/**
105130
* Triggered when the converter begins resolving a project.
106131
*

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

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa
7171
context.parameter(props.model.indexSignature.type.declaration)}
7272
</section>
7373
)}
74+
{!props.model.signatures && context.memberSources(props.model)}
7475
</>
7576
)}
7677
{!!props.model.children?.length && context.index(props.model)}

src/test/converter/comment/specs.json

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@
9999
"kind": 2048,
100100
"kindString": "Method",
101101
"flags": {},
102+
"sources": [
103+
{
104+
"fileName": "comment.ts",
105+
"line": 77,
106+
"character": 4,
107+
"url": "typedoc://comment.ts#L77"
108+
}
109+
],
102110
"signatures": [
103111
{
104112
"id": 22,

src/test/converter2/issues/gh1996.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const a = () => {};
2+
3+
export function b() {}

src/test/issueTests.ts

+11
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,15 @@ export const issueTests: {
608608
logger.discardDebugMessages();
609609
logger.expectNoOtherMessages();
610610
},
611+
612+
gh1996(project) {
613+
const a = query(project, "a");
614+
equal(a.signatures![0].sources?.[0].fileName, "gh1996.ts");
615+
equal(a.signatures![0].sources?.[0].line, 1);
616+
equal(a.signatures![0].sources?.[0].character, 17);
617+
const b = query(project, "b");
618+
equal(b.signatures![0].sources?.[0].fileName, "gh1996.ts");
619+
equal(b.signatures![0].sources?.[0].line, 3);
620+
equal(b.signatures![0].sources?.[0].character, 0);
621+
},
611622
};

static/style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ a.tsd-index-link {
942942
margin: 2rem 0;
943943
}
944944
.tsd-panel-group.tsd-index-group details {
945-
margin: 4rem 0;
945+
margin: 2rem 0;
946946
}
947947

948948
#tsd-search {

0 commit comments

Comments
 (0)