Skip to content

Commit

Permalink
fix: delete watcherMap when watcher is disposed (#2910)
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiiiiii authored Jul 20, 2023
1 parent 2d8d536 commit 9181a0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/file-service/src/browser/file-service-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,14 @@ export class FileServiceClient implements IFileServiceClient {
// 添加监听文件
async watchFileChanges(uri: URI, excludes?: string[]): Promise<IFileServiceWatcher> {
const _uri = this.convertUri(uri.toString());
if (this.uriWatcherMap.has(_uri.toString())) {
return this.uriWatcherMap.get(_uri.toString())!;
const originWatcher = this.uriWatcherMap.get(_uri.toString());
if (originWatcher) {
// 这里兼容重连逻辑,重连时 watcher 会 disposed,需要重新生成
if (!originWatcher.isDisposed()) {
return originWatcher;
} else {
this.uriWatcherMap.delete(_uri.toString());
}
}

const id = this.watcherId++;
Expand Down
4 changes: 4 additions & 0 deletions packages/file-service/src/browser/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ export class FileSystemWatcher implements IFileServiceWatcher {
this.fileServiceClient.unwatchFileChanges(this.watchId),
]) as any;
}

isDisposed() {
return this.toDispose.disposed;
}
}

0 comments on commit 9181a0b

Please sign in to comment.