Skip to content

Commit ec4b039

Browse files
committed
optimize folder watcher for Resource Explorer
1 parent 7e91a2c commit ec4b039

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/CodeBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export abstract class CodeBuilder {
278278
this.logWatcher = new FileWatcher(builderLog, false);
279279
this.logWatcher.OnChanged = () => {
280280
this.logWatcher?.Close();
281-
setTimeout(() => this.emit('finished', checkBuildDone(builderLog)), 400);
281+
setTimeout(() => this.emit('finished', checkBuildDone(builderLog)), 500);
282282
};
283283

284284
// start watch

src/EIDEProject.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ class SourceRootList implements SourceProvider {
384384
this.project = _project;
385385
this._event = new events.EventEmitter();
386386
this.srcFolderMaps = new Map();
387+
FileWatcher.on('rename', f => this.onFolderRenamed(this.getSourceRootKeyByAbspath(f.path), f));
387388
}
388389

389390
isAutoSearchObjectFile(): boolean {
@@ -413,10 +414,9 @@ class SourceRootList implements SourceProvider {
413414
}
414415

415416
private _add(dir: File): SourceRootInfo {
416-
const key: string = this.getRelativePath(dir.path);
417+
const key: string = this.getSourceRootKeyByAbspath(dir.path);
417418
const watcher = platform.createSafetyFileWatcher(dir, true);
418419
watcher.on('error', (err) => GlobalEvent.emit('globalLog', ExceptionToMessage(err, 'Warning')));
419-
watcher.OnRename = (file) => this.onFolderRenamed(key, file);
420420
const sourceInfo = this.newSourceInfo(key, watcher);
421421
this.srcFolderMaps.set(key, sourceInfo);
422422
return sourceInfo;
@@ -430,7 +430,7 @@ class SourceRootList implements SourceProvider {
430430
}
431431

432432
remove(absPath: string): boolean {
433-
const key = this.getRelativePath(absPath);
433+
const key = this.getSourceRootKeyByAbspath(absPath);
434434
return this.removeByKey(key);
435435
}
436436

@@ -566,7 +566,7 @@ class SourceRootList implements SourceProvider {
566566
this._event.emit(event, arg);
567567
}
568568

569-
private getRelativePath(abspath: string): string {
569+
private getSourceRootKeyByAbspath(abspath: string): string {
570570
return this.project.toRelativePath(abspath);
571571
}
572572

@@ -594,7 +594,9 @@ class SourceRootList implements SourceProvider {
594594
const rootInfo = this.srcFolderMaps.get(folderKey);
595595
if (rootInfo) {
596596

597-
if (targetFile.path == rootInfo.fileWatcher.file.path) { // root folder has been renamed
597+
// folder self has been renamed ?
598+
// - if true, this folder's file watcher is invalid, dispose it
599+
if (targetFile.path == rootInfo.fileWatcher.file.path) {
598600
this.disposeWatcher(folderKey);
599601
this.emit('dataChanged', 'folderStatusChanged');
600602
}

0 commit comments

Comments
 (0)