diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-01 10:30:25 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-01 10:30:25 +0100 |
commit | 42a883f06c28ddeab22e5703a578f19110dde7f3 (patch) | |
tree | fe57697b54ccfb791fe96c13cb553a8570516270 /crates/ra_cli | |
parent | dec9bde10868b5e459535449476d17a6a0987b3e (diff) | |
parent | 9e213385c9d06db3c8ca20812779e2b8f8ad2c71 (diff) |
Merge #1078
1078: rewrite syntax trees r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
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 11f5541eb..1f2750d89 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, time::Instant}; | 3 | use std::{fs, io::Read, path::Path, time::Instant}; |
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 | 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 | |||
102 | fn 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 | } | ||