aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src/analysis_bench.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli/src/analysis_bench.rs')
-rw-r--r--crates/ra_cli/src/analysis_bench.rs53
1 files changed, 11 insertions, 42 deletions
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 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::{ 3use std::{path::Path, sync::Arc, time::Instant};
4 path::{Path, PathBuf},
5 str::FromStr,
6 sync::Arc,
7 time::Instant,
8};
9 4
10use ra_db::{ 5use ra_db::{
11 salsa::{Database, Durability}, 6 salsa::{Database, Durability},
@@ -13,35 +8,9 @@ use ra_db::{
13}; 8};
14use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; 9use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
15 10
16use crate::{load_cargo::load_cargo, Result, Verbosity}; 11use crate::{load_cargo::load_cargo, BenchWhat, Result, Verbosity};
17
18pub(crate) struct Position {
19 path: PathBuf,
20 line: u32,
21 column: u32,
22}
23
24impl FromStr for Position {
25 type Err = Box<dyn std::error::Error + Send + Sync>;
26 fn from_str(s: &str) -> Result<Self> {
27 let (path_line, column) = rsplit_at_char(s, ':')?;
28 let (path, line) = rsplit_at_char(path_line, ':')?;
29 Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? })
30 }
31}
32
33fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
34 let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?;
35 Ok((&s[..idx], &s[idx + 1..]))
36}
37
38pub(crate) enum Op {
39 Highlight { path: PathBuf },
40 Complete(Position),
41 GotoDef(Position),
42}
43 12
44pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> { 13pub(crate) fn run(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Result<()> {
45 ra_prof::init(); 14 ra_prof::init();
46 15
47 let start = Instant::now(); 16 let start = Instant::now();
@@ -51,9 +20,9 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> {
51 eprintln!("{:?}\n", start.elapsed()); 20 eprintln!("{:?}\n", start.elapsed());
52 21
53 let file_id = { 22 let file_id = {
54 let path = match &op { 23 let path = match &what {
55 Op::Highlight { path } => path, 24 BenchWhat::Highlight { path } => path,
56 Op::Complete(pos) | Op::GotoDef(pos) => &pos.path, 25 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path,
57 }; 26 };
58 let path = std::env::current_dir()?.join(path).canonicalize()?; 27 let path = std::env::current_dir()?.join(path).canonicalize()?;
59 roots 28 roots
@@ -73,8 +42,8 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> {
73 .ok_or_else(|| format!("Can't find {:?}", path))? 42 .ok_or_else(|| format!("Can't find {:?}", path))?
74 }; 43 };
75 44
76 match &op { 45 match &what {
77 Op::Highlight { .. } => { 46 BenchWhat::Highlight { .. } => {
78 let res = do_work(&mut host, file_id, |analysis| { 47 let res = do_work(&mut host, file_id, |analysis| {
79 analysis.diagnostics(file_id).unwrap(); 48 analysis.diagnostics(file_id).unwrap();
80 analysis.highlight_as_html(file_id, false).unwrap() 49 analysis.highlight_as_html(file_id, false).unwrap()
@@ -83,9 +52,9 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> {
83 println!("\n{}", res); 52 println!("\n{}", res);
84 } 53 }
85 } 54 }
86 Op::Complete(pos) | Op::GotoDef(pos) => { 55 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => {
87 let is_completion = match op { 56 let is_completion = match what {
88 Op::Complete(..) => true, 57 BenchWhat::Complete(..) => true,
89 _ => false, 58 _ => false,
90 }; 59 };
91 60