@@ -349,8 +349,32 @@ namespace ts {
349349 return endsWith ( dirPath , "/node_modules/@types" ) ;
350350 }
351351
352- function isDirectoryAtleastAtLevelFromFSRoot ( dirPath : Path , minLevels : number ) {
353- for ( let searchIndex = getRootLength ( dirPath ) ; minLevels > 0 ; minLevels -- ) {
352+ /**
353+ * Filter out paths like
354+ * "/", "/user", "/user/username", "/user/username/folderAtRoot",
355+ * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
356+ * @param dirPath
357+ */
358+ function canWatchDirectory ( dirPath : Path ) {
359+ const rootLength = getRootLength ( dirPath ) ;
360+ if ( dirPath . length === rootLength ) {
361+ // Ignore "/", "c:/"
362+ return false ;
363+ }
364+
365+ const nextDirectorySeparator = dirPath . indexOf ( directorySeparator , rootLength ) ;
366+ if ( nextDirectorySeparator === - 1 ) {
367+ // ignore "/user", "c:/users" or "c:/folderAtRoot"
368+ return false ;
369+ }
370+
371+ if ( dirPath . charCodeAt ( 0 ) !== CharacterCodes . slash &&
372+ dirPath . substr ( rootLength , nextDirectorySeparator ) . search ( / u s e r s / i) === - 1 ) {
373+ // Paths like c:/folderAtRoot/subFolder are allowed
374+ return true ;
375+ }
376+
377+ for ( let searchIndex = nextDirectorySeparator + 1 , searchLevels = 2 ; searchLevels > 0 ; searchLevels -- ) {
354378 searchIndex = dirPath . indexOf ( directorySeparator , searchIndex ) + 1 ;
355379 if ( searchIndex === 0 ) {
356380 // Folder isnt at expected minimun levels
@@ -360,15 +384,6 @@ namespace ts {
360384 return true ;
361385 }
362386
363- function canWatchDirectory ( dirPath : Path ) {
364- return isDirectoryAtleastAtLevelFromFSRoot ( dirPath ,
365- // When root is "/" do not watch directories like:
366- // "/", "/user", "/user/username", "/user/username/folderAtRoot"
367- // When root is "c:/" do not watch directories like:
368- // "c:/", "c:/folderAtRoot"
369- dirPath . charCodeAt ( 0 ) === CharacterCodes . slash ? 3 : 1 ) ;
370- }
371-
372387 function filterFSRootDirectoriesToWatch ( watchPath : DirectoryOfFailedLookupWatch , dirPath : Path ) : DirectoryOfFailedLookupWatch {
373388 if ( ! canWatchDirectory ( dirPath ) ) {
374389 watchPath . ignore = true ;
0 commit comments