Use correct rustfmt for codegen

closes #1569
This commit is contained in:
Aleksey Kladov 2020-01-10 11:23:11 +01:00
parent b77a7e29a5
commit fd394ff424
4 changed files with 32 additions and 35 deletions

View file

@ -9,15 +9,9 @@ mod gen_syntax;
mod gen_parser_tests;
mod gen_assists_docs;
use std::{
fs,
io::Write,
mem,
path::Path,
process::{Command, Stdio},
};
use std::{fs, mem, path::Path};
use crate::{project_root, Result};
use crate::Result;
pub use self::{
gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests,
@ -62,20 +56,6 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
}
}
fn reformat(text: impl std::fmt::Display) -> Result<String> {
let mut rustfmt = Command::new("rustfmt")
.arg("--config-path")
.arg(project_root().join("rustfmt.toml"))
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
write!(rustfmt.stdin.take().unwrap(), "{}", text)?;
let output = rustfmt.wait_with_output()?;
let stdout = String::from_utf8(output.stdout)?;
let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`";
Ok(format!("//! {}\n\n{}", preamble, stdout))
}
fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
do_extract_comment_blocks(text, false)
}