55#![ warn( rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros) ]
66
77use std:: {
8+ ffi:: OsString ,
89 fmt, io,
10+ path:: PathBuf ,
911 process:: { ChildStderr , ChildStdout , Command , Stdio } ,
1012 time:: Duration ,
1113} ;
@@ -221,21 +223,19 @@ impl FlycheckActor {
221223 }
222224
223225 let command = self . check_command ( ) ;
226+ let formatted_command = format ! ( "{:?}" , command) ;
227+
224228 tracing:: debug!( ?command, "will restart flycheck" ) ;
225229 match CommandHandle :: spawn ( command) {
226230 Ok ( command_handle) => {
227- tracing:: debug!(
228- command = ?self . check_command( ) ,
229- "did restart flycheck"
230- ) ;
231+ tracing:: debug!( command = formatted_command, "did restart flycheck" ) ;
231232 self . command_handle = Some ( command_handle) ;
232233 self . report_progress ( Progress :: DidStart ) ;
233234 }
234235 Err ( error) => {
235236 self . report_progress ( Progress :: DidFailToRestart ( format ! (
236- "Failed to run the following command: {:?} error={}" ,
237- self . check_command( ) ,
238- error
237+ "Failed to run the following command: {} error={}" ,
238+ formatted_command, error
239239 ) ) ) ;
240240 }
241241 }
@@ -245,11 +245,13 @@ impl FlycheckActor {
245245
246246 // Watcher finished
247247 let command_handle = self . command_handle . take ( ) . unwrap ( ) ;
248+ let formatted_handle = format ! ( "{:?}" , command_handle) ;
249+
248250 let res = command_handle. join ( ) ;
249251 if res. is_err ( ) {
250252 tracing:: error!(
251- "Flycheck failed to run the following command: {:? }" ,
252- self . check_command ( )
253+ "Flycheck failed to run the following command: {}" ,
254+ formatted_handle
253255 ) ;
254256 }
255257 self . report_progress ( Progress :: DidFinish ( res) ) ;
@@ -286,7 +288,7 @@ impl FlycheckActor {
286288 fn cancel_check_process ( & mut self ) {
287289 if let Some ( command_handle) = self . command_handle . take ( ) {
288290 tracing:: debug!(
289- command = ?self . check_command ( ) ,
291+ command = ?command_handle ,
290292 "did cancel flycheck"
291293 ) ;
292294 command_handle. cancel ( ) ;
@@ -397,13 +399,30 @@ struct CommandHandle {
397399 child : JodGroupChild ,
398400 thread : stdx:: thread:: JoinHandle < io:: Result < ( bool , String ) > > ,
399401 receiver : Receiver < CargoMessage > ,
402+ program : OsString ,
403+ arguments : Vec < OsString > ,
404+ current_dir : Option < PathBuf > ,
405+ }
406+
407+ impl fmt:: Debug for CommandHandle {
408+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
409+ f. debug_struct ( "CommandHandle" )
410+ . field ( "program" , & self . program )
411+ . field ( "arguments" , & self . arguments )
412+ . field ( "current_dir" , & self . current_dir )
413+ . finish ( )
414+ }
400415}
401416
402417impl CommandHandle {
403418 fn spawn ( mut command : Command ) -> std:: io:: Result < CommandHandle > {
404419 command. stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: piped ( ) ) . stdin ( Stdio :: null ( ) ) ;
405420 let mut child = command. group_spawn ( ) . map ( JodGroupChild ) ?;
406421
422+ let program = command. get_program ( ) . into ( ) ;
423+ let arguments = command. get_args ( ) . map ( |arg| arg. into ( ) ) . collect :: < Vec < OsString > > ( ) ;
424+ let current_dir = command. get_current_dir ( ) . map ( |arg| arg. to_path_buf ( ) ) ;
425+
407426 let stdout = child. 0 . inner ( ) . stdout . take ( ) . unwrap ( ) ;
408427 let stderr = child. 0 . inner ( ) . stderr . take ( ) . unwrap ( ) ;
409428
@@ -413,7 +432,7 @@ impl CommandHandle {
413432 . name ( "CargoHandle" . to_owned ( ) )
414433 . spawn ( move || actor. run ( ) )
415434 . expect ( "failed to spawn thread" ) ;
416- Ok ( CommandHandle { child, thread, receiver } )
435+ Ok ( CommandHandle { program , arguments , current_dir , child, thread, receiver } )
417436 }
418437
419438 fn cancel ( mut self ) {
0 commit comments