@@ -28,6 +28,7 @@ import type {
2828import { parseComment } from "./comments/parser" ;
2929import { lexCommentString } from "./comments/rawLexer" ;
3030import { resolvePartLinks , resolveLinks } from "./comments/linkResolver" ;
31+ import type { DeclarationReference } from "./comments/declarationReference" ;
3132
3233/**
3334 * Compiles source files using TypeScript and converts compiler symbols to reflections.
@@ -41,29 +42,29 @@ export class Converter extends ChildableComponent<
4142 Application ,
4243 ConverterComponent
4344> {
44- /**
45- * The human readable name of the project. Used within the templates to set the title of the document.
46- */
47- @BindOption ( "name" )
48- name ! : string ;
49-
45+ /** @internal */
5046 @BindOption ( "externalPattern" )
5147 externalPattern ! : string [ ] ;
5248 private externalPatternCache ?: Minimatch [ ] ;
5349 private excludeCache ?: Minimatch [ ] ;
5450
51+ /** @internal */
5552 @BindOption ( "excludeExternals" )
5653 excludeExternals ! : boolean ;
5754
55+ /** @internal */
5856 @BindOption ( "excludeNotDocumented" )
5957 excludeNotDocumented ! : boolean ;
6058
59+ /** @internal */
6160 @BindOption ( "excludePrivate" )
6261 excludePrivate ! : boolean ;
6362
63+ /** @internal */
6464 @BindOption ( "excludeProtected" )
6565 excludeProtected ! : boolean ;
6666
67+ /** @internal */
6768 @BindOption ( "commentStyle" )
6869 commentStyle ! : CommentStyle ;
6970
@@ -72,6 +73,9 @@ export class Converter extends ChildableComponent<
7273 validation ! : ValidationOptions ;
7374
7475 private _config ?: CommentParserConfig ;
76+ private _externalSymbolResolvers : Array <
77+ ( ref : DeclarationReference ) => string | undefined
78+ > = [ ] ;
7579
7680 get config ( ) : CommentParserConfig {
7781 return this . _config || this . _buildCommentParserConfig ( ) ;
@@ -164,7 +168,9 @@ export class Converter extends ChildableComponent<
164168 const programs = entryPoints . map ( ( e ) => e . program ) ;
165169 this . externalPatternCache = void 0 ;
166170
167- const project = new ProjectReflection ( this . name ) ;
171+ const project = new ProjectReflection (
172+ this . application . options . getValue ( "name" )
173+ ) ;
168174 const context = new Context ( this , programs , project ) ;
169175
170176 this . trigger ( Converter . EVENT_BEGIN , context ) ;
@@ -211,6 +217,32 @@ export class Converter extends ChildableComponent<
211217 ) ;
212218 }
213219
220+ /**
221+ * Adds a new resolver that the theme can use to try to figure out how to link to a symbol declared
222+ * by a third-party library which is not included in the documentation.
223+ *
224+ * The resolver function will be passed a declaration reference which it can attempt to resolve. If
225+ * resolution fails, the function should return undefined.
226+ *
227+ * Note: This will be used for both references to types declared in node_modules (in which case the
228+ * reference passed will have the `moduleSource` set and the `symbolReference` will navigate via `.`)
229+ * and user defined \{\@link \} tags which cannot be resolved.
230+ * @since 0.22.14
231+ */
232+ addUnknownSymbolResolver (
233+ resolver : ( ref : DeclarationReference ) => string | undefined
234+ ) : void {
235+ this . _externalSymbolResolvers . push ( resolver ) ;
236+ }
237+
238+ /** @internal */
239+ resolveExternalLink ( ref : DeclarationReference ) : string | undefined {
240+ for ( const resolver of this . _externalSymbolResolvers ) {
241+ const resolved = resolver ( ref ) ;
242+ if ( resolved ) return resolved ;
243+ }
244+ }
245+
214246 resolveLinks ( comment : Comment , owner : Reflection ) : void ;
215247 resolveLinks (
216248 parts : readonly CommentDisplayPart [ ] ,
@@ -221,7 +253,13 @@ export class Converter extends ChildableComponent<
221253 owner : Reflection
222254 ) : CommentDisplayPart [ ] | undefined {
223255 if ( comment instanceof Comment ) {
224- resolveLinks ( comment , owner , this . validation , this . owner . logger ) ;
256+ resolveLinks (
257+ comment ,
258+ owner ,
259+ this . validation ,
260+ this . owner . logger ,
261+ ( ref ) => this . resolveExternalLink ( ref )
262+ ) ;
225263 } else {
226264 let warned = false ;
227265 const warn = ( ) => {
@@ -238,7 +276,8 @@ export class Converter extends ChildableComponent<
238276 comment ,
239277 warn ,
240278 this . validation ,
241- this . owner . logger
279+ this . owner . logger ,
280+ ( ref ) => this . resolveExternalLink ( ref )
242281 ) ;
243282 }
244283 }
0 commit comments