aboutsummaryrefslogtreecommitdiff
path: root/crates/tools
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-15 22:44:23 +0100
committerJeremy A. Kolb <[email protected]>2018-10-16 14:41:10 +0100
commit61f3a438d3a729a6be941bca1ff4c6a97a33f221 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/tools
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
Cargo Format
Run `cargo fmt` and ignore generated files
Diffstat (limited to 'crates/tools')
-rw-r--r--crates/tools/src/lib.rs12
-rw-r--r--crates/tools/src/main.rs45
-rw-r--r--crates/tools/tests/cli.rs16
3 files changed, 53 insertions, 20 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 @@
1extern crate itertools; 1extern crate itertools;
2#[macro_use] 2#[macro_use]
3extern crate failure; 3extern crate failure;
4extern crate heck;
4extern crate ron; 5extern crate ron;
5extern crate tera; 6extern crate tera;
6extern crate heck;
7 7
8use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
9use itertools::Itertools;
8use std::{ 10use std::{
9 collections::HashMap, 11 collections::HashMap,
10 fs, 12 fs,
11 path::{Path, PathBuf}, 13 path::{Path, PathBuf},
12}; 14};
13use itertools::Itertools;
14use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
15 15
16pub type Result<T> = ::std::result::Result<T, failure::Error>; 16pub 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
65pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> { 64pub 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
118pub fn project_root() -> PathBuf { 117pub 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};
14use tools::{AST, AST_TEMPLATE, Result, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, Test, collect_tests, render_template, update, project_root}; 14use tools::{
15 collect_tests, project_root, render_template, update, Result, Test, AST, AST_TEMPLATE,
16 SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE,
17};
15 18
16const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; 19const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
17const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline"; 20const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline";
@@ -40,18 +43,23 @@ fn main() -> Result<()> {
40fn run_gen_command(name: &str, verify: bool) -> Result<()> { 43fn 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
55fn gen_tests(verify: bool) -> Result<()> { 63fn 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<()> {
145fn run(cmdline: &'static str, dir: &str) -> Result<()> { 162fn 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)
diff --git a/crates/tools/tests/cli.rs b/crates/tools/tests/cli.rs
index f507d80a2..16899bb5f 100644
--- a/crates/tools/tests/cli.rs
+++ b/crates/tools/tests/cli.rs
@@ -1,13 +1,23 @@
1extern crate tools; 1extern crate tools;
2 2
3use tools::{AST, AST_TEMPLATE, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, render_template, update, project_root}; 3use tools::{
4 project_root, render_template, update, AST, AST_TEMPLATE, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE,
5};
4 6
5#[test] 7#[test]
6fn verify_template_generation() { 8fn verify_template_generation() {
7 if let Err(error) = update(&project_root().join(SYNTAX_KINDS), &render_template(&project_root().join(SYNTAX_KINDS_TEMPLATE)).unwrap(), true) { 9 if let Err(error) = update(
10 &project_root().join(SYNTAX_KINDS),
11 &render_template(&project_root().join(SYNTAX_KINDS_TEMPLATE)).unwrap(),
12 true,
13 ) {
8 panic!("{}. Please update it by running `cargo gen-kinds`", error); 14 panic!("{}. Please update it by running `cargo gen-kinds`", error);
9 } 15 }
10 if let Err(error) = update(&project_root().join(AST), &render_template(&project_root().join(AST_TEMPLATE)).unwrap(), true) { 16 if let Err(error) = update(
17 &project_root().join(AST),
18 &render_template(&project_root().join(AST_TEMPLATE)).unwrap(),
19 true,
20 ) {
11 panic!("{}. Please update it by running `cargo gen-kinds`", error); 21 panic!("{}. Please update it by running `cargo gen-kinds`", error);
12 } 22 }
13} 23}