aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli/src/main.rs')
-rw-r--r--crates/ra_cli/src/main.rs35
1 files changed, 1 insertions, 34 deletions
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;
3use std::{fs, io::Read, path::Path}; 3use std::{fs, io::Read, path::Path};
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;
12use ra_prof::profile; 10use 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
101fn 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}