aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli')
-rw-r--r--crates/ra_cli/Cargo.toml1
-rw-r--r--crates/ra_cli/src/main.rs22
2 files changed, 15 insertions, 8 deletions
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml
index ff30bf0b3..4c666f556 100644
--- a/crates/ra_cli/Cargo.toml
+++ b/crates/ra_cli/Cargo.toml
@@ -13,6 +13,7 @@ flexi_logger = "0.11.0"
13indicatif = "0.11.0" 13indicatif = "0.11.0"
14 14
15ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
16ra_ide_api = { path = "../ra_ide_api" }
16ra_ide_api_light = { path = "../ra_ide_api_light" } 17ra_ide_api_light = { path = "../ra_ide_api_light" }
17tools = { path = "../tools" } 18tools = { path = "../tools" }
18ra_batch = { path = "../ra_batch" } 19ra_batch = { path = "../ra_batch" }
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 294f4b8af..5285f1f28 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -4,7 +4,8 @@ use 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; 6use join_to_string::join;
7use ra_ide_api_light::{extend_selection, file_structure}; 7use ra_ide_api::{Analysis, FileRange};
8use ra_ide_api_light::file_structure;
8use ra_syntax::{SourceFile, TextRange, TreeArc, AstNode}; 9use ra_syntax::{SourceFile, TextRange, TreeArc, AstNode};
9use tools::collect_tests; 10use tools::collect_tests;
10use flexi_logger::Logger; 11use flexi_logger::Logger;
@@ -59,8 +60,8 @@ fn main() -> Result<()> {
59 ("extend-selection", Some(matches)) => { 60 ("extend-selection", Some(matches)) => {
60 let start: u32 = matches.value_of("start").unwrap().parse()?; 61 let start: u32 = matches.value_of("start").unwrap().parse()?;
61 let end: u32 = matches.value_of("end").unwrap().parse()?; 62 let end: u32 = matches.value_of("end").unwrap().parse()?;
62 let file = file()?; 63 let text = read_stdin()?;
63 let sels = selections(&file, start, end); 64 let sels = selections(text, start, end);
64 println!("{}", sels) 65 println!("{}", sels)
65 } 66 }
66 ("analysis-stats", Some(matches)) => { 67 ("analysis-stats", Some(matches)) => {
@@ -98,12 +99,17 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
98 Ok((test.text, tree)) 99 Ok((test.text, tree))
99} 100}
100 101
101fn selections(file: &SourceFile, start: u32, end: u32) -> String { 102fn selections(text: String, start: u32, end: u32) -> String {
103 let (analysis, file_id) = Analysis::from_single_file(text);
102 let mut ranges = Vec::new(); 104 let mut ranges = Vec::new();
103 let mut cur = Some(TextRange::from_to((start - 1).into(), (end - 1).into())); 105 let mut range = TextRange::from_to((start - 1).into(), (end - 1).into());
104 while let Some(r) = cur { 106 loop {
105 ranges.push(r); 107 ranges.push(range);
106 cur = extend_selection(file.syntax(), r); 108 let next = analysis.extend_selection(FileRange { file_id, range }).unwrap();
109 if range == next {
110 break;
111 }
112 range = next;
107 } 113 }
108 let ranges = ranges 114 let ranges = ranges
109 .iter() 115 .iter()