@@ -119,7 +119,7 @@ namespace ts.server {
119119 if ( ! resolution ) {
120120 const existingResolution = currentResolutionsInFile && ts . lookUp ( currentResolutionsInFile , moduleName ) ;
121121 if ( moduleResolutionIsValid ( existingResolution ) ) {
122- // ok, it is safe to use existing module resolution results
122+ // ok, it is safe to use existing module resolution results
123123 resolution = existingResolution ;
124124 }
125125 else {
@@ -144,8 +144,8 @@ namespace ts.server {
144144 }
145145
146146 if ( resolution . resolvedModule ) {
147- // TODO: consider checking failedLookupLocations
148- // TODO: use lastCheckTime to track expiration for module name resolution
147+ // TODO: consider checking failedLookupLocations
148+ // TODO: use lastCheckTime to track expiration for module name resolution
149149 return true ;
150150 }
151151
@@ -354,6 +354,7 @@ namespace ts.server {
354354 export interface ProjectOptions {
355355 // these fields can be present in the project file
356356 files ?: string [ ] ;
357+ wildcardDirectories ?: ts . Map < ts . WatchDirectoryFlags > ;
357358 compilerOptions ?: ts . CompilerOptions ;
358359 }
359360
@@ -362,6 +363,7 @@ namespace ts.server {
362363 projectFilename : string ;
363364 projectFileWatcher : FileWatcher ;
364365 directoryWatcher : FileWatcher ;
366+ directoriesWatchedForWildcards : Map < FileWatcher > ;
365367 // Used to keep track of what directories are watched for this project
366368 directoriesWatchedForTsconfig : string [ ] = [ ] ;
367369 program : ts . Program ;
@@ -510,7 +512,7 @@ namespace ts.server {
510512 openFileRootsConfigured : ScriptInfo [ ] = [ ] ;
511513 // a path to directory watcher map that detects added tsconfig files
512514 directoryWatchersForTsconfig : ts . Map < FileWatcher > = { } ;
513- // count of how many projects are using the directory watcher. If the
515+ // count of how many projects are using the directory watcher. If the
514516 // number becomes 0 for a watcher, then we should close it.
515517 directoryWatchersRefCount : ts . Map < number > = { } ;
516518 hostConfiguration : HostConfiguration ;
@@ -590,11 +592,11 @@ namespace ts.server {
590592 // We check if the project file list has changed. If so, we update the project.
591593 if ( ! arrayIsEqualTo ( currentRootFiles && currentRootFiles . sort ( ) , newRootFiles && newRootFiles . sort ( ) ) ) {
592594 // For configured projects, the change is made outside the tsconfig file, and
593- // it is not likely to affect the project for other files opened by the client. We can
595+ // it is not likely to affect the project for other files opened by the client. We can
594596 // just update the current project.
595597 this . updateConfiguredProject ( project ) ;
596598
597- // Call updateProjectStructure to clean up inferred projects we may have
599+ // Call updateProjectStructure to clean up inferred projects we may have
598600 // created for the new files
599601 this . updateProjectStructure ( ) ;
600602 }
@@ -739,6 +741,8 @@ namespace ts.server {
739741 if ( project . isConfiguredProject ( ) ) {
740742 project . projectFileWatcher . close ( ) ;
741743 project . directoryWatcher . close ( ) ;
744+ forEachValue ( project . directoriesWatchedForWildcards , watcher => { watcher . close ( ) ; } ) ;
745+ delete project . directoriesWatchedForWildcards ;
742746 this . configuredProjects = copyListRemovingItem ( project , this . configuredProjects ) ;
743747 }
744748 else {
@@ -816,8 +820,8 @@ namespace ts.server {
816820 * @param info The file that has been closed or newly configured
817821 */
818822 closeOpenFile ( info : ScriptInfo ) {
819- // Closing file should trigger re-reading the file content from disk. This is
820- // because the user may chose to discard the buffer content before saving
823+ // Closing file should trigger re-reading the file content from disk. This is
824+ // because the user may chose to discard the buffer content before saving
821825 // to the disk, and the server's version of the file can be out of sync.
822826 info . svc . reloadFromFile ( info . fileName ) ;
823827
@@ -915,8 +919,8 @@ namespace ts.server {
915919 }
916920
917921 /**
918- * This function is to update the project structure for every projects.
919- * It is called on the premise that all the configured projects are
922+ * This function is to update the project structure for every projects.
923+ * It is called on the premise that all the configured projects are
920924 * up to date.
921925 */
922926 updateProjectStructure ( ) {
@@ -970,7 +974,7 @@ namespace ts.server {
970974
971975 if ( rootFile . defaultProject && rootFile . defaultProject . isConfiguredProject ( ) ) {
972976 // If the root file has already been added into a configured project,
973- // meaning the original inferred project is gone already.
977+ // meaning the original inferred project is gone already.
974978 if ( ! rootedProject . isConfiguredProject ( ) ) {
975979 this . removeProject ( rootedProject ) ;
976980 }
@@ -1075,9 +1079,9 @@ namespace ts.server {
10751079 }
10761080
10771081 /**
1078- * This function tries to search for a tsconfig.json for the given file. If we found it,
1082+ * This function tries to search for a tsconfig.json for the given file. If we found it,
10791083 * we first detect if there is already a configured project created for it: if so, we re-read
1080- * the tsconfig file content and update the project; otherwise we create a new one.
1084+ * the tsconfig file content and update the project; otherwise we create a new one.
10811085 */
10821086 openOrUpdateConfiguredProjectForFile ( fileName : string ) {
10831087 const searchPath = ts . normalizePath ( getDirectoryPath ( fileName ) ) ;
@@ -1215,7 +1219,8 @@ namespace ts.server {
12151219 else {
12161220 const projectOptions : ProjectOptions = {
12171221 files : parsedCommandLine . fileNames ,
1218- compilerOptions : parsedCommandLine . options
1222+ wildcardDirectories : parsedCommandLine . wildcardDirectories ,
1223+ compilerOptions : parsedCommandLine . options ,
12191224 } ;
12201225 return { succeeded : true , projectOptions } ;
12211226 }
@@ -1241,12 +1246,30 @@ namespace ts.server {
12411246 }
12421247 project . finishGraph ( ) ;
12431248 project . projectFileWatcher = this . host . watchFile ( configFilename , _ => this . watchedProjectConfigFileChanged ( project ) ) ;
1244- this . log ( "Add recursive watcher for: " + ts . getDirectoryPath ( configFilename ) ) ;
1249+
1250+ const configDirectoryPath = ts . getDirectoryPath ( configFilename ) ;
1251+
1252+ this . log ( "Add recursive watcher for: " + configDirectoryPath ) ;
12451253 project . directoryWatcher = this . host . watchDirectory (
1246- ts . getDirectoryPath ( configFilename ) ,
1254+ configDirectoryPath ,
12471255 path => this . directoryWatchedForSourceFilesChanged ( project , path ) ,
12481256 /*recursive*/ true
12491257 ) ;
1258+
1259+ project . directoriesWatchedForWildcards = reduceProperties ( projectOptions . wildcardDirectories , ( watchers , flag , directory ) => {
1260+ if ( comparePaths ( configDirectoryPath , directory , "." , ! this . host . useCaseSensitiveFileNames ) !== Comparison . EqualTo ) {
1261+ const recursive = ( flag & WatchDirectoryFlags . Recursive ) !== 0 ;
1262+ this . log ( `Add ${ recursive ? "recursive " : "" } watcher for: ${ directory } ` ) ;
1263+ watchers [ directory ] = this . host . watchDirectory (
1264+ directory ,
1265+ path => this . directoryWatchedForSourceFilesChanged ( project , path ) ,
1266+ recursive
1267+ ) ;
1268+ }
1269+
1270+ return watchers ;
1271+ } , < Map < FileWatcher > > { } ) ;
1272+
12501273 return { success : true , project : project } ;
12511274 }
12521275 }
@@ -1280,7 +1303,7 @@ namespace ts.server {
12801303 info = this . openFile ( fileName , /*openedByClient*/ false ) ;
12811304 }
12821305 else {
1283- // if the root file was opened by client, it would belong to either
1306+ // if the root file was opened by client, it would belong to either
12841307 // openFileRoots or openFileReferenced.
12851308 if ( info . isOpen ) {
12861309 if ( this . openFileRoots . indexOf ( info ) >= 0 ) {
0 commit comments