diff --git a/Cargo.lock b/Cargo.lock index 3a4929a0f4..4ae611a6bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -917,21 +917,6 @@ dependencies = [ "test_utils", ] -[[package]] -name = "ra_batch" -version = "0.1.0" -dependencies = [ - "crossbeam-channel", - "log", - "ra_db", - "ra_hir", - "ra_ide", - "ra_project_model", - "ra_vfs", - "ra_vfs_glob", - "rustc-hash", -] - [[package]] name = "ra_cargo_watch" version = "0.1.0" @@ -960,18 +945,23 @@ dependencies = [ name = "ra_cli" version = "0.1.0" dependencies = [ + "crossbeam-channel", "env_logger", "itertools", + "log", "pico-args", - "ra_batch", "ra_db", "ra_hir", "ra_hir_def", "ra_hir_ty", "ra_ide", "ra_prof", + "ra_project_model", "ra_syntax", + "ra_vfs", + "ra_vfs_glob", "rand", + "rustc-hash", ] [[package]] diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml deleted file mode 100644 index 3bf351fe37..0000000000 --- a/crates/ra_batch/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -edition = "2018" -name = "ra_batch" -version = "0.1.0" -authors = ["rust-analyzer developers"] - -[lib] -doctest = false - -[dependencies] -log = "0.4.5" -rustc-hash = "1.0" -crossbeam-channel = "0.4.0" - -ra_vfs = "0.5.0" -ra_vfs_glob = { path = "../ra_vfs_glob" } -ra_db = { path = "../ra_db" } -ra_ide = { path = "../ra_ide" } -ra_hir = { path = "../ra_hir" } -ra_project_model = { path = "../ra_project_model" } diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml index 53d4876f64..03494a809f 100644 --- a/crates/ra_cli/Cargo.toml +++ b/crates/ra_cli/Cargo.toml @@ -6,18 +6,23 @@ authors = ["rust-analyzer developers"] publish = false [dependencies] -itertools = "0.8.0" -pico-args = "0.3.0" +crossbeam-channel = "0.4.0" env_logger = { version = "0.7.1", default-features = false } +itertools = "0.8.0" +log = "0.4.5" +pico-args = "0.3.0" rand = { version = "0.7.0", features = ["small_rng"] } +rustc-hash = "1.0" -ra_syntax = { path = "../ra_syntax" } -ra_ide = { path = "../ra_ide" } -ra_batch = { path = "../ra_batch" } hir = { path = "../ra_hir", package = "ra_hir" } -hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } +hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } ra_db = { path = "../ra_db" } +ra_ide = { path = "../ra_ide" } +ra_project_model = { path = "../ra_project_model" } +ra_syntax = { path = "../ra_syntax" } +ra_vfs = "0.5.0" +ra_vfs_glob = { path = "../ra_vfs_glob" } [dependencies.ra_prof] path = "../ra_prof" diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs index 4835a68ce9..3f10ed4002 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_cli/src/analysis_bench.rs @@ -13,7 +13,7 @@ use ra_db::{ }; use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; -use crate::Result; +use crate::{load_cargo::load_cargo, Result}; pub(crate) struct Position { path: PathBuf, @@ -46,7 +46,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { let start = Instant::now(); eprint!("loading: "); - let (mut host, roots) = ra_batch::load_cargo(path)?; + let (mut host, roots) = load_cargo(path)?; let db = host.raw_database(); eprintln!("{:?}\n", start.elapsed()); diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 6d2dd34c64..d40f043919 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -2,19 +2,18 @@ use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; -use itertools::Itertools; -use rand::{seq::SliceRandom, thread_rng}; - use hir::{ db::{DefDatabase, HirDatabase}, AssocItem, Crate, HasSource, HirDisplay, ModuleDef, }; use hir_def::FunctionId; use hir_ty::{Ty, TypeWalk}; +use itertools::Itertools; use ra_db::SourceDatabaseExt; use ra_syntax::AstNode; +use rand::{seq::SliceRandom, thread_rng}; -use crate::{progress_report::ProgressReport, Result, Verbosity}; +use crate::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; pub fn run( verbosity: Verbosity, @@ -25,7 +24,7 @@ pub fn run( randomize: bool, ) -> Result<()> { let db_load_time = Instant::now(); - let (mut host, roots) = ra_batch::load_cargo(path)?; + let (mut host, roots) = load_cargo(path)?; let db = host.raw_database(); println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); let analysis_time = Instant::now(); diff --git a/crates/ra_cli/src/help.rs b/crates/ra_cli/src/help.rs deleted file mode 100644 index d3c4c7d0bb..0000000000 --- a/crates/ra_cli/src/help.rs +++ /dev/null @@ -1,75 +0,0 @@ -//! FIXME: write short doc here - -pub const GLOBAL_HELP: &str = "ra-cli - -USAGE: - ra_cli - -FLAGS: - -h, --help Prints help information - -SUBCOMMANDS: - analysis-bench - analysis-stats - highlight - parse - symbols"; - -pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench - -USAGE: - ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] - -FLAGS: - -h, --help Prints help information - -v, --verbose - -OPTIONS: - --complete Compute completions at this location - --highlight Hightlight this file - -ARGS: - Project to analyse"; - -pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats - -USAGE: - ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] - -FLAGS: - -h, --help Prints help information - --memory-usage - -v, --verbose - -q, --quiet - -OPTIONS: - -o - -ARGS: - "; - -pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight - -USAGE: - ra_cli highlight [FLAGS] - -FLAGS: - -h, --help Prints help information - -r, --rainbow"; - -pub const SYMBOLS_HELP: &str = "ra-cli-symbols - -USAGE: - ra_cli highlight [FLAGS] - -FLAGS: - -h, --help Prints help inforamtion"; - -pub const PARSE_HELP: &str = "ra-cli-parse - -USAGE: - ra_cli parse [FLAGS] - -FLAGS: - -h, --help Prints help inforamtion - --no-dump"; diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_cli/src/load_cargo.rs similarity index 99% rename from crates/ra_batch/src/lib.rs rename to crates/ra_cli/src/load_cargo.rs index 7744ba85a2..2d6433f184 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_cli/src/load_cargo.rs @@ -139,7 +139,8 @@ pub fn load( #[cfg(test)] mod tests { use super::*; - use ra_hir::Crate; + + use hir::Crate; #[test] fn test_loading_rust_analyzer() { diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 750cbab866..4a428faff8 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -1,8 +1,8 @@ //! FIXME: write short doc here +mod load_cargo; mod analysis_stats; mod analysis_bench; -mod help; mod progress_report; use std::{error::Error, fmt::Write, io::Read}; @@ -40,21 +40,26 @@ impl Verbosity { fn main() -> Result<()> { env_logger::try_init()?; - let subcommand = match std::env::args_os().nth(1) { - None => { - eprintln!("{}", help::GLOBAL_HELP); - return Ok(()); - } - Some(s) => s, - }; - let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect()); + let mut matches = Arguments::from_env(); + let subcommand = matches.subcommand()?.unwrap_or_default(); - match &*subcommand.to_string_lossy() { + match subcommand.as_str() { "parse" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::PARSE_HELP); + eprintln!( + "\ +ra-cli-parse + +USAGE: + ra_cli parse [FLAGS] + +FLAGS: + -h, --help Prints help inforamtion + --no-dump" + ); return Ok(()); } + let no_dump = matches.contains("--no-dump"); matches.finish().or_else(handle_extra_flags)?; @@ -67,10 +72,21 @@ fn main() -> Result<()> { } "symbols" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::SYMBOLS_HELP); + eprintln!( + "\ +ra-cli-symbols + +USAGE: + ra_cli highlight [FLAGS] + +FLAGS: + -h, --help Prints help inforamtion" + ); return Ok(()); } + matches.finish().or_else(handle_extra_flags)?; + let file = file()?; for s in file_structure(&file) { println!("{:?}", s); @@ -78,20 +94,51 @@ fn main() -> Result<()> { } "highlight" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::HIGHLIGHT_HELP); + eprintln!( + "\ +ra-cli-highlight + +USAGE: + ra_cli highlight [FLAGS] + +FLAGS: + -h, --help Prints help information + -r, --rainbow" + ); return Ok(()); } + let rainbow_opt = matches.contains(["-r", "--rainbow"]); matches.finish().or_else(handle_extra_flags)?; + let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap(); println!("{}", html); } "analysis-stats" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::ANALYSIS_STATS_HELP); + eprintln!( + "\ +ra-cli-analysis-stats + +USAGE: + ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] + +FLAGS: + -h, --help Prints help information + --memory-usage + -v, --verbose + -q, --quiet + +OPTIONS: + -o + +ARGS: + " + ); return Ok(()); } + let verbosity = match ( matches.contains(["-vv", "--spammy"]), matches.contains(["-v", "--verbose"]), @@ -111,11 +158,11 @@ fn main() -> Result<()> { let path = { let mut trailing = matches.free()?; if trailing.len() != 1 { - eprintln!("{}", help::ANALYSIS_STATS_HELP); Err("Invalid flags")?; } trailing.pop().unwrap() }; + analysis_stats::run( verbosity, memory_usage, @@ -127,9 +174,27 @@ fn main() -> Result<()> { } "analysis-bench" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::ANALYSIS_BENCH_HELP); + eprintln!( + "\ +ra_cli-analysis-bench + +USAGE: + ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] + +FLAGS: + -h, --help Prints help information + -v, --verbose + +OPTIONS: + --complete Compute completions at this location + --highlight Hightlight this file + +ARGS: + Project to analyse" + ); return Ok(()); } + let verbose = matches.contains(["-v", "--verbose"]); let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); let highlight_path: Option = matches.opt_value_from_str("--highlight")?; @@ -144,9 +209,26 @@ fn main() -> Result<()> { ), }; matches.finish().or_else(handle_extra_flags)?; + analysis_bench::run(verbose, path.as_ref(), op)?; } - _ => eprintln!("{}", help::GLOBAL_HELP), + _ => eprintln!( + "\ +ra-cli + +USAGE: + ra_cli + +FLAGS: + -h, --help Prints help information + +SUBCOMMANDS: + analysis-bench + analysis-stats + highlight + parse + symbols" + ), } Ok(()) } diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs index 7ae73b9344..a8ed9793f2 100644 --- a/xtask/tests/tidy-tests/docs.rs +++ b/xtask/tests/tidy-tests/docs.rs @@ -73,7 +73,6 @@ fn no_docs_comments() { } let whitelist = [ - "ra_batch", "ra_cli", "ra_db", "ra_hir",