@@ -900,7 +900,7 @@ module ts {
900900 getReferencesAtPosition ( fileName : string , position : number ) : ReferenceEntry [ ] ;
901901 getOccurrencesAtPosition ( fileName : string , position : number ) : ReferenceEntry [ ] ;
902902
903- getNavigateToItems ( searchValue : string ) : NavigateToItem [ ] ;
903+ getNavigateToItems ( searchValue : string , maxResultCount ?: number ) : NavigateToItem [ ] ;
904904 getNavigationBarItems ( fileName : string ) : NavigationBarItem [ ] ;
905905
906906 getOutliningSpans ( fileName : string ) : OutliningSpan [ ] ;
@@ -1380,8 +1380,8 @@ module ts {
13801380 enum MatchKind {
13811381 none = 0 ,
13821382 exact = 1 ,
1383- substring = 2 ,
1384- prefix = 3
1383+ prefix = 2 ,
1384+ substring = 3 ,
13851385 }
13861386
13871387 /// Language Service
@@ -4662,7 +4662,7 @@ module ts {
46624662 }
46634663
46644664 /// NavigateTo
4665- function getNavigateToItems ( searchValue : string ) : NavigateToItem [ ] {
4665+ function getNavigateToItems ( searchValue : string , maxResultCount ?: number ) : NavigateToItem [ ] {
46664666 synchronizeHostData ( ) ;
46674667
46684668 // Split search value in terms array
@@ -4671,7 +4671,7 @@ module ts {
46714671 // default NavigateTo approach: if search term contains only lower-case chars - use case-insensitive search, otherwise switch to case-sensitive version
46724672 var searchTerms = map ( terms , t => ( { caseSensitive : hasAnyUpperCaseCharacter ( t ) , term : t } ) ) ;
46734673
4674- var items : NavigateToItem [ ] = [ ] ;
4674+ var rawItems : { name : string ; fileName : string ; matchKind : MatchKind ; declaration : Declaration } [ ] = [ ] ;
46754675
46764676 // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
46774677 forEach ( program . getSourceFiles ( ) , sourceFile => {
@@ -4685,22 +4685,32 @@ module ts {
46854685 var name = ( < Identifier > declaration . name ) . text ;
46864686 var matchKind = getMatchKind ( searchTerms , name ) ;
46874687 if ( matchKind !== MatchKind . none ) {
4688- var container = < Declaration > getContainerNode ( declaration ) ;
4689- items . push ( {
4690- name : name ,
4691- kind : getNodeKind ( declaration ) ,
4692- kindModifiers : getNodeModifiers ( declaration ) ,
4693- matchKind : MatchKind [ matchKind ] ,
4694- fileName : fileName ,
4695- textSpan : createTextSpanFromBounds ( declaration . getStart ( ) , declaration . getEnd ( ) ) ,
4696- // TODO(jfreeman): What should be the containerName when the container has a computed name?
4697- containerName : container && container . name ? ( < Identifier > container . name ) . text : "" ,
4698- containerKind : container && container . name ? getNodeKind ( container ) : ""
4699- } ) ;
4688+ rawItems . push ( { name, fileName, matchKind, declaration } ) ;
47004689 }
47014690 }
47024691 } ) ;
47034692
4693+ rawItems . sort ( ( i1 , i2 ) => i1 . matchKind - i2 . matchKind ) ;
4694+ if ( maxResultCount !== undefined ) {
4695+ rawItems = rawItems . slice ( 0 , maxResultCount ) ;
4696+ }
4697+
4698+ var items = map ( rawItems , i => {
4699+ var declaration = i . declaration ;
4700+ var container = < Declaration > getContainerNode ( declaration ) ;
4701+ return < NavigateToItem > {
4702+ name : i . name ,
4703+ kind : getNodeKind ( declaration ) ,
4704+ kindModifiers : getNodeModifiers ( declaration ) ,
4705+ matchKind : MatchKind [ i . matchKind ] ,
4706+ fileName : i . fileName ,
4707+ textSpan : createTextSpanFromBounds ( declaration . getStart ( ) , declaration . getEnd ( ) ) ,
4708+ // TODO(jfreeman): What should be the containerName when the container has a computed name?
4709+ containerName : container && container . name ? ( < Identifier > container . name ) . text : "" ,
4710+ containerKind : container && container . name ? getNodeKind ( container ) : ""
4711+ } ;
4712+ } ) ;
4713+
47044714 return items ;
47054715
47064716 function hasAnyUpperCaseCharacter ( s : string ) : boolean {
0 commit comments