@@ -363,6 +363,10 @@ namespace ts.server {
363363 this . printProjects ( ) ;
364364 }
365365
366+ private onTypeRootFileChanged ( project : ConfiguredProject , fileName : string ) {
367+ this . onSourceFileInDirectoryChangedForConfiguredProject ( project , fileName ) ;
368+ }
369+
366370 /**
367371 * This is the callback function when a watched directory has added or removed source code files.
368372 * @param project the project that associates with this directory watcher
@@ -389,17 +393,29 @@ namespace ts.server {
389393
390394 const newRootFiles = projectOptions . files . map ( ( f => this . getCanonicalFileName ( f ) ) ) ;
391395 const currentRootFiles = project . getRootFiles ( ) . map ( ( f => this . getCanonicalFileName ( f ) ) ) ;
396+ const lastUpdateTypesRoot : number = Math . max . apply ( Math , project . getEffectiveTypeRoots ( ) . map ( root => {
397+ this . logger . info ( 'Compute for ' + root ) ;
398+ if ( this . host . directoryExists ( root ) ) {
399+ return + this . host . getModifiedTime ( root ) ;
400+ }
401+ return 0 ;
402+ } ) ) ;
403+ this . logger . info ( 'Last type roots update = ' + lastUpdateTypesRoot + ', last was ' + project . lastUpdatedTypesRootTime ) ;
392404
393405 // We check if the project file list has changed. If so, we update the project.
394- if ( ! arrayIsEqualTo ( currentRootFiles . sort ( ) , newRootFiles . sort ( ) ) ) {
406+ if ( ! arrayIsEqualTo ( currentRootFiles . sort ( ) , newRootFiles . sort ( ) ) || ( lastUpdateTypesRoot > project . lastUpdatedTypesRootTime ) ) {
395407 // For configured projects, the change is made outside the tsconfig file, and
396408 // it is not likely to affect the project for other files opened by the client. We can
397409 // just update the current project.
410+
411+ this . logger . info ( 'Updating configured project' ) ;
398412 this . updateConfiguredProject ( project ) ;
399413
400414 // Call refreshInferredProjects to clean up inferred projects we may have
401415 // created for the new files
402416 this . refreshInferredProjects ( ) ;
417+
418+ project . lastUpdatedTypesRootTime = lastUpdateTypesRoot ;
403419 }
404420 }
405421
@@ -771,13 +787,14 @@ namespace ts.server {
771787 this . watchConfigDirectoryForProject ( project , projectOptions ) ;
772788 }
773789 project . watchWildcards ( ( project , path ) => this . onSourceFileInDirectoryChangedForConfiguredProject ( project , path ) ) ;
790+ project . watchTypeRoots ( ( project , path ) => this . onTypeRootFileChanged ( project , path ) ) ;
774791
775792 this . configuredProjects . push ( project ) ;
776793 return project ;
777794 }
778795
779796 private watchConfigDirectoryForProject ( project : ConfiguredProject , options : ProjectOptions ) : void {
780- if ( ! options . configHasFilesProperty ) {
797+ if ( ! options . configHasFilesProperty || ( options . compilerOptions . types === undefined ) ) {
781798 project . watchConfigDirectory ( ( project , path ) => this . onSourceFileInDirectoryChangedForConfiguredProject ( project , path ) ) ;
782799 }
783800 }
0 commit comments