Fix bench to work with relative paths

This commit is contained in:
Aleksey Kladov 2020-07-04 17:03:02 +02:00
parent 1d3a3c0782
commit 000d1db351
2 changed files with 14 additions and 15 deletions

View File

@ -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 @@ pub(crate) fn parse() -> Result<Result<Args, HelpPrinted>> {
let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?;
let goto_def_path: Option<Position> = 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!(

View File

@ -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 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<Self> {
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))?
};