diff options
author | Seivan Heidari <[email protected]> | 2019-10-31 08:43:20 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-10-31 08:43:20 +0000 |
commit | 8edda0e7b164009d6c03bb3d4be603fb38ad2e2a (patch) | |
tree | 744cf81075d394e2f9c06afb07642a2601800dda /xtask/src/codegen/gen_syntax.rs | |
parent | 49562d36b97ddde34cf7585a8c2e8f232519b657 (diff) | |
parent | d067afb064a7fa67b172abf561b7d80740cd6f18 (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'xtask/src/codegen/gen_syntax.rs')
-rw-r--r-- | xtask/src/codegen/gen_syntax.rs | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 6a81c0e4d..88f2ac0e3 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs | |||
@@ -3,12 +3,7 @@ | |||
3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype | 3 | //! Specifically, it generates the `SyntaxKind` enum and a number of newtype |
4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. | 4 | //! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. |
5 | 5 | ||
6 | use std::{ | 6 | use std::{collections::BTreeMap, fs}; |
7 | collections::BTreeMap, | ||
8 | fs, | ||
9 | io::Write, | ||
10 | process::{Command, Stdio}, | ||
11 | }; | ||
12 | 7 | ||
13 | use proc_macro2::{Punct, Spacing}; | 8 | use proc_macro2::{Punct, Spacing}; |
14 | use quote::{format_ident, quote}; | 9 | use quote::{format_ident, quote}; |
@@ -163,7 +158,7 @@ fn generate_ast(grammar: &Grammar) -> Result<String> { | |||
163 | #(#nodes)* | 158 | #(#nodes)* |
164 | }; | 159 | }; |
165 | 160 | ||
166 | let pretty = reformat(ast)?; | 161 | let pretty = codegen::reformat(ast)?; |
167 | Ok(pretty) | 162 | Ok(pretty) |
168 | } | 163 | } |
169 | 164 | ||
@@ -276,21 +271,7 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> { | |||
276 | } | 271 | } |
277 | }; | 272 | }; |
278 | 273 | ||
279 | reformat(ast) | 274 | codegen::reformat(ast) |
280 | } | ||
281 | |||
282 | fn reformat(text: impl std::fmt::Display) -> Result<String> { | ||
283 | let mut rustfmt = Command::new("rustfmt") | ||
284 | .arg("--config-path") | ||
285 | .arg(project_root().join("rustfmt.toml")) | ||
286 | .stdin(Stdio::piped()) | ||
287 | .stdout(Stdio::piped()) | ||
288 | .spawn()?; | ||
289 | write!(rustfmt.stdin.take().unwrap(), "{}", text)?; | ||
290 | let output = rustfmt.wait_with_output()?; | ||
291 | let stdout = String::from_utf8(output.stdout)?; | ||
292 | let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`"; | ||
293 | Ok(format!("//! {}\n\n{}", preamble, stdout)) | ||
294 | } | 275 | } |
295 | 276 | ||
296 | #[derive(Deserialize, Debug)] | 277 | #[derive(Deserialize, Debug)] |