Skip to content

Commit a65fb16

Browse files
author
Benjamin Pasero
committed
💄
1 parent 98ea894 commit a65fb16

2 files changed

Lines changed: 8 additions & 19 deletions

File tree

src/vs/base/node/watcher.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export function watchFolder(path: string, onChange: (type: 'added' | 'changed' |
2121
export const CHANGE_BUFFER_DELAY = 100;
2222

2323
function 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
}

src/vs/workbench/services/files2/node/watcher/nodejs/watcherService.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,14 @@ export class FileWatcher extends Disposable {
9696
}
9797

9898
// Fire
99-
this.onFileEvents(normalizedFileChanges);
99+
if (normalizedFileChanges.length > 0) {
100+
this.onFileChanges(normalizedFileChanges);
101+
}
100102

101103
return Promise.resolve();
102104
});
103105
}
104106

105-
private onFileEvents(events: IDiskFileChange[]): void {
106-
if (this.isDisposed) {
107-
return;
108-
}
109-
110-
// Emit through event emitter
111-
if (events.length > 0) {
112-
this.onFileChanges(events);
113-
}
114-
}
115-
116107
private onError(error: string): void {
117108
if (!this.isDisposed) {
118109
this.errorLogger(error);

0 commit comments

Comments
 (0)