@@ -531,6 +531,8 @@ impl GlobalState {
531531 }
532532 }
533533
534+ self . cleanup_discover_handles ( ) ;
535+
534536 if let Some ( diagnostic_changes) = self . diagnostics . take_changes ( ) {
535537 for file_id in diagnostic_changes {
536538 let uri = file_id_to_url ( & self . vfs . read ( ) . 0 , file_id) ;
@@ -806,33 +808,34 @@ impl GlobalState {
806808 self . report_progress ( "Fetching" , state, msg, None , None ) ;
807809 }
808810 Task :: DiscoverLinkedProjects ( arg) => {
809- if let Some ( cfg) = self . config . discover_workspace_config ( )
810- && !self . discover_workspace_queue . op_in_progress ( )
811- {
811+ if let Some ( cfg) = self . config . discover_workspace_config ( ) {
812812 // the clone is unfortunately necessary to avoid a borrowck error when
813813 // `self.report_progress` is called later
814814 let title = & cfg. progress_label . clone ( ) ;
815815 let command = cfg. command . clone ( ) ;
816816 let discover = DiscoverCommand :: new ( self . discover_sender . clone ( ) , command) ;
817817
818- self . report_progress ( title , Progress :: Begin , None , None , None ) ;
819- self . discover_workspace_queue
820- . request_op ( "Discovering workspace" . to_owned ( ) , ( ) ) ;
821- let _ = self . discover_workspace_queue . should_start_op ( ) ;
818+ if self . discover_jobs_active == 0 {
819+ self . report_progress ( title , Progress :: Begin , None , None , None ) ;
820+ }
821+ self . discover_jobs_active += 1 ;
822822
823823 let arg = match arg {
824824 DiscoverProjectParam :: Buildfile ( it) => DiscoverArgument :: Buildfile ( it) ,
825825 DiscoverProjectParam :: Path ( it) => DiscoverArgument :: Path ( it) ,
826826 } ;
827827
828- let handle = discover. spawn (
829- arg,
830- & std:: env:: current_dir ( )
831- . expect ( "Failed to get cwd during project discovery" ) ,
832- ) ;
833- self . discover_handle = Some ( handle. unwrap_or_else ( |e| {
834- panic ! ( "Failed to spawn project discovery command: {e}" )
835- } ) ) ;
828+ let handle = discover
829+ . spawn (
830+ arg,
831+ & std:: env:: current_dir ( )
832+ . expect ( "Failed to get cwd during project discovery" ) ,
833+ )
834+ . unwrap_or_else ( |e| {
835+ panic ! ( "Failed to spawn project discovery command: {e}" )
836+ } ) ;
837+
838+ self . discover_handles . push ( handle) ;
836839 }
837840 }
838841 Task :: FetchBuildData ( progress) => {
@@ -1036,25 +1039,43 @@ impl GlobalState {
10361039 . expect ( "No title could be found; this is a bug" ) ;
10371040 match message {
10381041 DiscoverProjectMessage :: Finished { project, buildfile } => {
1039- self . discover_handle = None ;
1040- self . report_progress ( & title, Progress :: End , None , None , None ) ;
1041- self . discover_workspace_queue . op_completed ( ( ) ) ;
1042+ self . discover_jobs_active = self . discover_jobs_active . saturating_sub ( 1 ) ;
1043+ if self . discover_jobs_active == 0 {
1044+ self . report_progress ( & title, Progress :: End , None , None , None ) ;
1045+ }
10421046
10431047 let mut config = Config :: clone ( & * self . config ) ;
10441048 config. add_discovered_project_from_command ( project, buildfile) ;
10451049 self . update_configuration ( config) ;
10461050 }
10471051 DiscoverProjectMessage :: Progress { message } => {
1048- self . report_progress ( & title, Progress :: Report , Some ( message) , None , None )
1052+ if self . discover_jobs_active > 0 {
1053+ self . report_progress ( & title, Progress :: Report , Some ( message) , None , None )
1054+ }
10491055 }
10501056 DiscoverProjectMessage :: Error { error, source } => {
1051- self . discover_handle = None ;
10521057 let message = format ! ( "Project discovery failed: {error}" ) ;
1053- self . discover_workspace_queue . op_completed ( ( ) ) ;
10541058 self . show_and_log_error ( message. clone ( ) , source) ;
1055- self . report_progress ( & title, Progress :: End , Some ( message) , None , None )
1059+
1060+ self . discover_jobs_active = self . discover_jobs_active . saturating_sub ( 1 ) ;
1061+ if self . discover_jobs_active == 0 {
1062+ self . report_progress ( & title, Progress :: End , Some ( message) , None , None )
1063+ }
1064+ }
1065+ }
1066+ }
1067+
1068+ /// Drop any discover command processes that have exited, due to
1069+ /// finishing or erroring.
1070+ fn cleanup_discover_handles ( & mut self ) {
1071+ let mut active_handles = vec ! [ ] ;
1072+
1073+ for mut discover_handle in self . discover_handles . drain ( ..) {
1074+ if !discover_handle. handle . has_exited ( ) {
1075+ active_handles. push ( discover_handle) ;
10561076 }
10571077 }
1078+ self . discover_handles = active_handles;
10581079 }
10591080
10601081 fn handle_cargo_test_msg ( & mut self , message : CargoTestMessage ) {
0 commit comments