File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -195,8 +195,11 @@ impl<T: IteratorWriter<Entry>> IteratorWriter<Entry> for UniqueOutputWriter<T> {
195195///
196196/// # Features
197197/// - Writes the entries to a file.
198+ /// - Formats the entries to the configured shape.
198199pub ( super ) struct ClangOutputWriter {
199200 output : io:: BufWriter < fs:: File > ,
201+ command_field_as_array : bool ,
202+ keep_output_field : bool ,
200203}
201204
202205impl ClangOutputWriter {
@@ -205,16 +208,33 @@ impl ClangOutputWriter {
205208 . map ( io:: BufWriter :: new)
206209 . with_context ( || format ! ( "Failed to open file: {:?}" , file_name) ) ?;
207210
208- Ok ( Self { output } )
211+ Ok ( Self {
212+ output,
213+ command_field_as_array : true ,
214+ keep_output_field : true ,
215+ } )
209216 }
210217}
211218
212219impl IteratorWriter < Entry > for ClangOutputWriter {
213220 fn write ( self , entries : impl Iterator < Item = Entry > ) -> anyhow:: Result < ( ) > {
221+ let entries = entries. map ( |entry| {
222+ let mut entry = if self . command_field_as_array {
223+ // It's safe to assume that the entry is valid, so we can unwrap.
224+ entry. as_arguments ( ) . unwrap ( )
225+ } else {
226+ entry. as_command ( )
227+ } ;
228+ if !self . keep_output_field {
229+ entry. output = None ;
230+ }
231+ entry
232+ } ) ;
214233 JsonCompilationDatabase :: write ( self . output , entries) ?;
215234 Ok ( ( ) )
216235 }
217236}
237+
218238#[ cfg( test) ]
219239mod tests {
220240 use super :: * ;
You can’t perform that action at this time.
0 commit comments