@@ -1264,21 +1264,43 @@ module ts {
1264
1264
} ;
1265
1265
}
1266
1266
1267
+ function sourceFileUpToDate ( sourceFile : SourceFile ) : boolean {
1268
+ return sourceFile && sourceFile . version === hostCache . getVersion ( sourceFile . filename ) && sourceFile . isOpen === hostCache . isOpen ( sourceFile . filename ) ;
1269
+ }
1270
+
1271
+ function programUpToDate ( ) : boolean {
1272
+ // If we haven't create a program yet, then it is not up-to-date
1273
+ if ( ! program ) return false ;
1274
+
1275
+ // If number of files in the program do not match, it is not up-to-date
1276
+ var hostFilenames = hostCache . getFilenames ( ) ;
1277
+ if ( program . getSourceFiles ( ) . length !== hostFilenames . length ) return false ;
1278
+
1279
+ // If any file is not up-to-date, then the whole program is not up-to-date
1280
+ for ( var i = 0 , n = hostFilenames . length ; i < n ; i ++ ) {
1281
+ if ( ! sourceFileUpToDate ( program . getSourceFile ( hostFilenames [ i ] ) ) )
1282
+ return false ;
1283
+ }
1284
+
1285
+ // If the compilation settings do no match, then the program is not up-to-date
1286
+ return compareDataObjects ( program . getCompilerOptions ( ) , hostCache . compilationSettings ( ) ) ;
1287
+ }
1288
+
1267
1289
function synchronizeHostData ( ) : void {
1268
1290
// Reset the cache at start of every refresh
1269
1291
hostCache = new HostCache ( host ) ;
1270
1292
1293
+ // If the program is already up-to-date, we can reuse it
1294
+ if ( programUpToDate ( ) ) {
1295
+ return ;
1296
+ }
1297
+
1271
1298
var compilationSettings = hostCache . compilationSettings ( ) ;
1272
1299
1273
- // TODO: check if we need to create a new compiler to start with
1274
- // 1. files are identical
1275
- // 2. compilation settings are identical
1276
-
1277
1300
// Now, remove any files from the compiler that are no longer in the host.
1278
1301
var oldProgram = program ;
1279
1302
if ( oldProgram ) {
1280
1303
var oldSettings = program . getCompilerOptions ( ) ;
1281
-
1282
1304
// If the language version changed, then that affects what types of things we parse. So
1283
1305
// we have to dump all syntax trees.
1284
1306
// TODO: handle propagateEnumConstants
@@ -1303,7 +1325,6 @@ module ts {
1303
1325
// doesn't know about it.). Or notify the compiler about any changes (if it does
1304
1326
// know about it.)
1305
1327
var hostfilenames = hostCache . getFilenames ( ) ;
1306
-
1307
1328
for ( var i = 0 , n = hostfilenames . length ; i < n ; i ++ ) {
1308
1329
var filename = hostfilenames [ i ] ;
1309
1330
@@ -1316,7 +1337,7 @@ module ts {
1316
1337
//
1317
1338
// If the sourceFile is the same, assume no update
1318
1339
//
1319
- if ( sourceFile . version === version && sourceFile . isOpen === isOpen ) {
1340
+ if ( sourceFileUpToDate ( sourceFile ) ) {
1320
1341
continue ;
1321
1342
}
1322
1343
0 commit comments