Skip to content

Commit 1cefc01

Browse files
committed
externalSymbolLinkMappings now handles symbol IDs
Resolves #2725
1 parent 59ec968 commit 1cefc01

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Bug Fixes
4+
5+
- `externalSymbolLinkMappings` now uses the TypeScript reported link target if available, #2725.
6+
37
## v0.26.8 (2024-10-04)
48

59
### Features

src/lib/converter/converter.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,21 @@ export class Converter extends ChildableComponent<
229229
constructor(owner: Application) {
230230
super(owner);
231231

232-
this.addUnknownSymbolResolver((ref) => {
232+
const userConfiguredSymbolResolver: ExternalSymbolResolver = (
233+
ref,
234+
refl,
235+
_part,
236+
symbolId,
237+
) => {
238+
if (symbolId) {
239+
return userConfiguredSymbolResolver(
240+
symbolId.toDeclarationReference(),
241+
refl,
242+
undefined,
243+
undefined,
244+
);
245+
}
246+
233247
// Require global links, matching local ones will likely hide mistakes where the
234248
// user meant to link to a local type.
235249
if (ref.resolutionStart !== "global" || !ref.symbolReference) {
@@ -256,7 +270,9 @@ export class Converter extends ChildableComponent<
256270
if (typeof modLinks["*"] === "string") {
257271
return modLinks["*"];
258272
}
259-
});
273+
};
274+
275+
this.addUnknownSymbolResolver(userConfiguredSymbolResolver);
260276
}
261277

262278
/**

src/test/converter2/issues/gh2725.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Node } from "typescript";
2+
3+
/**
4+
* {@link Node}
5+
*/
6+
export const node = true;

src/test/issues.c2.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,4 +1786,16 @@ describe("Issue Tests", () => {
17861786
equal(query(project, "big").defaultValue, "123n");
17871787
equal(query(project, "neg").defaultValue, "-123n");
17881788
});
1789+
1790+
it("#2725 respects symbol IDs when resolving links with user configured resolver", () => {
1791+
app.options.setValue("externalSymbolLinkMappings", {
1792+
typescript: {
1793+
"ts.Node": "https://typescriptlang.org",
1794+
},
1795+
});
1796+
const project = convert();
1797+
equal(getLinks(query(project, "node")), [
1798+
{ display: "Node", target: "https://typescriptlang.org" },
1799+
]);
1800+
});
17891801
});

0 commit comments

Comments
 (0)