@@ -1264,21 +1264,48 @@ module ts {
12641264 } ;
12651265 }
12661266
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+
12671294 function synchronizeHostData ( ) : void {
12681295 // Reset the cache at start of every refresh
12691296 hostCache = new HostCache ( host ) ;
12701297
1298+ // If the program is already up-to-date, we can reuse it
1299+ if ( programUpToDate ( ) ) {
1300+ return ;
1301+ }
1302+
12711303 var compilationSettings = hostCache . compilationSettings ( ) ;
12721304
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-
12771305 // Now, remove any files from the compiler that are no longer in the host.
12781306 var oldProgram = program ;
12791307 if ( oldProgram ) {
12801308 var oldSettings = program . getCompilerOptions ( ) ;
1281-
12821309 // If the language version changed, then that affects what types of things we parse. So
12831310 // we have to dump all syntax trees.
12841311 // TODO: handle propagateEnumConstants
@@ -1303,7 +1330,6 @@ module ts {
13031330 // doesn't know about it.). Or notify the compiler about any changes (if it does
13041331 // know about it.)
13051332 var hostfilenames = hostCache . getFilenames ( ) ;
1306-
13071333 for ( var i = 0 , n = hostfilenames . length ; i < n ; i ++ ) {
13081334 var filename = hostfilenames [ i ] ;
13091335
@@ -1316,7 +1342,7 @@ module ts {
13161342 //
13171343 // If the sourceFile is the same, assume no update
13181344 //
1319- if ( sourceFile . version === version && sourceFile . isOpen === isOpen ) {
1345+ if ( sourceFileUpToDate ( sourceFile ) ) {
13201346 continue ;
13211347 }
13221348
0 commit comments