@@ -85,13 +85,14 @@ impl ClangFormatter {
8585 Some ( p)
8686 }
8787
88- fn get_command ( & self , 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. args ( [ u. to_str ( ) . unwrap ( ) , "--output-replacements-xml" ] ) ;
94- c
93+ c. stdin ( File :: open ( u) . ok ( ) ?) ;
94+ c. args ( [ "--output-replacements-xml" , format ! ( "--assume-filename={f}" ) . as_str ( ) ] ) ;
95+ Some ( c)
9596 }
9697
9798 fn output_to_textedit ( & self , output : & str , content : & str ) -> Option < Vec < TextEdit > > {
@@ -107,9 +108,10 @@ impl ClangFormatter {
107108}
108109
109110impl ProtoFormatter for ClangFormatter {
110- fn format_document ( & self , content : & str ) -> Option < Vec < TextEdit > > {
111+ fn format_document ( & self , filename : & str , content : & str ) -> Option < Vec < TextEdit > > {
111112 let p = self . get_temp_file_path ( content) ?;
112- let output = self . get_command ( p. as_ref ( ) ) . output ( ) . ok ( ) ?;
113+ let mut cmd = self . get_command ( filename, p. as_ref ( ) ) ?;
114+ let output = cmd. output ( ) . ok ( ) ?;
113115 if !output. status . success ( ) {
114116 tracing:: error!(
115117 status = output. status. code( ) ,
@@ -120,12 +122,12 @@ impl ProtoFormatter for ClangFormatter {
120122 self . output_to_textedit ( & String :: from_utf8_lossy ( & output. stdout ) , content)
121123 }
122124
123- fn format_document_range ( & self , r : & Range , content : & str ) -> Option < Vec < TextEdit > > {
125+ fn format_document_range ( & self , r : & Range , filename : & str , content : & str ) -> Option < Vec < TextEdit > > {
124126 let p = self . get_temp_file_path ( content) ?;
125127 let start = r. start . line + 1 ;
126128 let end = r. end . line + 1 ;
127129 let output = self
128- . get_command ( p. as_ref ( ) )
130+ . get_command ( filename , p. as_ref ( ) ) ?
129131 . args ( [ "--lines" , format ! ( "{start}:{end}" ) . as_str ( ) ] )
130132 . output ( )
131133 . ok ( ) ?;
0 commit comments