@@ -846,21 +846,22 @@ namespace ts.server {
846
846
compareRenameLocation ,
847
847
( a , b ) => a . file === b . file && a . start . line === b . start . line && a . start . offset === b . start . offset
848
848
) ;
849
- const locs = fileSpans . reduce < protocol . SpanGroup [ ] > ( ( accum , cur ) => {
849
+
850
+ const locs : protocol . SpanGroup [ ] = [ ] ;
851
+ for ( const cur of fileSpans ) {
850
852
let curFileAccum : protocol . SpanGroup ;
851
- if ( accum . length > 0 ) {
852
- curFileAccum = accum [ accum . length - 1 ] ;
853
+ if ( locs . length > 0 ) {
854
+ curFileAccum = locs [ locs . length - 1 ] ;
853
855
if ( curFileAccum . file !== cur . file ) {
854
856
curFileAccum = undefined ;
855
857
}
856
858
}
857
859
if ( ! curFileAccum ) {
858
860
curFileAccum = { file : cur . file , locs : [ ] } ;
859
- accum . push ( curFileAccum ) ;
861
+ locs . push ( curFileAccum ) ;
860
862
}
861
863
curFileAccum . locs . push ( { start : cur . start , end : cur . end } ) ;
862
- return accum ;
863
- } , [ ] ) ;
864
+ }
864
865
865
866
return { info : renameInfo , locs } ;
866
867
}
@@ -1183,15 +1184,13 @@ namespace ts.server {
1183
1184
return undefined ;
1184
1185
}
1185
1186
if ( simplifiedResult ) {
1186
- return completions . entries . reduce ( ( result : protocol . CompletionEntry [ ] , entry : ts . CompletionEntry ) => {
1187
+ return mapDefined ( completions . entries , entry => {
1187
1188
if ( completions . isMemberCompletion || ( entry . name . toLowerCase ( ) . indexOf ( prefix . toLowerCase ( ) ) === 0 ) ) {
1188
1189
const { name, kind, kindModifiers, sortText, replacementSpan } = entry ;
1189
- const convertedSpan : protocol . TextSpan =
1190
- replacementSpan ? this . decorateSpan ( replacementSpan , scriptInfo ) : undefined ;
1191
- result . push ( { name, kind, kindModifiers, sortText, replacementSpan : convertedSpan } ) ;
1190
+ const convertedSpan = replacementSpan ? this . decorateSpan ( replacementSpan , scriptInfo ) : undefined ;
1191
+ return { name, kind, kindModifiers, sortText, replacementSpan : convertedSpan } ;
1192
1192
}
1193
- return result ;
1194
- } , [ ] ) . sort ( ( a , b ) => ts . compareStrings ( a . name , b . name ) ) ;
1193
+ } ) . sort ( ( a , b ) => ts . compareStrings ( a . name , b . name ) ) ;
1195
1194
}
1196
1195
else {
1197
1196
return completions ;
@@ -1203,13 +1202,8 @@ namespace ts.server {
1203
1202
const scriptInfo = project . getScriptInfoForNormalizedPath ( file ) ;
1204
1203
const position = this . getPosition ( args , scriptInfo ) ;
1205
1204
1206
- return args . entryNames . reduce ( ( accum : protocol . CompletionEntryDetails [ ] , entryName : string ) => {
1207
- const details = project . getLanguageService ( ) . getCompletionEntryDetails ( file , position , entryName ) ;
1208
- if ( details ) {
1209
- accum . push ( details ) ;
1210
- }
1211
- return accum ;
1212
- } , [ ] ) ;
1205
+ return mapDefined ( args . entryNames , entryName =>
1206
+ project . getLanguageService ( ) . getCompletionEntryDetails ( file , position , entryName ) ) ;
1213
1207
}
1214
1208
1215
1209
private getCompileOnSaveAffectedFileList ( args : protocol . FileRequestArgs ) : protocol . CompileOnSaveAffectedFileListSingleProject [ ] {
@@ -1274,14 +1268,11 @@ namespace ts.server {
1274
1268
}
1275
1269
1276
1270
private getDiagnostics ( next : NextStep , delay : number , fileNames : string [ ] ) : void {
1277
- const checkList = fileNames . reduce ( ( accum : PendingErrorCheck [ ] , uncheckedFileName : string ) => {
1271
+ const checkList = mapDefined ( fileNames , uncheckedFileName => {
1278
1272
const fileName = toNormalizedPath ( uncheckedFileName ) ;
1279
1273
const project = this . projectService . getDefaultProjectForFile ( fileName , /*refreshInferredProjects*/ true ) ;
1280
- if ( project ) {
1281
- accum . push ( { fileName, project } ) ;
1282
- }
1283
- return accum ;
1284
- } , [ ] ) ;
1274
+ return project && { fileName, project } ;
1275
+ } ) ;
1285
1276
1286
1277
if ( checkList . length > 0 ) {
1287
1278
this . updateErrorCheck ( next , checkList , this . changeSeq , ( n ) => n === this . changeSeq , delay ) ;
0 commit comments