@@ -85,14 +85,14 @@ impl ClangFormatter {
8585 Some ( p)
8686 }
8787
88- fn get_command ( & self , f : & str , u : & Path ) -> Command {
88+ fn get_command ( & self , f : & str , u : & Path ) -> Option < Command > {
8989 let mut c = Command :: new ( self . path . as_str ( ) ) ;
9090 if let Some ( wd) = self . working_dir . as_ref ( ) {
9191 c. current_dir ( wd. as_str ( ) ) ;
9292 }
93- c. stdin ( File :: open ( u) . unwrap ( ) ) ;
93+ c. stdin ( File :: open ( u) . ok ( ) ? ) ;
9494 c. args ( [ "--output-replacements-xml" , format ! ( "--assume-filename={f}" ) . as_str ( ) ] ) ;
95- c
95+ Some ( c )
9696 }
9797
9898 fn output_to_textedit ( & self , output : & str , content : & str ) -> Option < Vec < TextEdit > > {
@@ -110,7 +110,8 @@ impl ClangFormatter {
110110impl ProtoFormatter for ClangFormatter {
111111 fn format_document ( & self , filename : & str , content : & str ) -> Option < Vec < TextEdit > > {
112112 let p = self . get_temp_file_path ( content) ?;
113- let output = self . get_command ( filename, p. as_ref ( ) ) . output ( ) . ok ( ) ?;
113+ let mut cmd = self . get_command ( filename, p. as_ref ( ) ) ?;
114+ let output = cmd. output ( ) . ok ( ) ?;
114115 if !output. status . success ( ) {
115116 tracing:: error!(
116117 status = output. status. code( ) ,
@@ -126,7 +127,7 @@ impl ProtoFormatter for ClangFormatter {
126127 let start = r. start . line + 1 ;
127128 let end = r. end . line + 1 ;
128129 let output = self
129- . get_command ( filename, p. as_ref ( ) )
130+ . get_command ( filename, p. as_ref ( ) ) ?
130131 . args ( [ "--lines" , format ! ( "{start}:{end}" ) . as_str ( ) ] )
131132 . output ( )
132133 . ok ( ) ?;
0 commit comments