@@ -284,34 +284,43 @@ namespace ts.server {
284284 return deduplicate ( outputs , equateValues ) ;
285285 }
286286
287- function combineProjectOutputFromEveryProject < T > ( projectService : ProjectService , action : ( project : Project ) => readonly T [ ] , areEqual : ( a : T , b : T ) => boolean ) {
288- const outputs : T [ ] = [ ] ;
287+ type CombineOutputResult < T > = { project : Project ; result : readonly T [ ] ; } [ ] ;
288+ function combineOutputResultContains < T > ( outputs : CombineOutputResult < T > , output : T , areEqual : ( a : T , b : T ) => boolean ) {
289+ return outputs . some ( ( { result } ) => contains ( result , output , areEqual ) ) ;
290+ }
291+ function addToCombineOutputResult < T > ( outputs : CombineOutputResult < T > , project : Project , result : readonly T [ ] ) {
292+ if ( result . length ) outputs . push ( { project, result } ) ;
293+ }
294+
295+ function combineProjectOutputFromEveryProject < T > ( projectService : ProjectService , action : ( project : Project ) => readonly T [ ] , areEqual : ( a : T , b : T ) => boolean ) : CombineOutputResult < T > {
296+ const outputs : CombineOutputResult < T > = [ ] ;
289297 projectService . loadAncestorProjectTree ( ) ;
290298 projectService . forEachEnabledProject ( project => {
291299 const theseOutputs = action ( project ) ;
292- outputs . push ( ... theseOutputs . filter ( output => ! outputs . some ( o => areEqual ( o , output ) ) ) ) ;
300+ addToCombineOutputResult ( outputs , project , filter ( theseOutputs , output => ! combineOutputResultContains ( outputs , output , areEqual ) ) ) ;
293301 } ) ;
294302 return outputs ;
295303 }
296304
305+ function flattenCombineOutputResult < T > ( outputs : CombineOutputResult < T > ) : readonly T [ ] {
306+ return flatMap ( outputs , ( { result } ) => result ) ;
307+ }
308+
297309 function combineProjectOutputWhileOpeningReferencedProjects < T > (
298310 projects : Projects ,
299311 defaultProject : Project ,
300312 action : ( project : Project ) => readonly T [ ] ,
301313 getLocation : ( t : T ) => DocumentPosition ,
302314 resultsEqual : ( a : T , b : T ) => boolean ,
303- ) : T [ ] {
304- const outputs : T [ ] = [ ] ;
315+ ) : CombineOutputResult < T > {
316+ const outputs : CombineOutputResult < T > = [ ] ;
305317 combineProjectOutputWorker (
306318 projects ,
307319 defaultProject ,
308320 /*initialLocation*/ undefined ,
309321 ( project , _ , tryAddToTodo ) => {
310- for ( const output of action ( project ) ) {
311- if ( ! contains ( outputs , output , resultsEqual ) && ! tryAddToTodo ( project , getLocation ( output ) ) ) {
312- outputs . push ( output ) ;
313- }
314- }
322+ const theseOutputs = action ( project ) ;
323+ addToCombineOutputResult ( outputs , project , filter ( theseOutputs , output => ! combineOutputResultContains ( outputs , output , resultsEqual ) && ! tryAddToTodo ( project , getLocation ( output ) ) ) ) ;
315324 } ,
316325 ) ;
317326 return outputs ;
@@ -326,7 +335,6 @@ namespace ts.server {
326335 hostPreferences : UserPreferences
327336 ) : readonly RenameLocation [ ] {
328337 const outputs : RenameLocation [ ] = [ ] ;
329-
330338 combineProjectOutputWorker (
331339 projects ,
332340 defaultProject ,
@@ -1930,38 +1938,42 @@ namespace ts.server {
19301938
19311939 private getNavigateToItems ( args : protocol . NavtoRequestArgs , simplifiedResult : boolean ) : readonly protocol . NavtoItem [ ] | readonly NavigateToItem [ ] {
19321940 const full = this . getFullNavigateToItems ( args ) ;
1933- return ! simplifiedResult ? full : full . map ( ( navItem ) => {
1934- const { file, project } = this . getFileAndProject ( { file : navItem . fileName } ) ;
1935- const scriptInfo = project . getScriptInfo ( file ) ! ;
1936- const bakedItem : protocol . NavtoItem = {
1937- name : navItem . name ,
1938- kind : navItem . kind ,
1939- kindModifiers : navItem . kindModifiers ,
1940- isCaseSensitive : navItem . isCaseSensitive ,
1941- matchKind : navItem . matchKind ,
1942- file : navItem . fileName ,
1943- start : scriptInfo . positionToLineOffset ( navItem . textSpan . start ) ,
1944- end : scriptInfo . positionToLineOffset ( textSpanEnd ( navItem . textSpan ) )
1945- } ;
1946- if ( navItem . kindModifiers && ( navItem . kindModifiers !== "" ) ) {
1947- bakedItem . kindModifiers = navItem . kindModifiers ;
1948- }
1949- if ( navItem . containerName && ( navItem . containerName . length > 0 ) ) {
1950- bakedItem . containerName = navItem . containerName ;
1951- }
1952- if ( navItem . containerKind && ( navItem . containerKind . length > 0 ) ) {
1953- bakedItem . containerKind = navItem . containerKind ;
1954- }
1955- return bakedItem ;
1956- } ) ;
1941+ return ! simplifiedResult ?
1942+ flattenCombineOutputResult ( full ) :
1943+ flatMap (
1944+ full ,
1945+ ( { project, result } ) => result . map ( navItem => {
1946+ const scriptInfo = project . getScriptInfo ( navItem . fileName ) ! ;
1947+ const bakedItem : protocol . NavtoItem = {
1948+ name : navItem . name ,
1949+ kind : navItem . kind ,
1950+ kindModifiers : navItem . kindModifiers ,
1951+ isCaseSensitive : navItem . isCaseSensitive ,
1952+ matchKind : navItem . matchKind ,
1953+ file : navItem . fileName ,
1954+ start : scriptInfo . positionToLineOffset ( navItem . textSpan . start ) ,
1955+ end : scriptInfo . positionToLineOffset ( textSpanEnd ( navItem . textSpan ) )
1956+ } ;
1957+ if ( navItem . kindModifiers && ( navItem . kindModifiers !== "" ) ) {
1958+ bakedItem . kindModifiers = navItem . kindModifiers ;
1959+ }
1960+ if ( navItem . containerName && ( navItem . containerName . length > 0 ) ) {
1961+ bakedItem . containerName = navItem . containerName ;
1962+ }
1963+ if ( navItem . containerKind && ( navItem . containerKind . length > 0 ) ) {
1964+ bakedItem . containerKind = navItem . containerKind ;
1965+ }
1966+ return bakedItem ;
1967+ } )
1968+ ) ;
19571969 }
19581970
1959- private getFullNavigateToItems ( args : protocol . NavtoRequestArgs ) : readonly NavigateToItem [ ] {
1971+ private getFullNavigateToItems ( args : protocol . NavtoRequestArgs ) : CombineOutputResult < NavigateToItem > {
19601972 const { currentFileOnly, searchValue, maxResultCount, projectFileName } = args ;
19611973 if ( currentFileOnly ) {
19621974 Debug . assertDefined ( args . file ) ;
19631975 const { file, project } = this . getFileAndProject ( args as protocol . FileRequestArgs ) ;
1964- return project . getLanguageService ( ) . getNavigateToItems ( searchValue , maxResultCount , file ) ;
1976+ return [ { project, result : project . getLanguageService ( ) . getNavigateToItems ( searchValue , maxResultCount , file ) } ] ;
19651977 }
19661978 else if ( ! args . file && ! projectFileName ) {
19671979 return combineProjectOutputFromEveryProject (
@@ -2082,10 +2094,13 @@ namespace ts.server {
20822094 const newPath = toNormalizedPath ( args . newFilePath ) ;
20832095 const formatOptions = this . getHostFormatOptions ( ) ;
20842096 const preferences = this . getHostPreferences ( ) ;
2085- const changes = combineProjectOutputFromEveryProject (
2086- this . projectService ,
2087- project => project . getLanguageService ( ) . getEditsForFileRename ( oldPath , newPath , formatOptions , preferences ) ,
2088- ( a , b ) => a . fileName === b . fileName ) ;
2097+ const changes = flattenCombineOutputResult (
2098+ combineProjectOutputFromEveryProject (
2099+ this . projectService ,
2100+ project => project . getLanguageService ( ) . getEditsForFileRename ( oldPath , newPath , formatOptions , preferences ) ,
2101+ ( a , b ) => a . fileName === b . fileName
2102+ )
2103+ ) ;
20892104 return simplifiedResult ? changes . map ( c => this . mapTextChangeToCodeEdit ( c ) ) : changes ;
20902105 }
20912106
0 commit comments