aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli/src')
-rw-r--r--crates/ra_cli/src/analysis_stats.rs11
-rw-r--r--crates/ra_cli/src/main.rs40
2 files changed, 16 insertions, 35 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index 4516ed660..e6b2b30c6 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -7,9 +7,9 @@ use ra_syntax::AstNode;
7 7
8use crate::Result; 8use crate::Result;
9 9
10pub fn run(verbose: bool) -> Result<()> { 10pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> {
11 let db_load_time = Instant::now(); 11 let db_load_time = Instant::now();
12 let (db, roots) = BatchDatabase::load_cargo(".")?; 12 let (db, roots) = BatchDatabase::load_cargo(path)?;
13 println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); 13 println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
14 let analysis_time = Instant::now(); 14 let analysis_time = Instant::now();
15 let mut num_crates = 0; 15 let mut num_crates = 0;
@@ -57,14 +57,19 @@ pub fn run(verbose: bool) -> Result<()> {
57 let mut num_exprs_unknown = 0; 57 let mut num_exprs_unknown = 0;
58 let mut num_exprs_partially_unknown = 0; 58 let mut num_exprs_partially_unknown = 0;
59 for f in funcs { 59 for f in funcs {
60 let name = f.name(&db);
60 if verbose { 61 if verbose {
61 let (file_id, source) = f.source(&db); 62 let (file_id, source) = f.source(&db);
62 let original_file = file_id.original_file(&db); 63 let original_file = file_id.original_file(&db);
63 let path = db.file_relative_path(original_file); 64 let path = db.file_relative_path(original_file);
64 let syntax_range = source.syntax().range(); 65 let syntax_range = source.syntax().range();
65 let name = f.name(&db);
66 println!("{} ({:?} {})", name, path, syntax_range); 66 println!("{} ({:?} {})", name, path, syntax_range);
67 } 67 }
68 if let Some(only_name) = only {
69 if name.to_string() != only_name {
70 continue;
71 }
72 }
68 let body = f.body(&db); 73 let body = f.body(&db);
69 let inference_result = f.infer(&db); 74 let inference_result = f.infer(&db);
70 for (expr_id, _) in body.exprs() { 75 for (expr_id, _) in body.exprs() {
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 45555be6e..038f5f3fe 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -1,11 +1,10 @@
1mod analysis_stats; 1mod analysis_stats;
2 2
3use std::{fs, io::Read, path::Path}; 3use std::io::Read;
4 4
5use clap::{App, Arg, SubCommand}; 5use clap::{App, Arg, SubCommand};
6use ra_ide_api::file_structure; 6use ra_ide_api::file_structure;
7use ra_syntax::{SourceFile, TreeArc, AstNode}; 7use ra_syntax::{SourceFile, TreeArc, AstNode};
8use tools::collect_tests;
9use flexi_logger::Logger; 8use flexi_logger::Logger;
10use ra_prof::profile; 9use ra_prof::profile;
11 10
@@ -15,15 +14,13 @@ fn main() -> Result<()> {
15 Logger::with_env().start()?; 14 Logger::with_env().start()?;
16 let matches = App::new("ra-cli") 15 let matches = App::new("ra-cli")
17 .setting(clap::AppSettings::SubcommandRequiredElseHelp) 16 .setting(clap::AppSettings::SubcommandRequiredElseHelp)
18 .subcommand(
19 SubCommand::with_name("render-test")
20 .arg(Arg::with_name("line").long("--line").required(true).takes_value(true))
21 .arg(Arg::with_name("file").long("--file").required(true).takes_value(true)),
22 )
23 .subcommand(SubCommand::with_name("parse").arg(Arg::with_name("no-dump").long("--no-dump"))) 17 .subcommand(SubCommand::with_name("parse").arg(Arg::with_name("no-dump").long("--no-dump")))
24 .subcommand(SubCommand::with_name("symbols")) 18 .subcommand(SubCommand::with_name("symbols"))
25 .subcommand( 19 .subcommand(
26 SubCommand::with_name("analysis-stats").arg(Arg::with_name("verbose").short("v")), 20 SubCommand::with_name("analysis-stats")
21 .arg(Arg::with_name("verbose").short("v"))
22 .arg(Arg::with_name("only").short("o").takes_value(true))
23 .arg(Arg::with_name("path")),
27 ) 24 )
28 .get_matches(); 25 .get_matches();
29 match matches.subcommand() { 26 match matches.subcommand() {
@@ -41,17 +38,11 @@ fn main() -> Result<()> {
41 println!("{:?}", s); 38 println!("{:?}", s);
42 } 39 }
43 } 40 }
44 ("render-test", Some(matches)) => {
45 let file = matches.value_of("file").unwrap();
46 let file = Path::new(file);
47 let line: usize = matches.value_of("line").unwrap().parse()?;
48 let line = line - 1;
49 let (test, tree) = render_test(file, line)?;
50 println!("{}\n{}", test, tree);
51 }
52 ("analysis-stats", Some(matches)) => { 41 ("analysis-stats", Some(matches)) => {
53 let verbose = matches.is_present("verbose"); 42 let verbose = matches.is_present("verbose");
54 analysis_stats::run(verbose)?; 43 let path = matches.value_of("path").unwrap_or("");
44 let only = matches.value_of("only");
45 analysis_stats::run(verbose, path, only)?;
55 } 46 }
56 _ => unreachable!(), 47 _ => unreachable!(),
57 } 48 }
@@ -68,18 +59,3 @@ fn read_stdin() -> Result<String> {
68 ::std::io::stdin().read_to_string(&mut buff)?; 59 ::std::io::stdin().read_to_string(&mut buff)?;
69 Ok(buff) 60 Ok(buff)
70} 61}
71
72fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
73 let text = fs::read_to_string(file)?;
74 let tests = collect_tests(&text);
75 let test = tests.into_iter().find(|(start_line, t)| {
76 *start_line <= line && line <= *start_line + t.text.lines().count()
77 });
78 let test = match test {
79 None => failure::bail!("No test found at line {} at {}", line, file.display()),
80 Some((_start_line, test)) => test,
81 };
82 let file = SourceFile::parse(&test.text);
83 let tree = file.syntax().debug_dump();
84 Ok((test.text, tree))
85}