diff options
author | Aleksey Kladov <[email protected]> | 2019-03-20 20:52:55 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-03-20 20:52:55 +0000 |
commit | b931a472c4465e553f23c8b0e0e754b7b06169dd (patch) | |
tree | 748877a47b9a94d65d40037fbcf0d6be375569ce /crates/ra_cli | |
parent | 3eb56f7a6aab1e9814cb901c8cd90c2b4b3138af (diff) |
move extend selection from ra_ide_api_light to ra_ide_api
Diffstat (limited to 'crates/ra_cli')
-rw-r--r-- | crates/ra_cli/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 22 |
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" | |||
13 | indicatif = "0.11.0" | 13 | indicatif = "0.11.0" |
14 | 14 | ||
15 | ra_syntax = { path = "../ra_syntax" } | 15 | ra_syntax = { path = "../ra_syntax" } |
16 | ra_ide_api = { path = "../ra_ide_api" } | ||
16 | ra_ide_api_light = { path = "../ra_ide_api_light" } | 17 | ra_ide_api_light = { path = "../ra_ide_api_light" } |
17 | tools = { path = "../tools" } | 18 | tools = { path = "../tools" } |
18 | ra_batch = { path = "../ra_batch" } | 19 | ra_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 | ||
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() |