From 000d1db35131238190f3d62e7b100d71e31eb24c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 4 Jul 2020 17:03:02 +0200 Subject: Fix bench to work with relative paths --- crates/rust-analyzer/src/bin/args.rs | 10 +++++++--- 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 @@ //! If run started args, we run the LSP server loop. With a subcommand, we do a //! one-time batch processing. +use std::{env, fmt::Write, path::PathBuf}; + use anyhow::{bail, Result}; use pico_args::Arguments; +use ra_db::AbsPathBuf; use ra_ssr::{SsrPattern, SsrRule}; use rust_analyzer::cli::{BenchWhat, Position, Verbosity}; -use std::{fmt::Write, path::PathBuf}; - pub(crate) struct Args { pub(crate) verbosity: Verbosity, pub(crate) command: Command, @@ -240,7 +241,10 @@ ARGS: let complete_path: Option = matches.opt_value_from_str("--complete")?; let goto_def_path: Option = matches.opt_value_from_str("--goto-def")?; let what = match (highlight_path, complete_path, goto_def_path) { - (Some(path), None, None) => BenchWhat::Highlight { path: path.into() }, + (Some(path), None, None) => { + let path = env::current_dir().unwrap().join(path); + BenchWhat::Highlight { path: AbsPathBuf::assert(path) } + } (None, Some(position), None) => BenchWhat::Complete(position), (None, None, Some(position)) => BenchWhat::GotoDef(position), _ => 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 @@ //! Benchmark operations like highlighting or goto definition. -use std::{ - convert::TryFrom, - path::{Path, PathBuf}, - str::FromStr, - sync::Arc, - time::Instant, -}; +use std::{env, path::Path, str::FromStr, sync::Arc, time::Instant}; use anyhow::{format_err, Result}; use ra_db::{ @@ -18,13 +12,13 @@ use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosit use crate::cli::{load_cargo::load_cargo, Verbosity}; pub enum BenchWhat { - Highlight { path: PathBuf }, + Highlight { path: AbsPathBuf }, Complete(Position), GotoDef(Position), } pub struct Position { - pub path: PathBuf, + pub path: AbsPathBuf, pub line: u32, pub column: u32, } @@ -34,7 +28,9 @@ impl FromStr for Position { 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()? }) + let path = env::current_dir().unwrap().join(path); + let path = AbsPathBuf::assert(path); + Ok(Position { path, line: line.parse()?, column: column.parse()? }) } } @@ -62,8 +58,7 @@ pub fn analysis_bench( BenchWhat::Highlight { path } => path, BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path, }; - let path = AbsPathBuf::try_from(path.clone()).unwrap(); - let path = path.into(); + let path = path.clone().into(); vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))? }; -- cgit v1.2.3