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.rs7
-rw-r--r--crates/ra_cli/src/main.rs35
2 files changed, 6 insertions, 36 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index ee410c548..4516ed660 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -1,4 +1,4 @@
1use std::collections::HashSet; 1use std::{collections::HashSet, time::Instant};
2 2
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_batch::BatchDatabase; 4use ra_batch::BatchDatabase;
@@ -8,8 +8,10 @@ use ra_syntax::AstNode;
8use crate::Result; 8use crate::Result;
9 9
10pub fn run(verbose: bool) -> Result<()> { 10pub fn run(verbose: bool) -> Result<()> {
11 let db_load_time = Instant::now();
11 let (db, roots) = BatchDatabase::load_cargo(".")?; 12 let (db, roots) = BatchDatabase::load_cargo(".")?;
12 println!("Database loaded, {} roots", roots.len()); 13 println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed());
14 let analysis_time = Instant::now();
13 let mut num_crates = 0; 15 let mut num_crates = 0;
14 let mut visited_modules = HashSet::new(); 16 let mut visited_modules = HashSet::new();
15 let mut visit_queue = Vec::new(); 17 let mut visit_queue = Vec::new();
@@ -96,5 +98,6 @@ pub fn run(verbose: bool) -> Result<()> {
96 num_exprs_partially_unknown, 98 num_exprs_partially_unknown,
97 (num_exprs_partially_unknown * 100 / num_exprs) 99 (num_exprs_partially_unknown * 100 / num_exprs)
98 ); 100 );
101 println!("Analysis: {:?}", analysis_time.elapsed());
99 Ok(()) 102 Ok(())
100} 103}
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 11f5541eb..1f2750d89 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -3,10 +3,8 @@ mod analysis_stats;
3use std::{fs, io::Read, path::Path, time::Instant}; 3use std::{fs, io::Read, path::Path, time::Instant};
4 4
5use clap::{App, Arg, SubCommand}; 5use clap::{App, Arg, SubCommand};
6use join_to_string::join;
7use ra_ide_api::{Analysis, FileRange};
8use ra_ide_api::file_structure; 6use ra_ide_api::file_structure;
9use ra_syntax::{SourceFile, TextRange, TreeArc, AstNode}; 7use ra_syntax::{SourceFile, TreeArc, AstNode};
10use tools::collect_tests; 8use tools::collect_tests;
11use flexi_logger::Logger; 9use flexi_logger::Logger;
12 10
@@ -24,11 +22,6 @@ fn main() -> Result<()> {
24 .subcommand(SubCommand::with_name("parse").arg(Arg::with_name("no-dump").long("--no-dump"))) 22 .subcommand(SubCommand::with_name("parse").arg(Arg::with_name("no-dump").long("--no-dump")))
25 .subcommand(SubCommand::with_name("symbols")) 23 .subcommand(SubCommand::with_name("symbols"))
26 .subcommand( 24 .subcommand(
27 SubCommand::with_name("extend-selection")
28 .arg(Arg::with_name("start"))
29 .arg(Arg::with_name("end")),
30 )
31 .subcommand(
32 SubCommand::with_name("analysis-stats").arg(Arg::with_name("verbose").short("v")), 25 SubCommand::with_name("analysis-stats").arg(Arg::with_name("verbose").short("v")),
33 ) 26 )
34 .get_matches(); 27 .get_matches();
@@ -57,13 +50,6 @@ fn main() -> Result<()> {
57 let (test, tree) = render_test(file, line)?; 50 let (test, tree) = render_test(file, line)?;
58 println!("{}\n{}", test, tree); 51 println!("{}\n{}", test, tree);
59 } 52 }
60 ("extend-selection", Some(matches)) => {
61 let start: u32 = matches.value_of("start").unwrap().parse()?;
62 let end: u32 = matches.value_of("end").unwrap().parse()?;
63 let text = read_stdin()?;
64 let sels = selections(text, start, end);
65 println!("{}", sels)
66 }
67 ("analysis-stats", Some(matches)) => { 53 ("analysis-stats", Some(matches)) => {
68 let verbose = matches.is_present("verbose"); 54 let verbose = matches.is_present("verbose");
69 analysis_stats::run(verbose)?; 55 analysis_stats::run(verbose)?;
@@ -98,22 +84,3 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
98 let tree = file.syntax().debug_dump(); 84 let tree = file.syntax().debug_dump();
99 Ok((test.text, tree)) 85 Ok((test.text, tree))
100} 86}
101
102fn selections(text: String, start: u32, end: u32) -> String {
103 let (analysis, file_id) = Analysis::from_single_file(text);
104 let mut ranges = Vec::new();
105 let mut range = TextRange::from_to((start - 1).into(), (end - 1).into());
106 loop {
107 ranges.push(range);
108 let next = analysis.extend_selection(FileRange { file_id, range }).unwrap();
109 if range == next {
110 break;
111 }
112 range = next;
113 }
114 let ranges = ranges
115 .iter()
116 .map(|r| (1 + u32::from(r.start()), 1 + u32::from(r.end())))
117 .map(|(s, e)| format!("({} {})", s, e));
118 join(ranges).separator(" ").surround_with("(", ")").to_string()
119}