From 8e86d12771c0d77dce82cf80671d4cf9383057c9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 18:15:19 +0100 Subject: Cleanup --- crates/ra_cli/src/analysis_bench.rs | 53 ++++++++----------------------------- 1 file changed, 11 insertions(+), 42 deletions(-) (limited to 'crates/ra_cli/src/analysis_bench.rs') diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs index 83f95555f..3dc8dc691 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_cli/src/analysis_bench.rs @@ -1,11 +1,6 @@ //! FIXME: write short doc here -use std::{ - path::{Path, PathBuf}, - str::FromStr, - sync::Arc, - time::Instant, -}; +use std::{path::Path, sync::Arc, time::Instant}; use ra_db::{ salsa::{Database, Durability}, @@ -13,35 +8,9 @@ use ra_db::{ }; use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; -use crate::{load_cargo::load_cargo, Result, Verbosity}; - -pub(crate) struct Position { - path: PathBuf, - line: u32, - column: u32, -} - -impl FromStr for Position { - type Err = Box; - fn from_str(s: &str) -> Result { - let (path_line, column) = rsplit_at_char(s, ':')?; - let (path, line) = rsplit_at_char(path_line, ':')?; - Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) - } -} - -fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { - let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?; - Ok((&s[..idx], &s[idx + 1..])) -} - -pub(crate) enum Op { - Highlight { path: PathBuf }, - Complete(Position), - GotoDef(Position), -} +use crate::{load_cargo::load_cargo, BenchWhat, Result, Verbosity}; -pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> { +pub(crate) fn run(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Result<()> { ra_prof::init(); let start = Instant::now(); @@ -51,9 +20,9 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> { eprintln!("{:?}\n", start.elapsed()); let file_id = { - let path = match &op { - Op::Highlight { path } => path, - Op::Complete(pos) | Op::GotoDef(pos) => &pos.path, + let path = match &what { + BenchWhat::Highlight { path } => path, + BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path, }; let path = std::env::current_dir()?.join(path).canonicalize()?; roots @@ -73,8 +42,8 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> { .ok_or_else(|| format!("Can't find {:?}", path))? }; - match &op { - Op::Highlight { .. } => { + match &what { + BenchWhat::Highlight { .. } => { let res = do_work(&mut host, file_id, |analysis| { analysis.diagnostics(file_id).unwrap(); analysis.highlight_as_html(file_id, false).unwrap() @@ -83,9 +52,9 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> { println!("\n{}", res); } } - Op::Complete(pos) | Op::GotoDef(pos) => { - let is_completion = match op { - Op::Complete(..) => true, + BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => { + let is_completion = match what { + BenchWhat::Complete(..) => true, _ => false, }; -- cgit v1.2.3