@@ -25,6 +25,7 @@ import { FolderContext } from "../FolderContext";
25
25
import { getPlatformConfig , resolveTaskCwd } from "../utilities/tasks" ;
26
26
import { SwiftTask , TaskPlatformSpecificConfig } from "../tasks/SwiftTaskProvider" ;
27
27
import { Version } from "../utilities/version" ;
28
+ import { existsSync } from "fs" ;
28
29
29
30
const LOADING_ICON = "loading~spin" ;
30
31
/**
@@ -469,6 +470,7 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
469
470
private activeTasks : Set < string > = new Set ( ) ;
470
471
private lastComputedNodes : TreeNode [ ] = [ ] ;
471
472
private buildPluginOutputWatcher ?: vscode . FileSystemWatcher ;
473
+ private buildPluginFolderWatcher ?: vscode . Disposable ;
472
474
473
475
onDidChangeTreeData = this . didChangeTreeDataEmitter . event ;
474
476
@@ -565,13 +567,27 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
565
567
if ( this . buildPluginOutputWatcher ) {
566
568
this . buildPluginOutputWatcher . dispose ( ) ;
567
569
}
568
- this . buildPluginOutputWatcher = vscode . workspace . createFileSystemWatcher (
569
- new vscode . RelativePattern ( folderContext . folder , ".build/plugins/outputs/{*,*/*}" )
570
- ) ;
570
+ if ( this . buildPluginFolderWatcher ) {
571
+ this . buildPluginFolderWatcher . dispose ( ) ;
572
+ }
573
+
571
574
const fire = ( ) => this . didChangeTreeDataEmitter . fire ( ) ;
572
- this . buildPluginOutputWatcher . onDidCreate ( fire ) ;
573
- this . buildPluginOutputWatcher . onDidDelete ( fire ) ;
574
- this . buildPluginOutputWatcher . onDidChange ( fire ) ;
575
+ const buildPath = path . join ( folderContext . folder . fsPath , ".build/plugins/outputs" ) ;
576
+ this . buildPluginFolderWatcher = watchForFolder (
577
+ buildPath ,
578
+ ( ) => {
579
+ this . buildPluginOutputWatcher = vscode . workspace . createFileSystemWatcher (
580
+ new vscode . RelativePattern ( buildPath , "{*,*/*}" )
581
+ ) ;
582
+ this . buildPluginOutputWatcher . onDidCreate ( fire ) ;
583
+ this . buildPluginOutputWatcher . onDidDelete ( fire ) ;
584
+ this . buildPluginOutputWatcher . onDidChange ( fire ) ;
585
+ } ,
586
+ ( ) => {
587
+ this . buildPluginOutputWatcher ?. dispose ( ) ;
588
+ fire ( ) ;
589
+ }
590
+ ) ;
575
591
}
576
592
577
593
getTreeItem ( element : TreeNode ) : vscode . TreeItem {
@@ -590,7 +606,6 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
590
606
...this . lastComputedNodes ,
591
607
] ;
592
608
}
593
-
594
609
const nodes = await this . computeChildren ( folderContext , element ) ;
595
610
596
611
// If we're fetching the root nodes then save them in case we have an error later,
@@ -794,3 +809,35 @@ class TaskPoller implements vscode.Disposable {
794
809
}
795
810
}
796
811
}
812
+
813
+ /**
814
+ * Polls for the existence of a folder at the given path every 2.5 seconds.
815
+ * Notifies via the provided callbacks when the folder becomes available or is deleted.
816
+ */
817
+ function watchForFolder (
818
+ folderPath : string ,
819
+ onAvailable : ( ) => void ,
820
+ onDeleted : ( ) => void
821
+ ) : vscode . Disposable {
822
+ const POLL_INTERVAL = 2500 ;
823
+ let folderExists = existsSync ( folderPath ) ;
824
+
825
+ if ( folderExists ) {
826
+ onAvailable ( ) ;
827
+ }
828
+
829
+ const interval = setInterval ( ( ) => {
830
+ const nowExists = existsSync ( folderPath ) ;
831
+ if ( nowExists && ! folderExists ) {
832
+ folderExists = true ;
833
+ onAvailable ( ) ;
834
+ } else if ( ! nowExists && folderExists ) {
835
+ folderExists = false ;
836
+ onDeleted ( ) ;
837
+ }
838
+ } , POLL_INTERVAL ) ;
839
+
840
+ return {
841
+ dispose : ( ) => clearInterval ( interval ) ,
842
+ } ;
843
+ }
0 commit comments