mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-26 22:05:14 +00:00
Merge #5222
5222: Add Item change to the set of benches r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
08108d29b2
@ -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<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!(
|
||||
|
@ -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<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))?
|
||||
};
|
||||
|
||||
@ -139,6 +134,19 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, w
|
||||
work(&host.analysis());
|
||||
eprintln!("{:?}", start.elapsed());
|
||||
}
|
||||
{
|
||||
let start = Instant::now();
|
||||
eprint!("item change: ");
|
||||
{
|
||||
let mut text = host.analysis().file_text(file_id).unwrap().to_string();
|
||||
text.push_str("\npub fn _dummy() {}\n");
|
||||
let mut change = AnalysisChange::new();
|
||||
change.change_file(file_id, Some(Arc::new(text)));
|
||||
host.apply_change(change);
|
||||
}
|
||||
work(&host.analysis());
|
||||
eprintln!("{:?}", start.elapsed());
|
||||
}
|
||||
{
|
||||
let start = Instant::now();
|
||||
eprint!("const change: ");
|
||||
|
Loading…
Reference in New Issue
Block a user