@@ -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