@@ -167,7 +167,7 @@ namespace ts.server {
167
167
/**
168
168
* Set of files that was returned from the last call to getChangesSinceVersion.
169
169
*/
170
- private lastReportedFileNames : Map < true > | undefined ;
170
+ private lastReportedFileNames : Map < boolean > | undefined ;
171
171
/**
172
172
* Last version that was reported.
173
173
*/
@@ -803,6 +803,14 @@ namespace ts.server {
803
803
return result ;
804
804
}
805
805
806
+ /* @internal */
807
+ getFileNamesWithRedirectInfo ( includeProjectReferenceRedirectInfo : boolean ) {
808
+ return this . getFileNames ( ) . map ( ( fileName ) : protocol . FileWithProjectReferenceRedirectInfo => ( {
809
+ fileName,
810
+ isSourceOfProjectReferenceRedirect : includeProjectReferenceRedirectInfo && this . isSourceOfProjectReferenceRedirect ( fileName )
811
+ } ) ) ;
812
+ }
813
+
806
814
hasConfigFile ( configFilePath : NormalizedPath ) {
807
815
if ( this . program && this . languageServiceEnabled ) {
808
816
const configFile = this . program . getCompilerOptions ( ) . configFile ;
@@ -1300,7 +1308,15 @@ namespace ts.server {
1300
1308
}
1301
1309
1302
1310
/* @internal */
1303
- getChangesSinceVersion ( lastKnownVersion ?: number ) : ProjectFilesWithTSDiagnostics {
1311
+ getChangesSinceVersion ( lastKnownVersion ?: number , includeProjectReferenceRedirectInfo ?: boolean ) : ProjectFilesWithTSDiagnostics {
1312
+ const includeProjectReferenceRedirectInfoIfRequested =
1313
+ includeProjectReferenceRedirectInfo
1314
+ ? ( files : Map < boolean > ) => arrayFrom ( files . entries ( ) , ( [ fileName , isSourceOfProjectReferenceRedirect ] ) : protocol . FileWithProjectReferenceRedirectInfo => ( {
1315
+ fileName,
1316
+ isSourceOfProjectReferenceRedirect
1317
+ } ) )
1318
+ : ( files : Map < boolean > ) => arrayFrom ( files . keys ( ) ) ;
1319
+
1304
1320
// Update the graph only if initial configured project load is not pending
1305
1321
if ( ! this . isInitialLoadPending ( ) ) {
1306
1322
updateProjectIfDirty ( this ) ;
@@ -1324,35 +1340,75 @@ namespace ts.server {
1324
1340
}
1325
1341
// compute and return the difference
1326
1342
const lastReportedFileNames = this . lastReportedFileNames ;
1327
- const externalFiles = this . getExternalFiles ( ) . map ( f => toNormalizedPath ( f ) ) ;
1328
- const currentFiles = arrayToSet ( this . getFileNames ( ) . concat ( externalFiles ) ) ;
1343
+ const externalFiles = this . getExternalFiles ( ) . map ( ( f ) : protocol . FileWithProjectReferenceRedirectInfo => ( {
1344
+ fileName : toNormalizedPath ( f ) ,
1345
+ isSourceOfProjectReferenceRedirect : false
1346
+ } ) ) ;
1347
+ const currentFiles = arrayToMap (
1348
+ this . getFileNamesWithRedirectInfo ( ! ! includeProjectReferenceRedirectInfo ) . concat ( externalFiles ) ,
1349
+ info => info . fileName ,
1350
+ info => info . isSourceOfProjectReferenceRedirect
1351
+ ) ;
1352
+
1353
+ const added : Map < boolean > = new Map < boolean > ( ) ;
1354
+ const removed : Map < boolean > = new Map < boolean > ( ) ;
1329
1355
1330
- const added : string [ ] = [ ] ;
1331
- const removed : string [ ] = [ ] ;
1332
1356
const updated : string [ ] = updatedFileNames ? arrayFrom ( updatedFileNames . keys ( ) ) : [ ] ;
1357
+ const updatedRedirects : protocol . FileWithProjectReferenceRedirectInfo [ ] = [ ] ;
1333
1358
1334
- forEachKey ( currentFiles , id => {
1335
- if ( ! lastReportedFileNames . has ( id ) ) {
1336
- added . push ( id ) ;
1359
+ forEachEntry ( currentFiles , ( isSourceOfProjectReferenceRedirect , fileName ) => {
1360
+ if ( ! lastReportedFileNames . has ( fileName ) ) {
1361
+ added . set ( fileName , isSourceOfProjectReferenceRedirect ) ;
1362
+ }
1363
+ else if ( includeProjectReferenceRedirectInfo && isSourceOfProjectReferenceRedirect !== lastReportedFileNames . get ( fileName ) ) {
1364
+ updatedRedirects . push ( {
1365
+ fileName,
1366
+ isSourceOfProjectReferenceRedirect
1367
+ } ) ;
1337
1368
}
1338
1369
} ) ;
1339
- forEachKey ( lastReportedFileNames , id => {
1340
- if ( ! currentFiles . has ( id ) ) {
1341
- removed . push ( id ) ;
1370
+ forEachEntry ( lastReportedFileNames , ( isSourceOfProjectReferenceRedirect , fileName ) => {
1371
+ if ( ! currentFiles . has ( fileName ) ) {
1372
+ removed . set ( fileName , isSourceOfProjectReferenceRedirect ) ;
1342
1373
}
1343
1374
} ) ;
1344
1375
this . lastReportedFileNames = currentFiles ;
1345
1376
this . lastReportedVersion = this . projectProgramVersion ;
1346
- return { info, changes : { added, removed, updated } , projectErrors : this . getGlobalProjectErrors ( ) } ;
1377
+ return {
1378
+ info,
1379
+ changes : {
1380
+ added : includeProjectReferenceRedirectInfoIfRequested ( added ) ,
1381
+ removed : includeProjectReferenceRedirectInfoIfRequested ( removed ) ,
1382
+ updated : includeProjectReferenceRedirectInfoIfRequested
1383
+ ? updated . map ( ( fileName ) : protocol . FileWithProjectReferenceRedirectInfo => ( {
1384
+ fileName,
1385
+ isSourceOfProjectReferenceRedirect : this . isSourceOfProjectReferenceRedirect ( fileName )
1386
+ } ) )
1387
+ : updated ,
1388
+ updatedRedirects : includeProjectReferenceRedirectInfo ? updatedRedirects : undefined
1389
+ } ,
1390
+ projectErrors : this . getGlobalProjectErrors ( )
1391
+ } ;
1347
1392
}
1348
1393
else {
1349
1394
// unknown version - return everything
1350
- const projectFileNames = this . getFileNames ( ) ;
1351
- const externalFiles = this . getExternalFiles ( ) . map ( f => toNormalizedPath ( f ) ) ;
1395
+ const projectFileNames = this . getFileNamesWithRedirectInfo ( ! ! includeProjectReferenceRedirectInfo ) ;
1396
+ const externalFiles = this . getExternalFiles ( ) . map ( ( f ) : protocol . FileWithProjectReferenceRedirectInfo => ( {
1397
+ fileName : toNormalizedPath ( f ) ,
1398
+ isSourceOfProjectReferenceRedirect : false
1399
+ } ) ) ;
1352
1400
const allFiles = projectFileNames . concat ( externalFiles ) ;
1353
- this . lastReportedFileNames = arrayToSet ( allFiles ) ;
1401
+ this . lastReportedFileNames = arrayToMap (
1402
+ allFiles ,
1403
+ info => info . fileName ,
1404
+ info => info . isSourceOfProjectReferenceRedirect
1405
+ ) ;
1354
1406
this . lastReportedVersion = this . projectProgramVersion ;
1355
- return { info, files : allFiles , projectErrors : this . getGlobalProjectErrors ( ) } ;
1407
+ return {
1408
+ info,
1409
+ files : includeProjectReferenceRedirectInfo ? allFiles : allFiles . map ( f => f . fileName ) ,
1410
+ projectErrors : this . getGlobalProjectErrors ( )
1411
+ } ;
1356
1412
}
1357
1413
}
1358
1414
0 commit comments