diff options
Diffstat (limited to 'crates/ra_cli/src/main.rs')
-rw-r--r-- | crates/ra_cli/src/main.rs | 22 |
1 files changed, 14 insertions, 8 deletions
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 | ||
5 | use clap::{App, Arg, SubCommand}; | 5 | use clap::{App, Arg, SubCommand}; |
6 | use join_to_string::join; | 6 | use join_to_string::join; |
7 | use ra_ide_api_light::{extend_selection, file_structure}; | 7 | use ra_ide_api::{Analysis, FileRange}; |
8 | use ra_ide_api_light::file_structure; | ||
8 | use ra_syntax::{SourceFile, TextRange, TreeArc, AstNode}; | 9 | use ra_syntax::{SourceFile, TextRange, TreeArc, AstNode}; |
9 | use tools::collect_tests; | 10 | use tools::collect_tests; |
10 | use flexi_logger::Logger; | 11 | use 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 | ||
101 | fn selections(file: &SourceFile, start: u32, end: u32) -> String { | 102 | fn 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() |