Skip to content

Commit

Permalink
externalSymbolLinkMappings now handles symbol IDs
Browse files Browse the repository at this point in the history
Resolves #2725
  • Loading branch information
Gerrit0 committed Oct 4, 2024
1 parent 59ec968 commit 1cefc01
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- `externalSymbolLinkMappings` now uses the TypeScript reported link target if available, #2725.

## v0.26.8 (2024-10-04)

### Features
Expand Down
20 changes: 18 additions & 2 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,21 @@ export class Converter extends ChildableComponent<
constructor(owner: Application) {
super(owner);

this.addUnknownSymbolResolver((ref) => {
const userConfiguredSymbolResolver: ExternalSymbolResolver = (
ref,
refl,
_part,
symbolId,
) => {
if (symbolId) {
return userConfiguredSymbolResolver(
symbolId.toDeclarationReference(),
refl,
undefined,
undefined,
);
}

// Require global links, matching local ones will likely hide mistakes where the
// user meant to link to a local type.
if (ref.resolutionStart !== "global" || !ref.symbolReference) {
Expand All @@ -256,7 +270,9 @@ export class Converter extends ChildableComponent<
if (typeof modLinks["*"] === "string") {
return modLinks["*"];
}
});
};

this.addUnknownSymbolResolver(userConfiguredSymbolResolver);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter2/issues/gh2725.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Node } from "typescript";

/**
* {@link Node}
*/
export const node = true;
12 changes: 12 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1786,4 +1786,16 @@ describe("Issue Tests", () => {
equal(query(project, "big").defaultValue, "123n");
equal(query(project, "neg").defaultValue, "-123n");
});

it("#2725 respects symbol IDs when resolving links with user configured resolver", () => {
app.options.setValue("externalSymbolLinkMappings", {
typescript: {
"ts.Node": "https://typescriptlang.org",
},
});
const project = convert();
equal(getLinks(query(project, "node")), [
{ display: "Node", target: "https://typescriptlang.org" },
]);
});
});

0 comments on commit 1cefc01

Please sign in to comment.