aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r--xtask/src/codegen.rs34
1 files changed, 25 insertions, 9 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index f5f4b964a..98acd7fa6 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -15,7 +15,11 @@ use std::{
15 path::{Path, PathBuf}, 15 path::{Path, PathBuf},
16}; 16};
17 17
18use crate::{not_bash::fs2, project_root, Result}; 18use crate::{
19 ensure_rustfmt,
20 not_bash::{fs2, pushenv, run},
21 project_root, Result,
22};
19 23
20pub use self::{ 24pub use self::{
21 gen_assists_docs::{generate_assists_docs, generate_assists_tests}, 25 gen_assists_docs::{generate_assists_docs, generate_assists_tests},
@@ -24,16 +28,16 @@ pub use self::{
24 gen_syntax::generate_syntax, 28 gen_syntax::generate_syntax,
25}; 29};
26 30
27const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; 31const GRAMMAR_DIR: &str = "crates/parser/src/grammar";
28const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok"; 32const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok";
29const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; 33const ERR_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/err";
30 34
31const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs"; 35const SYNTAX_KINDS: &str = "crates/parser/src/syntax_kind/generated.rs";
32const AST_NODES: &str = "crates/ra_syntax/src/ast/generated/nodes.rs"; 36const AST_NODES: &str = "crates/syntax/src/ast/generated/nodes.rs";
33const AST_TOKENS: &str = "crates/ra_syntax/src/ast/generated/tokens.rs"; 37const AST_TOKENS: &str = "crates/syntax/src/ast/generated/tokens.rs";
34 38
35const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers"; 39const ASSISTS_DIR: &str = "crates/assists/src/handlers";
36const ASSISTS_TESTS: &str = "crates/ra_assists/src/tests/generated.rs"; 40const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs";
37 41
38#[derive(Debug, PartialEq, Eq, Clone, Copy)] 42#[derive(Debug, PartialEq, Eq, Clone, Copy)]
39pub enum Mode { 43pub enum Mode {
@@ -62,6 +66,18 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
62 } 66 }
63} 67}
64 68
69const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`";
70
71fn reformat(text: impl std::fmt::Display) -> Result<String> {
72 let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
73 ensure_rustfmt()?;
74 let stdout = run!(
75 "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display();
76 <text.to_string().as_bytes()
77 )?;
78 Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout))
79}
80
65fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { 81fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
66 do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect() 82 do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect()
67} 83}