Skip to content

Commit aa74782

Browse files
authored
watcher - ignore uncorrelated events when in correlation mode (microsoft#196530)
1 parent 18b7f75 commit aa74782

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/vs/workbench/api/browser/mainThreadFileSystemEventService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ export class MainThreadFileSystemEventService implements MainThreadFileSystemEve
214214

215215
async $watch(extensionId: string, session: number, resource: UriComponents, unvalidatedOpts: IWatchOptions): Promise<void> {
216216
const uri = URI.revive(resource);
217-
const correlate = Array.isArray(unvalidatedOpts?.excludes) && unvalidatedOpts.excludes.length > 0; // TODO@bpasero for now only correlate proposed new file system watcher API with excludes
218217

219218
const opts: IWatchOptions = {
220219
...unvalidatedOpts
@@ -235,7 +234,8 @@ export class MainThreadFileSystemEventService implements MainThreadFileSystemEve
235234
}
236235
}
237236

238-
// Correlated file watching is taken as is
237+
// Correlated file watching is taken as is (for now we only opt into correlating with proposed new file system watcher API with excludes)
238+
const correlate = Array.isArray(unvalidatedOpts?.excludes) && unvalidatedOpts.excludes.length > 0;
239239
if (correlate) {
240240
this._logService.trace(`MainThreadFileSystemEventService#$watch(): request to start watching correlated (extension: ${extensionId}, path: ${uri.toString(true)}, recursive: ${opts.recursive}, session: ${session})`);
241241

src/vs/workbench/api/common/extHostFileSystemEventService.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,18 @@ class FileSystemWatcher implements vscode.FileSystemWatcher {
7070
// https://github.com/microsoft/vscode/issues/3025
7171
const excludeOutOfWorkspaceEvents = typeof globPattern === 'string';
7272

73+
// 1.84.x introduces new proposed API for a watcher to set exclude
74+
// rules. When this is provided, we turn the file watcher into correlation
75+
// mode and ignore any event that does not match the correlation ID.
76+
const excludeUncorrelatedEvents = Array.isArray(options?.excludes) && options.excludes.length > 0;
77+
7378
const subscription = dispatcher(events => {
7479
if (typeof events.session === 'number' && events.session !== this.session) {
75-
return; // ignore events from other file watchers
80+
return; // ignore events from other file watchers that are in correlation mode
81+
}
82+
83+
if (excludeUncorrelatedEvents && typeof events.session === 'undefined') {
84+
return; // ignore events from other non-correlating file watcher when we are in correlation mode
7685
}
7786

7887
if (!options?.ignoreCreateEvents) {

0 commit comments

Comments
 (0)