diff options
-rw-r--r-- | crates/ra_cli/src/analysis_bench.rs | 53 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 88 |
2 files changed, 68 insertions, 73 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 | ||
3 | use std::{ | 3 | use std::{path::Path, sync::Arc, time::Instant}; |
4 | path::{Path, PathBuf}, | ||
5 | str::FromStr, | ||
6 | sync::Arc, | ||
7 | time::Instant, | ||
8 | }; | ||
9 | 4 | ||
10 | use ra_db::{ | 5 | use ra_db::{ |
11 | salsa::{Database, Durability}, | 6 | salsa::{Database, Durability}, |
@@ -13,35 +8,9 @@ use ra_db::{ | |||
13 | }; | 8 | }; |
14 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; | 9 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; |
15 | 10 | ||
16 | use crate::{load_cargo::load_cargo, Result, Verbosity}; | 11 | use crate::{load_cargo::load_cargo, BenchWhat, Result, Verbosity}; |
17 | |||
18 | pub(crate) struct Position { | ||
19 | path: PathBuf, | ||
20 | line: u32, | ||
21 | column: u32, | ||
22 | } | ||
23 | |||
24 | impl 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 | |||
33 | fn 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 | |||
38 | pub(crate) enum Op { | ||
39 | Highlight { path: PathBuf }, | ||
40 | Complete(Position), | ||
41 | GotoDef(Position), | ||
42 | } | ||
43 | 12 | ||
44 | pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> { | 13 | pub(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 | ||
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index f4eb0bd3c..66258c860 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -5,7 +5,7 @@ mod analysis_stats; | |||
5 | mod analysis_bench; | 5 | mod analysis_bench; |
6 | mod progress_report; | 6 | mod progress_report; |
7 | 7 | ||
8 | use std::{error::Error, fmt::Write, io::Read, path::PathBuf}; | 8 | use std::{error::Error, fmt::Write, io::Read, path::PathBuf, str::FromStr}; |
9 | 9 | ||
10 | use pico_args::Arguments; | 10 | use pico_args::Arguments; |
11 | use ra_ide::{file_structure, Analysis}; | 11 | use ra_ide::{file_structure, Analysis}; |
@@ -51,14 +51,37 @@ fn main() -> Result<()> { | |||
51 | randomize, | 51 | randomize, |
52 | )?; | 52 | )?; |
53 | } | 53 | } |
54 | Command::Bench { verbosity, path, op } => { | 54 | Command::Bench { verbosity, path, what } => { |
55 | analysis_bench::run(verbosity, path.as_ref(), op)?; | 55 | analysis_bench::run(verbosity, path.as_ref(), what)?; |
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | Ok(()) | 59 | Ok(()) |
60 | } | 60 | } |
61 | 61 | ||
62 | enum Command { | ||
63 | Parse { | ||
64 | no_dump: bool, | ||
65 | }, | ||
66 | Symbols, | ||
67 | Highlight { | ||
68 | rainbow: bool, | ||
69 | }, | ||
70 | Stats { | ||
71 | verbosity: Verbosity, | ||
72 | randomize: bool, | ||
73 | memory_usage: bool, | ||
74 | only: Option<String>, | ||
75 | with_deps: bool, | ||
76 | path: PathBuf, | ||
77 | }, | ||
78 | Bench { | ||
79 | verbosity: Verbosity, | ||
80 | path: PathBuf, | ||
81 | what: BenchWhat, | ||
82 | }, | ||
83 | } | ||
84 | |||
62 | #[derive(Clone, Copy)] | 85 | #[derive(Clone, Copy)] |
63 | pub enum Verbosity { | 86 | pub enum Verbosity { |
64 | Spammy, | 87 | Spammy, |
@@ -82,27 +105,30 @@ impl Verbosity { | |||
82 | } | 105 | } |
83 | } | 106 | } |
84 | 107 | ||
85 | enum Command { | 108 | enum BenchWhat { |
86 | Parse { | 109 | Highlight { path: PathBuf }, |
87 | no_dump: bool, | 110 | Complete(Position), |
88 | }, | 111 | GotoDef(Position), |
89 | Symbols, | 112 | } |
90 | Highlight { | 113 | |
91 | rainbow: bool, | 114 | pub(crate) struct Position { |
92 | }, | 115 | path: PathBuf, |
93 | Stats { | 116 | line: u32, |
94 | verbosity: Verbosity, | 117 | column: u32, |
95 | randomize: bool, | 118 | } |
96 | memory_usage: bool, | 119 | |
97 | only: Option<String>, | 120 | impl FromStr for Position { |
98 | with_deps: bool, | 121 | type Err = Box<dyn std::error::Error + Send + Sync>; |
99 | path: PathBuf, | 122 | fn from_str(s: &str) -> Result<Self> { |
100 | }, | 123 | let (path_line, column) = rsplit_at_char(s, ':')?; |
101 | Bench { | 124 | let (path, line) = rsplit_at_char(path_line, ':')?; |
102 | verbosity: Verbosity, | 125 | Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) |
103 | path: PathBuf, | 126 | } |
104 | op: analysis_bench::Op, | 127 | } |
105 | }, | 128 | |
129 | fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { | ||
130 | let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?; | ||
131 | Ok((&s[..idx], &s[idx + 1..])) | ||
106 | } | 132 | } |
107 | 133 | ||
108 | struct HelpPrinted; | 134 | struct HelpPrinted; |
@@ -248,17 +274,17 @@ ARGS: | |||
248 | 274 | ||
249 | let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); | 275 | let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); |
250 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; | 276 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; |
251 | let complete_path: Option<String> = matches.opt_value_from_str("--complete")?; | 277 | let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; |
252 | let goto_def_path: Option<String> = matches.opt_value_from_str("--goto-def")?; | 278 | let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; |
253 | let op = match (highlight_path, complete_path, goto_def_path) { | 279 | let what = match (highlight_path, complete_path, goto_def_path) { |
254 | (Some(path), None, None) => analysis_bench::Op::Highlight { path: path.into() }, | 280 | (Some(path), None, None) => BenchWhat::Highlight { path: path.into() }, |
255 | (None, Some(position), None) => analysis_bench::Op::Complete(position.parse()?), | 281 | (None, Some(position), None) => BenchWhat::Complete(position), |
256 | (None, None, Some(position)) => analysis_bench::Op::GotoDef(position.parse()?), | 282 | (None, None, Some(position)) => BenchWhat::GotoDef(position), |
257 | _ => panic!( | 283 | _ => panic!( |
258 | "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" | 284 | "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" |
259 | ), | 285 | ), |
260 | }; | 286 | }; |
261 | Command::Bench { verbosity, path, op } | 287 | Command::Bench { verbosity, path, what } |
262 | } | 288 | } |
263 | _ => { | 289 | _ => { |
264 | eprintln!( | 290 | eprintln!( |