aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen.rs
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-18 13:37:22 +0100
committerDmitry <[email protected]>2020-08-18 13:37:22 +0100
commite18748ed152989953e39492a6b44f8001267ce5f (patch)
tree300dc7ce2998d9521319ff76f4df6ec2d165d0a1 /xtask/src/codegen.rs
parent73315c9168901ef6d676f017daaa9b4976380c03 (diff)
parentb8dfc331abbfce6aad0c248c91c57bd9890a668f (diff)
Merge remote-tracking branch 'rust-analyzer/master'
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r--xtask/src/codegen.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 4b2b614fa..c468468de 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -16,7 +16,11 @@ use std::{
16 path::{Path, PathBuf}, 16 path::{Path, PathBuf},
17}; 17};
18 18
19use crate::{not_bash::fs2, project_root, Result}; 19use crate::{
20 ensure_rustfmt,
21 not_bash::{fs2, pushenv, run},
22 project_root, Result,
23};
20 24
21pub use self::{ 25pub use self::{
22 gen_assists_docs::{generate_assists_docs, generate_assists_tests}, 26 gen_assists_docs::{generate_assists_docs, generate_assists_tests},
@@ -71,6 +75,18 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
71 } 75 }
72} 76}
73 77
78const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`";
79
80fn reformat(text: impl std::fmt::Display) -> Result<String> {
81 let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
82 ensure_rustfmt()?;
83 let stdout = run!(
84 "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display();
85 <text.to_string().as_bytes()
86 )?;
87 Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout))
88}
89
74fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { 90fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
75 do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect() 91 do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect()
76} 92}