@@ -69,6 +69,8 @@ namespace ts.server {
6969
7070 protected projectErrors : Diagnostic [ ] ;
7171
72+ public typesVersion = 0 ;
73+
7274 public isJsOnlyProject ( ) {
7375 this . updateGraph ( ) ;
7476 return allFilesAreJsOrDts ( this ) ;
@@ -153,6 +155,12 @@ namespace ts.server {
153155 return this . program . getSourceFileByPath ( path ) ;
154156 }
155157
158+ updateTypes ( ) {
159+ this . typesVersion ++ ;
160+ this . markAsDirty ( ) ;
161+ this . updateGraph ( ) ;
162+ }
163+
156164 close ( ) {
157165 if ( this . program ) {
158166 // if we have a program - release all files that are enlisted in program
@@ -569,6 +577,7 @@ namespace ts.server {
569577 private projectFileWatcher : FileWatcher ;
570578 private directoryWatcher : FileWatcher ;
571579 private directoriesWatchedForWildcards : Map < FileWatcher > ;
580+ private typeRootsWatchers : FileWatcher [ ] ;
572581
573582 /** Used for configured projects which may have multiple open roots */
574583 openRefCount = 0 ;
@@ -608,6 +617,16 @@ namespace ts.server {
608617 this . projectFileWatcher = this . projectService . host . watchFile ( this . configFileName , _ => callback ( this ) ) ;
609618 }
610619
620+ watchTypeRoots ( callback : ( project : ConfiguredProject , path : string ) => void ) {
621+ const roots = this . getEffectiveTypeRoots ( ) ;
622+ const watchers : FileWatcher [ ] = [ ] ;
623+ for ( const root of roots ) {
624+ this . projectService . logger . info ( `Add type root watcher for: ${ root } ` ) ;
625+ watchers . push ( this . projectService . host . watchDirectory ( root , path => callback ( this , path ) , /*recursive*/ false ) ) ;
626+ }
627+ this . typeRootsWatchers = watchers ;
628+ }
629+
611630 watchConfigDirectory ( callback : ( project : ConfiguredProject , path : string ) => void ) {
612631 if ( this . directoryWatcher ) {
613632 return ;
@@ -651,6 +670,13 @@ namespace ts.server {
651670 this . projectFileWatcher . close ( ) ;
652671 }
653672
673+ if ( this . typeRootsWatchers ) {
674+ for ( const watcher of this . typeRootsWatchers ) {
675+ watcher . close ( ) ;
676+ }
677+ this . typeRootsWatchers = undefined ;
678+ }
679+
654680 for ( const id in this . directoriesWatchedForWildcards ) {
655681 this . directoriesWatchedForWildcards [ id ] . close ( ) ;
656682 }
@@ -667,6 +693,10 @@ namespace ts.server {
667693 this . openRefCount -- ;
668694 return this . openRefCount ;
669695 }
696+
697+ getEffectiveTypeRoots ( ) {
698+ return ts . getEffectiveTypeRoots ( this . getCompilerOptions ( ) , this . projectService . host ) || [ ] ;
699+ }
670700 }
671701
672702 export class ExternalProject extends Project {
0 commit comments