diff options
-rw-r--r-- | crates/rust-analyzer/src/bin/args.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_bench.rs | 19 |
2 files changed, 14 insertions, 15 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index 8c0f4df8b..85c2e415a 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs | |||
@@ -3,13 +3,14 @@ | |||
3 | //! If run started args, we run the LSP server loop. With a subcommand, we do a | 3 | //! If run started args, we run the LSP server loop. With a subcommand, we do a |
4 | //! one-time batch processing. | 4 | //! one-time batch processing. |
5 | 5 | ||
6 | use std::{env, fmt::Write, path::PathBuf}; | ||
7 | |||
6 | use anyhow::{bail, Result}; | 8 | use anyhow::{bail, Result}; |
7 | use pico_args::Arguments; | 9 | use pico_args::Arguments; |
10 | use ra_db::AbsPathBuf; | ||
8 | use ra_ssr::{SsrPattern, SsrRule}; | 11 | use ra_ssr::{SsrPattern, SsrRule}; |
9 | use rust_analyzer::cli::{BenchWhat, Position, Verbosity}; | 12 | use rust_analyzer::cli::{BenchWhat, Position, Verbosity}; |
10 | 13 | ||
11 | use std::{fmt::Write, path::PathBuf}; | ||
12 | |||
13 | pub(crate) struct Args { | 14 | pub(crate) struct Args { |
14 | pub(crate) verbosity: Verbosity, | 15 | pub(crate) verbosity: Verbosity, |
15 | pub(crate) command: Command, | 16 | pub(crate) command: Command, |
@@ -240,7 +241,10 @@ ARGS: | |||
240 | let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; | 241 | let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; |
241 | let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; | 242 | let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; |
242 | let what = match (highlight_path, complete_path, goto_def_path) { | 243 | let what = match (highlight_path, complete_path, goto_def_path) { |
243 | (Some(path), None, None) => BenchWhat::Highlight { path: path.into() }, | 244 | (Some(path), None, None) => { |
245 | let path = env::current_dir().unwrap().join(path); | ||
246 | BenchWhat::Highlight { path: AbsPathBuf::assert(path) } | ||
247 | } | ||
244 | (None, Some(position), None) => BenchWhat::Complete(position), | 248 | (None, Some(position), None) => BenchWhat::Complete(position), |
245 | (None, None, Some(position)) => BenchWhat::GotoDef(position), | 249 | (None, None, Some(position)) => BenchWhat::GotoDef(position), |
246 | _ => panic!( | 250 | _ => panic!( |
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 930375d3e..3730d346c 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs | |||
@@ -1,12 +1,6 @@ | |||
1 | //! Benchmark operations like highlighting or goto definition. | 1 | //! Benchmark operations like highlighting or goto definition. |
2 | 2 | ||
3 | use std::{ | 3 | use std::{env, path::Path, str::FromStr, sync::Arc, time::Instant}; |
4 | convert::TryFrom, | ||
5 | path::{Path, PathBuf}, | ||
6 | str::FromStr, | ||
7 | sync::Arc, | ||
8 | time::Instant, | ||
9 | }; | ||
10 | 4 | ||
11 | use anyhow::{format_err, Result}; | 5 | use anyhow::{format_err, Result}; |
12 | use ra_db::{ | 6 | use ra_db::{ |
@@ -18,13 +12,13 @@ use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosit | |||
18 | use crate::cli::{load_cargo::load_cargo, Verbosity}; | 12 | use crate::cli::{load_cargo::load_cargo, Verbosity}; |
19 | 13 | ||
20 | pub enum BenchWhat { | 14 | pub enum BenchWhat { |
21 | Highlight { path: PathBuf }, | 15 | Highlight { path: AbsPathBuf }, |
22 | Complete(Position), | 16 | Complete(Position), |
23 | GotoDef(Position), | 17 | GotoDef(Position), |
24 | } | 18 | } |
25 | 19 | ||
26 | pub struct Position { | 20 | pub struct Position { |
27 | pub path: PathBuf, | 21 | pub path: AbsPathBuf, |
28 | pub line: u32, | 22 | pub line: u32, |
29 | pub column: u32, | 23 | pub column: u32, |
30 | } | 24 | } |
@@ -34,7 +28,9 @@ impl FromStr for Position { | |||
34 | fn from_str(s: &str) -> Result<Self> { | 28 | fn from_str(s: &str) -> Result<Self> { |
35 | let (path_line, column) = rsplit_at_char(s, ':')?; | 29 | let (path_line, column) = rsplit_at_char(s, ':')?; |
36 | let (path, line) = rsplit_at_char(path_line, ':')?; | 30 | let (path, line) = rsplit_at_char(path_line, ':')?; |
37 | Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) | 31 | let path = env::current_dir().unwrap().join(path); |
32 | let path = AbsPathBuf::assert(path); | ||
33 | Ok(Position { path, line: line.parse()?, column: column.parse()? }) | ||
38 | } | 34 | } |
39 | } | 35 | } |
40 | 36 | ||
@@ -62,8 +58,7 @@ pub fn analysis_bench( | |||
62 | BenchWhat::Highlight { path } => path, | 58 | BenchWhat::Highlight { path } => path, |
63 | BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path, | 59 | BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path, |
64 | }; | 60 | }; |
65 | let path = AbsPathBuf::try_from(path.clone()).unwrap(); | 61 | let path = path.clone().into(); |
66 | let path = path.into(); | ||
67 | vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))? | 62 | vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))? |
68 | }; | 63 | }; |
69 | 64 | ||