11/* @internal */
22namespace ts . NavigateTo {
33 interface RawNavigateToItem {
4- name : string ;
5- fileName : string ;
6- matchKind : PatternMatchKind ;
7- isCaseSensitive : boolean ;
8- declaration : Declaration ;
4+ readonly name : string ;
5+ readonly fileName : string ;
6+ readonly matchKind : PatternMatchKind ;
7+ readonly isCaseSensitive : boolean ;
8+ readonly declaration : Declaration ;
99 }
1010
1111 export function getNavigateToItems ( sourceFiles : ReadonlyArray < SourceFile > , checker : TypeChecker , cancellationToken : CancellationToken , searchValue : string , maxResultCount : number | undefined , excludeDtsFiles : boolean ) : NavigateToItem [ ] {
1212 const patternMatcher = createPatternMatcher ( searchValue ) ;
1313 if ( ! patternMatcher ) return emptyArray ;
14- let rawItems : RawNavigateToItem [ ] = [ ] ;
14+ const rawItems : RawNavigateToItem [ ] = [ ] ;
1515
1616 // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
1717 for ( const sourceFile of sourceFiles ) {
@@ -27,10 +27,7 @@ namespace ts.NavigateTo {
2727 }
2828
2929 rawItems . sort ( compareNavigateToItems ) ;
30- if ( maxResultCount !== undefined ) {
31- rawItems = rawItems . slice ( 0 , maxResultCount ) ;
32- }
33- return rawItems . map ( createNavigateToItem ) ;
30+ return ( maxResultCount === undefined ? rawItems : rawItems . slice ( 0 , maxResultCount ) ) . map ( createNavigateToItem ) ;
3431 }
3532
3633 function getItemsFromNamedDeclaration ( patternMatcher : PatternMatcher , name : string , declarations : ReadonlyArray < Declaration > , checker : TypeChecker , fileName : string , rawItems : Push < RawNavigateToItem > ) : void {
@@ -45,13 +42,13 @@ namespace ts.NavigateTo {
4542 if ( ! shouldKeepItem ( declaration , checker ) ) continue ;
4643
4744 if ( patternMatcher . patternContainsDots ) {
48- const fullMatch = patternMatcher . getFullMatch ( getContainers ( declaration ) ! , name ) ; // TODO: GH#18217
45+ // If the pattern has dots in it, then also see if the declaration container matches as well.
46+ const fullMatch = patternMatcher . getFullMatch ( getContainers ( declaration ) , name ) ;
4947 if ( fullMatch ) {
5048 rawItems . push ( { name, fileName, matchKind : fullMatch . kind , isCaseSensitive : fullMatch . isCaseSensitive , declaration } ) ;
5149 }
5250 }
5351 else {
54- // If the pattern has dots in it, then also see if the declaration container matches as well.
5552 rawItems . push ( { name, fileName, matchKind : match . kind , isCaseSensitive : match . isCaseSensitive , declaration } ) ;
5653 }
5754 }
@@ -62,7 +59,7 @@ namespace ts.NavigateTo {
6259 case SyntaxKind . ImportClause :
6360 case SyntaxKind . ImportSpecifier :
6461 case SyntaxKind . ImportEqualsDeclaration :
65- const importer = checker . getSymbolAtLocation ( ( declaration as ImportClause | ImportSpecifier | ImportEqualsDeclaration ) . name ! ) ! ;
62+ const importer = checker . getSymbolAtLocation ( ( declaration as ImportClause | ImportSpecifier | ImportEqualsDeclaration ) . name ! ) ! ; // TODO: GH#18217
6663 const imported = checker . getAliasedSymbol ( importer ) ;
6764 return importer . escapedName !== imported . escapedName ;
6865 default :
@@ -107,22 +104,22 @@ namespace ts.NavigateTo {
107104 return false ;
108105 }
109106
110- function getContainers ( declaration : Declaration ) : string [ ] | undefined {
107+ function getContainers ( declaration : Declaration ) : ReadonlyArray < string > {
111108 const containers : string [ ] = [ ] ;
112109
113110 // First, if we started with a computed property name, then add all but the last
114111 // portion into the container array.
115112 const name = getNameOfDeclaration ( declaration ) ;
116113 if ( name && name . kind === SyntaxKind . ComputedPropertyName && ! tryAddComputedPropertyName ( name . expression , containers , /*includeLastPortion*/ false ) ) {
117- return undefined ;
114+ return emptyArray ;
118115 }
119116
120117 // Now, walk up our containers, adding all their names to the container array.
121118 let container = getContainerNode ( declaration ) ;
122119
123120 while ( container ) {
124121 if ( ! tryAddSingleDeclarationName ( container , containers ) ) {
125- return undefined ;
122+ return emptyArray ;
126123 }
127124
128125 container = getContainerNode ( container ) ;
@@ -145,13 +142,13 @@ namespace ts.NavigateTo {
145142 name : rawItem . name ,
146143 kind : getNodeKind ( declaration ) ,
147144 kindModifiers : getNodeModifiers ( declaration ) ,
148- matchKind : PatternMatchKind [ rawItem . matchKind ] ,
145+ matchKind : PatternMatchKind [ rawItem . matchKind ] as keyof typeof PatternMatchKind ,
149146 isCaseSensitive : rawItem . isCaseSensitive ,
150147 fileName : rawItem . fileName ,
151148 textSpan : createTextSpanFromNode ( declaration ) ,
152149 // TODO(jfreeman): What should be the containerName when the container has a computed name?
153150 containerName : containerName ? ( < Identifier > containerName ) . text : "" ,
154- containerKind : containerName ? getNodeKind ( container ! ) : ScriptElementKind . unknown // TODO: GH#18217 Just use `container ? ...`
151+ containerKind : containerName ? getNodeKind ( container ! ) : ScriptElementKind . unknown , // TODO: GH#18217 Just use `container ? ...`
155152 } ;
156153 }
157154}
0 commit comments