From a904e979c6070d35afdd1eef1cb199a77906f3eb Mon Sep 17 00:00:00 2001 From: Simon Graband Date: Fri, 10 Mar 2023 11:26:47 +0100 Subject: [PATCH] Fix file watching events being lost (#12264) Fixed an issue with tracking the current `FileSystemEvents` in the `MainFileSystemEventService`. Before, the events were tracked in a global field which was intended to be cleaned after an `onDidFilesChanges()` update was sent to the proxy. This is problematic as we do not await sending the update. Thus, the global field will be cleaned before the update is even sent and therefore, file watching updates might get lost. This change ensures that a field of events is kept for each update. Note that simply awaiting the update to be sent is not enough. This would introduce race conditions as other parallel updates might clean the state of other updates before they are being sent. Fixes #12260. Contributed on behalf of STMicroelectronics --- .../browser/main-file-system-event-service.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/plugin-ext/src/main/browser/main-file-system-event-service.ts b/packages/plugin-ext/src/main/browser/main-file-system-event-service.ts index 02d1ad6b635a8..1a9593d9eb6cb 100644 --- a/packages/plugin-ext/src/main/browser/main-file-system-event-service.ts +++ b/packages/plugin-ext/src/main/browser/main-file-system-event-service.ts @@ -37,13 +37,13 @@ export class MainFileSystemEventService { const proxy = rpc.getProxy(MAIN_RPC_CONTEXT.ExtHostFileSystemEventService); const fileService = container.get(FileService); - // file system events - (changes the editor and other make) - const events: FileSystemEvents = { - created: [], - changed: [], - deleted: [] - }; this.toDispose.push(fileService.onDidFilesChange(event => { + // file system events - (changes the editor and others make) + const events: FileSystemEvents = { + created: [], + changed: [], + deleted: [] + }; for (const change of event.changes) { switch (change.type) { case FileChangeType.ADDED: @@ -59,9 +59,6 @@ export class MainFileSystemEventService { } proxy.$onFileEvent(events); - events.created.length = 0; - events.changed.length = 0; - events.deleted.length = 0; })); // BEFORE file operation