Skip to content

Commit 6be07dd

Browse files
committed
fix: add excludes after reconnected
1 parent b4c46c2 commit 6be07dd

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

packages/file-service/src/browser/file-service-client.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,13 @@ export class FileServiceClient implements IFileServiceClient, IDisposable {
352352
this.eventBus.fire(new FilesChangeEvent(changes));
353353
}
354354

355-
private uriWatcherMap: Map<string, FileSystemWatcher> = new Map();
355+
private uriWatcherMap: Map<
356+
string,
357+
{
358+
watcher: FileSystemWatcher;
359+
excludes?: string[];
360+
}
361+
> = new Map();
356362

357363
// 添加监听文件
358364
async watchFileChanges(uri: URI, excludes?: string[]): Promise<IFileServiceWatcher> {
@@ -367,8 +373,11 @@ export class FileServiceClient implements IFileServiceClient, IDisposable {
367373

368374
let prevWatcher: IFileServiceWatcher | undefined;
369375
if (this.uriWatcherMap.has(_uri.toString())) {
370-
prevWatcher = this.uriWatcherMap.get(_uri.toString()) as IFileServiceWatcher;
371-
prevWatcher.dispose();
376+
const watcherInfo = this.uriWatcherMap.get(_uri.toString());
377+
prevWatcher = watcherInfo?.watcher;
378+
if (prevWatcher) {
379+
await prevWatcher.dispose();
380+
}
372381
}
373382

374383
if (prevWatcher) {
@@ -384,7 +393,8 @@ export class FileServiceClient implements IFileServiceClient, IDisposable {
384393

385394
this.watcherDisposerMap.set(id, {
386395
dispose: async () => {
387-
const watcher = this.uriWatcherMap.get(_uri.toString());
396+
const watcherInfo = this.uriWatcherMap.get(_uri.toString());
397+
const watcher = watcherInfo?.watcher;
388398
await Promise.all([provider.unwatch && provider.unwatch(watcherId), watcher && watcher.dispose()]);
389399
this.uriWatcherMap.delete(_uri.toString());
390400
},
@@ -396,7 +406,10 @@ export class FileServiceClient implements IFileServiceClient, IDisposable {
396406
watchId: id,
397407
uri,
398408
});
399-
this.uriWatcherMap.set(_uri.toString(), watcher);
409+
this.uriWatcherMap.set(_uri.toString(), {
410+
watcher,
411+
excludes,
412+
});
400413
return watcher;
401414
}
402415

@@ -722,16 +735,17 @@ export class FileServiceClient implements IFileServiceClient, IDisposable {
722735
await provider.initialize(this.clientId, this.appConfig.recursiveWatcherBackend);
723736
}
724737
const uriList = Array.from(this.uriWatcherMap.keys());
725-
for (const uriString of uriList) {
738+
const reconnectPromises = uriList.map(async (uriString) => {
726739
try {
727740
const uri = new URI(uriString);
728-
const watcher = this.uriWatcherMap.get(uriString);
729-
if (watcher) {
730-
await this.watchFileChanges(uri);
741+
const watcherInfo = this.uriWatcherMap.get(uriString);
742+
if (watcherInfo?.watcher) {
743+
await this.watchFileChanges(uri, watcherInfo.excludes);
731744
}
732745
} catch (err) {
733746
this.logger?.error('Error reconnecting watcher for:', uriString, err);
734747
}
735-
}
748+
});
749+
await Promise.allSettled(reconnectPromises);
736750
}
737751
}

0 commit comments

Comments
 (0)