Skip to content

Commit 08108d2

Browse files
bors[bot]matklad
andauthored
Merge #5222
5222: Add Item change to the set of benches r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 1d3a3c0 + 3902e55 commit 08108d2

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

crates/rust-analyzer/src/bin/args.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
//! If run started args, we run the LSP server loop. With a subcommand, we do a
44
//! one-time batch processing.
55
6+
use std::{env, fmt::Write, path::PathBuf};
7+
68
use anyhow::{bail, Result};
79
use pico_args::Arguments;
10+
use ra_db::AbsPathBuf;
811
use ra_ssr::{SsrPattern, SsrRule};
912
use rust_analyzer::cli::{BenchWhat, Position, Verbosity};
1013

11-
use std::{fmt::Write, path::PathBuf};
12-
1314
pub(crate) struct Args {
1415
pub(crate) verbosity: Verbosity,
1516
pub(crate) command: Command,
@@ -240,7 +241,10 @@ ARGS:
240241
let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?;
241242
let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?;
242243
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+
}
244248
(None, Some(position), None) => BenchWhat::Complete(position),
245249
(None, None, Some(position)) => BenchWhat::GotoDef(position),
246250
_ => panic!(

crates/rust-analyzer/src/cli/analysis_bench.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
//! Benchmark operations like highlighting or goto definition.
22
3-
use std::{
4-
convert::TryFrom,
5-
path::{Path, PathBuf},
6-
str::FromStr,
7-
sync::Arc,
8-
time::Instant,
9-
};
3+
use std::{env, path::Path, str::FromStr, sync::Arc, time::Instant};
104

115
use anyhow::{format_err, Result};
126
use ra_db::{
@@ -18,13 +12,13 @@ use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosit
1812
use crate::cli::{load_cargo::load_cargo, Verbosity};
1913

2014
pub enum BenchWhat {
21-
Highlight { path: PathBuf },
15+
Highlight { path: AbsPathBuf },
2216
Complete(Position),
2317
GotoDef(Position),
2418
}
2519

2620
pub struct Position {
27-
pub path: PathBuf,
21+
pub path: AbsPathBuf,
2822
pub line: u32,
2923
pub column: u32,
3024
}
@@ -34,7 +28,9 @@ impl FromStr for Position {
3428
fn from_str(s: &str) -> Result<Self> {
3529
let (path_line, column) = rsplit_at_char(s, ':')?;
3630
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()? })
3834
}
3935
}
4036

@@ -62,8 +58,7 @@ pub fn analysis_bench(
6258
BenchWhat::Highlight { path } => path,
6359
BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path,
6460
};
65-
let path = AbsPathBuf::try_from(path.clone()).unwrap();
66-
let path = path.into();
61+
let path = path.clone().into();
6762
vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))?
6863
};
6964

@@ -139,6 +134,19 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, w
139134
work(&host.analysis());
140135
eprintln!("{:?}", start.elapsed());
141136
}
137+
{
138+
let start = Instant::now();
139+
eprint!("item change: ");
140+
{
141+
let mut text = host.analysis().file_text(file_id).unwrap().to_string();
142+
text.push_str("\npub fn _dummy() {}\n");
143+
let mut change = AnalysisChange::new();
144+
change.change_file(file_id, Some(Arc::new(text)));
145+
host.apply_change(change);
146+
}
147+
work(&host.analysis());
148+
eprintln!("{:?}", start.elapsed());
149+
}
142150
{
143151
let start = Instant::now();
144152
eprint!("const change: ");

0 commit comments

Comments
 (0)