From 61f3a438d3a729a6be941bca1ff4c6a97a33f221 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 15 Oct 2018 17:44:23 -0400 Subject: Cargo Format Run `cargo fmt` and ignore generated files --- crates/tools/src/lib.rs | 12 +++++++----- crates/tools/src/main.rs | 45 +++++++++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 17 deletions(-) (limited to 'crates/tools/src') 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 @@ extern crate itertools; #[macro_use] extern crate failure; +extern crate heck; extern crate ron; extern crate tera; -extern crate heck; +use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; +use itertools::Itertools; use std::{ collections::HashMap, fs, path::{Path, PathBuf}, }; -use itertools::Itertools; -use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; pub type Result = ::std::result::Result; @@ -61,7 +61,6 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { res } - pub fn update(path: &Path, contents: &str, verify: bool) -> Result<()> { match fs::read_to_string(path) { Ok(ref old_contents) if old_contents == contents => { @@ -116,5 +115,8 @@ pub fn render_template(template: &Path) -> Result { } pub fn project_root() -> PathBuf { - Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).parent().unwrap().to_path_buf() + Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) + .parent() + .unwrap() + .to_path_buf() } 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::{ path::{Path, PathBuf}, process::Command, }; -use tools::{AST, AST_TEMPLATE, Result, SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, Test, collect_tests, render_template, update, project_root}; +use tools::{ + collect_tests, project_root, render_template, update, Result, Test, AST, AST_TEMPLATE, + SYNTAX_KINDS, SYNTAX_KINDS_TEMPLATE, +}; const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline"; @@ -40,18 +43,23 @@ fn main() -> Result<()> { fn run_gen_command(name: &str, verify: bool) -> Result<()> { match name { "gen-kinds" => { - update(&project_root().join(SYNTAX_KINDS), &render_template(&project_root().join(SYNTAX_KINDS_TEMPLATE))?, verify)?; - update(&project_root().join(AST), &render_template(&project_root().join(AST_TEMPLATE))?, verify)?; - }, - "gen-tests" => { - gen_tests(verify)? - }, + update( + &project_root().join(SYNTAX_KINDS), + &render_template(&project_root().join(SYNTAX_KINDS_TEMPLATE))?, + verify, + )?; + update( + &project_root().join(AST), + &render_template(&project_root().join(AST_TEMPLATE))?, + verify, + )?; + } + "gen-tests" => gen_tests(verify)?, _ => unreachable!(), } Ok(()) } - fn gen_tests(verify: bool) -> Result<()> { let tests = tests_from_dir(Path::new(GRAMMAR_DIR))?; @@ -133,11 +141,20 @@ fn install_code_extension() -> Result<()> { } else { run(r"npm install", "./editors/code")?; } - run(r"node ./node_modules/vsce/out/vsce package", "./editors/code")?; + run( + r"node ./node_modules/vsce/out/vsce package", + "./editors/code", + )?; if cfg!(windows) { - run(r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix", "./editors/code")?; + run( + r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix", + "./editors/code", + )?; } else { - run(r"code --install-extension ./ra-lsp-0.0.1.vsix", "./editors/code")?; + run( + r"code --install-extension ./ra-lsp-0.0.1.vsix", + "./editors/code", + )?; } Ok(()) } @@ -145,7 +162,11 @@ fn install_code_extension() -> Result<()> { fn run(cmdline: &'static str, dir: &str) -> Result<()> { eprintln!("\nwill run: {}", cmdline); let manifest_dir = env!("CARGO_MANIFEST_DIR"); - let project_dir = Path::new(manifest_dir).ancestors().nth(2).unwrap().join(dir); + let project_dir = Path::new(manifest_dir) + .ancestors() + .nth(2) + .unwrap() + .join(dir); let mut args = cmdline.split_whitespace(); let exec = args.next().unwrap(); let status = Command::new(exec) -- cgit v1.2.3