@@ -21,12 +21,14 @@ export function watchFolder(path: string, onChange: (type: 'added' | 'changed' |
2121export const CHANGE_BUFFER_DELAY = 100 ;
2222
2323function doWatchNonRecursive ( file : { path : string , isDirectory : boolean } , onChange : ( type : 'added' | 'changed' | 'deleted' , path : string ) => void , onError : ( error : string ) => void ) : IDisposable {
24+ const originalFileName = basename ( file . path ) ;
2425 const mapPathToStatDisposable = new Map < string , IDisposable > ( ) ;
2526
2627 let disposed = false ;
27- let watcherDisposables : IDisposable [ ] = [ ] ;
28-
29- const originalFileName = basename ( file . path ) ;
28+ let watcherDisposables : IDisposable [ ] = [ toDisposable ( ( ) => {
29+ mapPathToStatDisposable . forEach ( disposable => dispose ( disposable ) ) ;
30+ mapPathToStatDisposable . clear ( ) ;
31+ } ) ] ;
3032
3133 try {
3234
@@ -84,7 +86,6 @@ function doWatchNonRecursive(file: { path: string, isDirectory: boolean }, onCha
8486 // In addition, we send out a delete event if after a timeout we detect that the file
8587 // does indeed not exist anymore.
8688
87- // Wait a bit and try to install watcher again, assuming that the file was renamed quickly ("Atomic Save")
8889 const timeoutHandle = setTimeout ( async ( ) => {
8990 const fileExists = await exists ( changedFilePath ) ;
9091
@@ -187,8 +188,5 @@ function doWatchNonRecursive(file: { path: string, isDirectory: boolean }, onCha
187188 disposed = true ;
188189
189190 watcherDisposables = dispose ( watcherDisposables ) ;
190-
191- mapPathToStatDisposable . forEach ( disposable => dispose ( disposable ) ) ;
192- mapPathToStatDisposable . clear ( ) ;
193191 } ) ;
194192}
0 commit comments