diff options
author | Jeremy A. Kolb <[email protected]> | 2018-10-15 22:44:23 +0100 |
---|---|---|
committer | Jeremy A. Kolb <[email protected]> | 2018-10-16 14:41:10 +0100 |
commit | 61f3a438d3a729a6be941bca1ff4c6a97a33f221 (patch) | |
tree | 6551967cc8c6e921b66071453ad7888a9121d326 /crates/tools/src | |
parent | 39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff) |
Cargo Format
Run `cargo fmt` and ignore generated files
Diffstat (limited to 'crates/tools/src')
-rw-r--r-- | crates/tools/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 45 |
2 files changed, 40 insertions, 17 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 9a1b12a16..5d5d372bb 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -1,17 +1,17 @@ | |||
1 | extern crate itertools; | 1 | extern crate itertools; |
2 | #[macro_use] | 2 | #[macro_use] |
3 | extern crate failure; | 3 | extern crate failure; |
4 | extern crate heck; | ||
4 | extern crate ron; | 5 | extern crate ron; |
5 | extern crate tera; | 6 | extern crate tera; |
6 | extern crate heck; | ||
7 | 7 | ||
8 | use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; | ||
9 | use itertools::Itertools; | ||
8 | use std::{ | 10 | use std::{ |
9 | collections::HashMap, | 11 | collections::HashMap, |
10 | fs, | 12 | fs, |
11 | path::{Path, PathBuf}, | 13 | path::{Path, PathBuf}, |
12 | }; | 14 | }; |
13 | use itertools::Itertools; | ||
14 | use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; | ||
15 | 15 | ||
16 | pub type Result<T> = ::std::result::Result<T, failure::Error>; | 16 | pub type Result<T> = ::std::result::Result<T, failure::Error>; |
17 | 17 | ||
@@ -61,7 +61,6 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { | |||
61 | res | 61 | res |
62 | } | 62 | } |
63 | 63 | ||
64 | |||
65 | pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> { | 64 | pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> { |
66 | match fs::read_to_string(path) { | 65 | match fs::read_to_string(path) { |
67 | Ok(ref old_contents) if old_contents == contents => { | 66 | Ok(ref old_contents) if old_contents == contents => { |
@@ -116,5 +115,8 @@ pub fn render_template(template: &Path) -> Result<String> { | |||
116 | } | 115 | } |
117 | 116 | ||
118 | pub fn project_root() -> PathBuf { | 117 | pub fn project_root() -> PathBuf { |
119 | Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).parent().unwrap().to_path_buf() | 118 | Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) |
119 | .parent() | ||
120 | .unwrap() | ||
121 | .to_path_buf() | ||
120 | } | 122 | } |
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 6eacfc190..b662d78df 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -11,7 +11,10 @@ use std::{ | |||
11 | path::{Path, PathBuf}, | 11 | path::{Path, PathBuf}, |
12 | process::Command, | 12 | process::Command, |
13 | }; | 13 | }; |
14 | use tools::{AST, AST_TEMPLATE, Result, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, Test, collect_tests, render_template, update, project_root}; | 14 | use tools::{ |
15 | collect_tests, project_root, render_template, update, Result, Test, AST, AST_TEMPLATE, | ||
16 | SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, | ||
17 | }; | ||
15 | 18 | ||
16 | const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; | 19 | const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; |
17 | const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline"; | 20 | const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline"; |
@@ -40,18 +43,23 @@ fn main() -> Result<()> { | |||
40 | fn run_gen_command(name: &str, verify: bool) -> Result<()> { | 43 | fn run_gen_command(name: &str, verify: bool) -> Result<()> { |
41 | match name { | 44 | match name { |
42 | "gen-kinds" => { | 45 | "gen-kinds" => { |
43 | update(&project_root().join(SYNTAX_KINDS), &render_template(&project_root().join(SYNTAX_KINDS_TEMPLATE))?, verify)?; | 46 | update( |
44 | update(&project_root().join(AST), &render_template(&project_root().join(AST_TEMPLATE))?, verify)?; | 47 | &project_root().join(SYNTAX_KINDS), |
45 | }, | 48 | &render_template(&project_root().join(SYNTAX_KINDS_TEMPLATE))?, |
46 | "gen-tests" => { | 49 | verify, |
47 | gen_tests(verify)? | 50 | )?; |
48 | }, | 51 | update( |
52 | &project_root().join(AST), | ||
53 | &render_template(&project_root().join(AST_TEMPLATE))?, | ||
54 | verify, | ||
55 | )?; | ||
56 | } | ||
57 | "gen-tests" => gen_tests(verify)?, | ||
49 | _ => unreachable!(), | 58 | _ => unreachable!(), |
50 | } | 59 | } |
51 | Ok(()) | 60 | Ok(()) |
52 | } | 61 | } |
53 | 62 | ||
54 | |||
55 | fn gen_tests(verify: bool) -> Result<()> { | 63 | fn gen_tests(verify: bool) -> Result<()> { |
56 | let tests = tests_from_dir(Path::new(GRAMMAR_DIR))?; | 64 | let tests = tests_from_dir(Path::new(GRAMMAR_DIR))?; |
57 | 65 | ||
@@ -133,11 +141,20 @@ fn install_code_extension() -> Result<()> { | |||
133 | } else { | 141 | } else { |
134 | run(r"npm install", "./editors/code")?; | 142 | run(r"npm install", "./editors/code")?; |
135 | } | 143 | } |
136 | run(r"node ./node_modules/vsce/out/vsce package", "./editors/code")?; | 144 | run( |
145 | r"node ./node_modules/vsce/out/vsce package", | ||
146 | "./editors/code", | ||
147 | )?; | ||
137 | if cfg!(windows) { | 148 | if cfg!(windows) { |
138 | run(r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix", "./editors/code")?; | 149 | run( |
150 | r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix", | ||
151 | "./editors/code", | ||
152 | )?; | ||
139 | } else { | 153 | } else { |
140 | run(r"code --install-extension ./ra-lsp-0.0.1.vsix", "./editors/code")?; | 154 | run( |
155 | r"code --install-extension ./ra-lsp-0.0.1.vsix", | ||
156 | "./editors/code", | ||
157 | )?; | ||
141 | } | 158 | } |
142 | Ok(()) | 159 | Ok(()) |
143 | } | 160 | } |
@@ -145,7 +162,11 @@ fn install_code_extension() -> Result<()> { | |||
145 | fn run(cmdline: &'static str, dir: &str) -> Result<()> { | 162 | fn run(cmdline: &'static str, dir: &str) -> Result<()> { |
146 | eprintln!("\nwill run: {}", cmdline); | 163 | eprintln!("\nwill run: {}", cmdline); |
147 | let manifest_dir = env!("CARGO_MANIFEST_DIR"); | 164 | let manifest_dir = env!("CARGO_MANIFEST_DIR"); |
148 | let project_dir = Path::new(manifest_dir).ancestors().nth(2).unwrap().join(dir); | 165 | let project_dir = Path::new(manifest_dir) |
166 | .ancestors() | ||
167 | .nth(2) | ||
168 | .unwrap() | ||
169 | .join(dir); | ||
149 | let mut args = cmdline.split_whitespace(); | 170 | let mut args = cmdline.split_whitespace(); |
150 | let exec = args.next().unwrap(); | 171 | let exec = args.next().unwrap(); |
151 | let status = Command::new(exec) | 172 | let status = Command::new(exec) |