Skip to content

Commit

Permalink
Fix source links for signatures
Browse files Browse the repository at this point in the history
Closes #180
Closes #1996
  • Loading branch information
Gerrit0 committed Jul 17, 2022
1 parent 70ab81a commit ec9efa0
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .config/typedoc.json
Expand Up @@ -11,7 +11,7 @@
"MarkedPlugin"
],
"entryPoints": ["../src"],
"entryPointStrategy": "Resolve",
"entryPointStrategy": "resolve",
"excludeExternals": true,
"excludeInternal": false,
"excludePrivate": true,
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,11 @@

- Added support for `*.ghe.com` and `*.github.us` GitHub enterprise domains for source links, #2001.
- Expose `Converter.parseRawComment` for plugins to parse additional markdown files, #2004.
- Added defined in links for classes, enums #180.

### Bug Fixes

- Fixed missing `sources` property on signature reflections #1996.

### Thanks!

Expand Down
3 changes: 2 additions & 1 deletion src/lib/converter/converter.ts
Expand Up @@ -94,7 +94,8 @@ export class Converter extends ChildableComponent<

/**
* Triggered when the converter has created a signature reflection.
* The listener will be given {@link Context}, {@link SignatureReflection} | {@link ProjectReflection} and a `ts.Node?`
* The listener will be given {@link Context}, {@link SignatureReflection} | {@link ProjectReflection} and
* `ts.SignatureDeclaration | ts.IndexSignatureDeclaration | ts.JSDocSignature | undefined`
* @event
*/
static readonly EVENT_CREATE_SIGNATURE = ConverterEvents.CREATE_SIGNATURE;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/factories/signature.ts
Expand Up @@ -98,7 +98,7 @@ export function createSignature(
break;
}

context.trigger(ConverterEvents.CREATE_SIGNATURE, sigRef);
context.trigger(ConverterEvents.CREATE_SIGNATURE, sigRef, declaration);
}

function convertParameters(
Expand Down
27 changes: 26 additions & 1 deletion src/lib/converter/plugins/SourcePlugin.ts
Expand Up @@ -50,7 +50,7 @@ export class SourcePlugin extends ConverterComponent {
this.listenTo(this.owner, {
[Converter.EVENT_END]: this.onEnd,
[Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,
[Converter.EVENT_CREATE_SIGNATURE]: this.onDeclaration,
[Converter.EVENT_CREATE_SIGNATURE]: this.onSignature,
[Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve,
});
}
Expand Down Expand Up @@ -101,6 +101,31 @@ export class SourcePlugin extends ConverterComponent {
}
}

private onSignature(
_context: Context,
reflection: Reflection,
sig?:
| ts.SignatureDeclaration
| ts.IndexSignatureDeclaration
| ts.JSDocSignature
) {
if (this.disableSources || !sig) return;

const sourceFile = sig.getSourceFile();
const fileName = sourceFile.fileName;
this.fileNames.add(fileName);

const position = ts.getLineAndCharacterOfPosition(
sourceFile,
sig.getStart()
);

reflection.sources ||= [];
reflection.sources.push(
new SourceReference(fileName, position.line + 1, position.character)
);
}

/**
* Triggered when the converter begins resolving a project.
*
Expand Down
1 change: 1 addition & 0 deletions src/lib/output/themes/default/templates/reflection.tsx
Expand Up @@ -71,6 +71,7 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa
context.parameter(props.model.indexSignature.type.declaration)}
</section>
)}
{!props.model.signatures && context.memberSources(props.model)}
</>
)}
{!!props.model.children?.length && context.index(props.model)}
Expand Down
8 changes: 8 additions & 0 deletions src/test/converter/comment/specs.json
Expand Up @@ -99,6 +99,14 @@
"kind": 2048,
"kindString": "Method",
"flags": {},
"sources": [
{
"fileName": "comment.ts",
"line": 77,
"character": 4,
"url": "typedoc://comment.ts#L77"
}
],
"signatures": [
{
"id": 22,
Expand Down
3 changes: 3 additions & 0 deletions src/test/converter2/issues/gh1996.ts
@@ -0,0 +1,3 @@
export const a = () => {};

export function b() {}
11 changes: 11 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -608,4 +608,15 @@ export const issueTests: {
logger.discardDebugMessages();
logger.expectNoOtherMessages();
},

gh1996(project) {
const a = query(project, "a");
equal(a.signatures![0].sources?.[0].fileName, "gh1996.ts");
equal(a.signatures![0].sources?.[0].line, 1);
equal(a.signatures![0].sources?.[0].character, 17);
const b = query(project, "b");
equal(b.signatures![0].sources?.[0].fileName, "gh1996.ts");
equal(b.signatures![0].sources?.[0].line, 3);
equal(b.signatures![0].sources?.[0].character, 0);
},
};
2 changes: 1 addition & 1 deletion static/style.css
Expand Up @@ -942,7 +942,7 @@ a.tsd-index-link {
margin: 2rem 0;
}
.tsd-panel-group.tsd-index-group details {
margin: 4rem 0;
margin: 2rem 0;
}

#tsd-search {
Expand Down

0 comments on commit ec9efa0

Please sign in to comment.