@@ -76,6 +76,41 @@ namespace ts {
7676 return some ( ignoredPaths , searchPath => stringContains ( path , searchPath ) ) ;
7777 }
7878
79+ /**
80+ * Filter out paths like
81+ * "/", "/user", "/user/username", "/user/username/folderAtRoot",
82+ * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
83+ * @param dirPath
84+ */
85+ export function canWatchDirectory ( dirPath : Path ) {
86+ const rootLength = getRootLength ( dirPath ) ;
87+ if ( dirPath . length === rootLength ) {
88+ // Ignore "/", "c:/"
89+ return false ;
90+ }
91+
92+ const nextDirectorySeparator = dirPath . indexOf ( directorySeparator , rootLength ) ;
93+ if ( nextDirectorySeparator === - 1 ) {
94+ // ignore "/user", "c:/users" or "c:/folderAtRoot"
95+ return false ;
96+ }
97+
98+ if ( dirPath . charCodeAt ( 0 ) !== CharacterCodes . slash &&
99+ dirPath . substr ( rootLength , nextDirectorySeparator ) . search ( / u s e r s / i) === - 1 ) {
100+ // Paths like c:/folderAtRoot/subFolder are allowed
101+ return true ;
102+ }
103+
104+ for ( let searchIndex = nextDirectorySeparator + 1 , searchLevels = 2 ; searchLevels > 0 ; searchLevels -- ) {
105+ searchIndex = dirPath . indexOf ( directorySeparator , searchIndex ) + 1 ;
106+ if ( searchIndex === 0 ) {
107+ // Folder isnt at expected minimun levels
108+ return false ;
109+ }
110+ }
111+ return true ;
112+ }
113+
79114 export const maxNumberOfFilesToIterateForInvalidation = 256 ;
80115
81116 type GetResolutionWithResolvedFileName < T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations , R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName > =
@@ -373,41 +408,6 @@ namespace ts {
373408 return endsWith ( dirPath , "/node_modules/@types" ) ;
374409 }
375410
376- /**
377- * Filter out paths like
378- * "/", "/user", "/user/username", "/user/username/folderAtRoot",
379- * "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
380- * @param dirPath
381- */
382- function canWatchDirectory ( dirPath : Path ) {
383- const rootLength = getRootLength ( dirPath ) ;
384- if ( dirPath . length === rootLength ) {
385- // Ignore "/", "c:/"
386- return false ;
387- }
388-
389- const nextDirectorySeparator = dirPath . indexOf ( directorySeparator , rootLength ) ;
390- if ( nextDirectorySeparator === - 1 ) {
391- // ignore "/user", "c:/users" or "c:/folderAtRoot"
392- return false ;
393- }
394-
395- if ( dirPath . charCodeAt ( 0 ) !== CharacterCodes . slash &&
396- dirPath . substr ( rootLength , nextDirectorySeparator ) . search ( / u s e r s / i) === - 1 ) {
397- // Paths like c:/folderAtRoot/subFolder are allowed
398- return true ;
399- }
400-
401- for ( let searchIndex = nextDirectorySeparator + 1 , searchLevels = 2 ; searchLevels > 0 ; searchLevels -- ) {
402- searchIndex = dirPath . indexOf ( directorySeparator , searchIndex ) + 1 ;
403- if ( searchIndex === 0 ) {
404- // Folder isnt at expected minimun levels
405- return false ;
406- }
407- }
408- return true ;
409- }
410-
411411 function getDirectoryToWatchFailedLookupLocation ( failedLookupLocation : string , failedLookupLocationPath : Path ) : DirectoryOfFailedLookupWatch | undefined {
412412 if ( isInDirectoryPath ( rootPath , failedLookupLocationPath ) ) {
413413 // Ensure failed look up is normalized path
0 commit comments