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 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}