@@ -284,34 +284,43 @@ namespace ts.server {
284
284
return deduplicate ( outputs , equateValues ) ;
285
285
}
286
286
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 > = [ ] ;
289
297
projectService . loadAncestorProjectTree ( ) ;
290
298
projectService . forEachEnabledProject ( project => {
291
299
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 ) ) ) ;
293
301
} ) ;
294
302
return outputs ;
295
303
}
296
304
305
+ function flattenCombineOutputResult < T > ( outputs : CombineOutputResult < T > ) : readonly T [ ] {
306
+ return flatMap ( outputs , ( { result } ) => result ) ;
307
+ }
308
+
297
309
function combineProjectOutputWhileOpeningReferencedProjects < T > (
298
310
projects : Projects ,
299
311
defaultProject : Project ,
300
312
action : ( project : Project ) => readonly T [ ] ,
301
313
getLocation : ( t : T ) => DocumentPosition ,
302
314
resultsEqual : ( a : T , b : T ) => boolean ,
303
- ) : T [ ] {
304
- const outputs : T [ ] = [ ] ;
315
+ ) : CombineOutputResult < T > {
316
+ const outputs : CombineOutputResult < T > = [ ] ;
305
317
combineProjectOutputWorker (
306
318
projects ,
307
319
defaultProject ,
308
320
/*initialLocation*/ undefined ,
309
321
( 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 ) ) ) ) ;
315
324
} ,
316
325
) ;
317
326
return outputs ;
@@ -326,7 +335,6 @@ namespace ts.server {
326
335
hostPreferences : UserPreferences
327
336
) : readonly RenameLocation [ ] {
328
337
const outputs : RenameLocation [ ] = [ ] ;
329
-
330
338
combineProjectOutputWorker (
331
339
projects ,
332
340
defaultProject ,
@@ -1930,38 +1938,42 @@ namespace ts.server {
1930
1938
1931
1939
private getNavigateToItems ( args : protocol . NavtoRequestArgs , simplifiedResult : boolean ) : readonly protocol . NavtoItem [ ] | readonly NavigateToItem [ ] {
1932
1940
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
+ ) ;
1957
1969
}
1958
1970
1959
- private getFullNavigateToItems ( args : protocol . NavtoRequestArgs ) : readonly NavigateToItem [ ] {
1971
+ private getFullNavigateToItems ( args : protocol . NavtoRequestArgs ) : CombineOutputResult < NavigateToItem > {
1960
1972
const { currentFileOnly, searchValue, maxResultCount, projectFileName } = args ;
1961
1973
if ( currentFileOnly ) {
1962
1974
Debug . assertDefined ( args . file ) ;
1963
1975
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 ) } ] ;
1965
1977
}
1966
1978
else if ( ! args . file && ! projectFileName ) {
1967
1979
return combineProjectOutputFromEveryProject (
@@ -2082,10 +2094,13 @@ namespace ts.server {
2082
2094
const newPath = toNormalizedPath ( args . newFilePath ) ;
2083
2095
const formatOptions = this . getHostFormatOptions ( ) ;
2084
2096
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
+ ) ;
2089
2104
return simplifiedResult ? changes . map ( c => this . mapTextChangeToCodeEdit ( c ) ) : changes ;
2090
2105
}
2091
2106
0 commit comments