mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-02 09:46:06 +00:00
pipe debug output through rustfmt
is there a nicer way to do this?!
This commit is contained in:
parent
04e041b4a2
commit
4f74037f41
1 changed files with 18 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
|
@ -16,7 +18,22 @@ pub(crate) fn debug_enabled(input_name: impl ToString) -> bool {
|
||||||
|
|
||||||
pub(crate) fn dump_tokens(input_name: impl ToString, tokens: TokenStream) -> TokenStream {
|
pub(crate) fn dump_tokens(input_name: impl ToString, tokens: TokenStream) -> TokenStream {
|
||||||
if debug_enabled(input_name) {
|
if debug_enabled(input_name) {
|
||||||
eprintln!("{}", tokens);
|
let token_string = tokens.to_string();
|
||||||
|
|
||||||
|
let _: Result<(), ()> = Command::new("rustfmt")
|
||||||
|
.arg("--emit=stdout")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.and_then(|mut rustfmt| {
|
||||||
|
rustfmt
|
||||||
|
.stdin
|
||||||
|
.take()
|
||||||
|
.unwrap()
|
||||||
|
.write_all(token_string.as_bytes())?;
|
||||||
|
rustfmt.wait_with_output()
|
||||||
|
})
|
||||||
|
.and_then(|output| Ok(eprintln!("{}", String::from_utf8_lossy(&output.stdout))))
|
||||||
|
.or_else(|_| Ok(eprintln!("{token_string}")));
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens
|
tokens
|
||||||
|
|
Loading…
Reference in a new issue