@@ -1264,21 +1264,48 @@ 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 ) {
1274
+ return false ;
1275
+ }
1276
+
1277
+ // If number of files in the program do not match, it is not up-to-date
1278
+ var hostFilenames = hostCache . getFilenames ( ) ;
1279
+ if ( program . getSourceFiles ( ) . length !== hostFilenames . length ) {
1280
+ return false ;
1281
+ }
1282
+
1283
+ // If any file is not up-to-date, then the whole program is not up-to-date
1284
+ for ( var i = 0 , n = hostFilenames . length ; i < n ; i ++ ) {
1285
+ if ( ! sourceFileUpToDate ( program . getSourceFile ( hostFilenames [ i ] ) ) ) {
1286
+ return false ;
1287
+ }
1288
+ }
1289
+
1290
+ // If the compilation settings do no match, then the program is not up-to-date
1291
+ return compareDataObjects ( program . getCompilerOptions ( ) , hostCache . compilationSettings ( ) ) ;
1292
+ }
1293
+
1267
1294
function synchronizeHostData ( ) : void {
1268
1295
// Reset the cache at start of every refresh
1269
1296
hostCache = new HostCache ( host ) ;
1270
1297
1298
+ // If the program is already up-to-date, we can reuse it
1299
+ if ( programUpToDate ( ) ) {
1300
+ return ;
1301
+ }
1302
+
1271
1303
var compilationSettings = hostCache . compilationSettings ( ) ;
1272
1304
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
1305
// Now, remove any files from the compiler that are no longer in the host.
1278
1306
var oldProgram = program ;
1279
1307
if ( oldProgram ) {
1280
1308
var oldSettings = program . getCompilerOptions ( ) ;
1281
-
1282
1309
// If the language version changed, then that affects what types of things we parse. So
1283
1310
// we have to dump all syntax trees.
1284
1311
// TODO: handle propagateEnumConstants
@@ -1303,7 +1330,6 @@ module ts {
1303
1330
// doesn't know about it.). Or notify the compiler about any changes (if it does
1304
1331
// know about it.)
1305
1332
var hostfilenames = hostCache . getFilenames ( ) ;
1306
-
1307
1333
for ( var i = 0 , n = hostfilenames . length ; i < n ; i ++ ) {
1308
1334
var filename = hostfilenames [ i ] ;
1309
1335
@@ -1316,7 +1342,7 @@ module ts {
1316
1342
//
1317
1343
// If the sourceFile is the same, assume no update
1318
1344
//
1319
- if ( sourceFile . version === version && sourceFile . isOpen === isOpen ) {
1345
+ if ( sourceFileUpToDate ( sourceFile ) ) {
1320
1346
continue ;
1321
1347
}
1322
1348
0 commit comments