@@ -133,7 +133,9 @@ export class AstReferenceResolver {
133133 private _selectDeclaration ( astDeclarations : ReadonlyArray < AstDeclaration > ,
134134 memberReference : tsdoc . DocMemberReference , astSymbolName : string ) : AstDeclaration | ResolverFailure {
135135
136- if ( memberReference . selector === undefined ) {
136+ const memberSelector : tsdoc . DocMemberSelector | undefined = memberReference . selector ;
137+
138+ if ( memberSelector === undefined ) {
137139 if ( astDeclarations . length === 1 ) {
138140 return astDeclarations [ 0 ] ;
139141 } else {
@@ -149,12 +151,21 @@ export class AstReferenceResolver {
149151 }
150152 }
151153
152- const selectorName : string = memberReference . selector . selector ;
153-
154- if ( memberReference . selector . selectorKind !== tsdoc . SelectorKind . System ) {
155- return new ResolverFailure ( `The selector "${ selectorName } " is not a supported selector type` ) ;
154+ switch ( memberSelector . selectorKind ) {
155+ case tsdoc . SelectorKind . System :
156+ return this . _selectUsingSystemSelector ( astDeclarations , memberSelector , astSymbolName ) ;
157+ case tsdoc . SelectorKind . Index :
158+ return this . _selectUsingIndexSelector ( astDeclarations , memberSelector , astSymbolName ) ;
156159 }
157160
161+ return new ResolverFailure ( `The selector "${ memberSelector . selector } " is not a supported selector type` ) ;
162+ }
163+
164+ private _selectUsingSystemSelector ( astDeclarations : ReadonlyArray < AstDeclaration > ,
165+ memberSelector : tsdoc . DocMemberSelector , astSymbolName : string ) : AstDeclaration | ResolverFailure {
166+
167+ const selectorName : string = memberSelector . selector ;
168+
158169 let selectorSyntaxKind : ts . SyntaxKind ;
159170
160171 switch ( selectorName ) {
@@ -202,6 +213,37 @@ export class AstReferenceResolver {
202213 return matches [ 0 ] ;
203214 }
204215
216+ private _selectUsingIndexSelector ( astDeclarations : ReadonlyArray < AstDeclaration > ,
217+ memberSelector : tsdoc . DocMemberSelector , astSymbolName : string ) : AstDeclaration | ResolverFailure {
218+
219+ const selectorOverloadIndex : number = parseInt ( memberSelector . selector ) ;
220+
221+ const matches : AstDeclaration [ ] = [ ] ;
222+ for ( const astDeclaration of astDeclarations ) {
223+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
224+ if ( overloadIndex === selectorOverloadIndex ) {
225+ matches . push ( astDeclaration ) ;
226+ }
227+ }
228+
229+ if ( matches . length === 0 ) {
230+ return new ResolverFailure ( `An overload for "${ astSymbolName } " was not found that matches the`
231+ + ` TSDoc selector ":${ selectorOverloadIndex } "` ) ;
232+ }
233+ if ( matches . length > 1 ) {
234+ // If we found multiple matches, but the extra ones are all ancillary declarations,
235+ // then return the main declaration.
236+ const nonAncillaryMatch : AstDeclaration | undefined = this . _tryDisambiguateAncillaryMatches ( matches ) ;
237+ if ( nonAncillaryMatch ) {
238+ return nonAncillaryMatch ;
239+ }
240+
241+ return new ResolverFailure ( `More than one declaration for "${ astSymbolName } " matches the`
242+ + ` TSDoc selector ":${ selectorOverloadIndex } "` ) ;
243+ }
244+ return matches [ 0 ] ;
245+ }
246+
205247 /**
206248 * This resolves an ambiguous match in the case where the extra matches are all ancillary declarations,
207249 * except for one match that is the main declaration.
0 commit comments