From b931a472c4465e553f23c8b0e0e754b7b06169dd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Mar 2019 23:52:55 +0300 Subject: move extend selection from ra_ide_api_light to ra_ide_api --- crates/ra_cli/Cargo.toml | 1 + crates/ra_cli/src/main.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'crates/ra_cli') 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" indicatif = "0.11.0" ra_syntax = { path = "../ra_syntax" } +ra_ide_api = { path = "../ra_ide_api" } ra_ide_api_light = { path = "../ra_ide_api_light" } tools = { path = "../tools" } 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}; use clap::{App, Arg, SubCommand}; use join_to_string::join; -use ra_ide_api_light::{extend_selection, file_structure}; +use ra_ide_api::{Analysis, FileRange}; +use ra_ide_api_light::file_structure; use ra_syntax::{SourceFile, TextRange, TreeArc, AstNode}; use tools::collect_tests; use flexi_logger::Logger; @@ -59,8 +60,8 @@ fn main() -> Result<()> { ("extend-selection", Some(matches)) => { let start: u32 = matches.value_of("start").unwrap().parse()?; let end: u32 = matches.value_of("end").unwrap().parse()?; - let file = file()?; - let sels = selections(&file, start, end); + let text = read_stdin()?; + let sels = selections(text, start, end); println!("{}", sels) } ("analysis-stats", Some(matches)) => { @@ -98,12 +99,17 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> { Ok((test.text, tree)) } -fn selections(file: &SourceFile, start: u32, end: u32) -> String { +fn selections(text: String, start: u32, end: u32) -> String { + let (analysis, file_id) = Analysis::from_single_file(text); let mut ranges = Vec::new(); - let mut cur = Some(TextRange::from_to((start - 1).into(), (end - 1).into())); - while let Some(r) = cur { - ranges.push(r); - cur = extend_selection(file.syntax(), r); + let mut range = TextRange::from_to((start - 1).into(), (end - 1).into()); + loop { + ranges.push(range); + let next = analysis.extend_selection(FileRange { file_id, range }).unwrap(); + if range == next { + break; + } + range = next; } let ranges = ranges .iter() -- cgit v1.2.3