Skip to content

Commit

Permalink
Fix file watching events being lost (#12264)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sgraband authored and tsmaeder committed Mar 17, 2023
1 parent 13392f6 commit a904e97
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit a904e97

Please sign in to comment.