diff options
Diffstat (limited to 'crates/ra_cli')
-rw-r--r-- | crates/ra_cli/src/analysis_stats.rs | 7 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 35 |
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 @@ | |||
1 | use std::collections::HashSet; | 1 | use std::{collections::HashSet, time::Instant}; |
2 | 2 | ||
3 | use ra_db::SourceDatabase; | 3 | use ra_db::SourceDatabase; |
4 | use ra_batch::BatchDatabase; | 4 | use ra_batch::BatchDatabase; |
@@ -8,8 +8,10 @@ use ra_syntax::AstNode; | |||
8 | use crate::Result; | 8 | use crate::Result; |
9 | 9 | ||
10 | pub fn run(verbose: bool) -> Result<()> { | 10 | pub 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 ecea516f1..45555be6e 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -3,10 +3,8 @@ mod analysis_stats; | |||
3 | use std::{fs, io::Read, path::Path}; | 3 | use std::{fs, io::Read, path::Path}; |
4 | 4 | ||
5 | use clap::{App, Arg, SubCommand}; | 5 | use clap::{App, Arg, SubCommand}; |
6 | use join_to_string::join; | ||
7 | use ra_ide_api::{Analysis, FileRange}; | ||
8 | use ra_ide_api::file_structure; | 6 | use ra_ide_api::file_structure; |
9 | use ra_syntax::{SourceFile, TextRange, TreeArc, AstNode}; | 7 | use ra_syntax::{SourceFile, TreeArc, AstNode}; |
10 | use tools::collect_tests; | 8 | use tools::collect_tests; |
11 | use flexi_logger::Logger; | 9 | use flexi_logger::Logger; |
12 | use ra_prof::profile; | 10 | use ra_prof::profile; |
@@ -25,11 +23,6 @@ fn main() -> Result<()> { | |||
25 | .subcommand(SubCommand::with_name("parse").arg(Arg::with_name("no-dump").long("--no-dump"))) | 23 | .subcommand(SubCommand::with_name("parse").arg(Arg::with_name("no-dump").long("--no-dump"))) |
26 | .subcommand(SubCommand::with_name("symbols")) | 24 | .subcommand(SubCommand::with_name("symbols")) |
27 | .subcommand( | 25 | .subcommand( |
28 | SubCommand::with_name("extend-selection") | ||
29 | .arg(Arg::with_name("start")) | ||
30 | .arg(Arg::with_name("end")), | ||
31 | ) | ||
32 | .subcommand( | ||
33 | SubCommand::with_name("analysis-stats").arg(Arg::with_name("verbose").short("v")), | 26 | SubCommand::with_name("analysis-stats").arg(Arg::with_name("verbose").short("v")), |
34 | ) | 27 | ) |
35 | .get_matches(); | 28 | .get_matches(); |
@@ -56,13 +49,6 @@ fn main() -> Result<()> { | |||
56 | let (test, tree) = render_test(file, line)?; | 49 | let (test, tree) = render_test(file, line)?; |
57 | println!("{}\n{}", test, tree); | 50 | println!("{}\n{}", test, tree); |
58 | } | 51 | } |
59 | ("extend-selection", Some(matches)) => { | ||
60 | let start: u32 = matches.value_of("start").unwrap().parse()?; | ||
61 | let end: u32 = matches.value_of("end").unwrap().parse()?; | ||
62 | let text = read_stdin()?; | ||
63 | let sels = selections(text, start, end); | ||
64 | println!("{}", sels) | ||
65 | } | ||
66 | ("analysis-stats", Some(matches)) => { | 52 | ("analysis-stats", Some(matches)) => { |
67 | let verbose = matches.is_present("verbose"); | 53 | let verbose = matches.is_present("verbose"); |
68 | analysis_stats::run(verbose)?; | 54 | analysis_stats::run(verbose)?; |
@@ -97,22 +83,3 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> { | |||
97 | let tree = file.syntax().debug_dump(); | 83 | let tree = file.syntax().debug_dump(); |
98 | Ok((test.text, tree)) | 84 | Ok((test.text, tree)) |
99 | } | 85 | } |
100 | |||
101 | fn selections(text: String, start: u32, end: u32) -> String { | ||
102 | let (analysis, file_id) = Analysis::from_single_file(text); | ||
103 | let mut ranges = Vec::new(); | ||
104 | let mut range = TextRange::from_to((start - 1).into(), (end - 1).into()); | ||
105 | loop { | ||
106 | ranges.push(range); | ||
107 | let next = analysis.extend_selection(FileRange { file_id, range }).unwrap(); | ||
108 | if range == next { | ||
109 | break; | ||
110 | } | ||
111 | range = next; | ||
112 | } | ||
113 | let ranges = ranges | ||
114 | .iter() | ||
115 | .map(|r| (1 + u32::from(r.start()), 1 + u32::from(r.end()))) | ||
116 | .map(|(s, e)| format!("({} {})", s, e)); | ||
117 | join(ranges).separator(" ").surround_with("(", ")").to_string() | ||
118 | } | ||