1
1
//! Benchmark operations like highlighting or goto definition.
2
2
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 } ;
10
4
11
5
use anyhow:: { format_err, Result } ;
12
6
use ra_db:: {
@@ -18,13 +12,13 @@ use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosit
18
12
use crate :: cli:: { load_cargo:: load_cargo, Verbosity } ;
19
13
20
14
pub enum BenchWhat {
21
- Highlight { path : PathBuf } ,
15
+ Highlight { path : AbsPathBuf } ,
22
16
Complete ( Position ) ,
23
17
GotoDef ( Position ) ,
24
18
}
25
19
26
20
pub struct Position {
27
- pub path : PathBuf ,
21
+ pub path : AbsPathBuf ,
28
22
pub line : u32 ,
29
23
pub column : u32 ,
30
24
}
@@ -34,7 +28,9 @@ impl FromStr for Position {
34
28
fn from_str ( s : & str ) -> Result < Self > {
35
29
let ( path_line, column) = rsplit_at_char ( s, ':' ) ?;
36
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
58
BenchWhat :: Highlight { path } => path,
63
59
BenchWhat :: Complete ( pos) | BenchWhat :: GotoDef ( pos) => & pos. path ,
64
60
} ;
65
- let path = AbsPathBuf :: try_from ( path. clone ( ) ) . unwrap ( ) ;
66
- let path = path. into ( ) ;
61
+ let path = path. clone ( ) . into ( ) ;
67
62
vfs. file_id ( & path) . ok_or_else ( || format_err ! ( "Can't find {}" , path) ) ?
68
63
} ;
69
64
@@ -139,6 +134,19 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, w
139
134
work ( & host. analysis ( ) ) ;
140
135
eprintln ! ( "{:?}" , start. elapsed( ) ) ;
141
136
}
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 ( "\n pub 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
+ }
142
150
{
143
151
let start = Instant :: now ( ) ;
144
152
eprint ! ( "const change: " ) ;
0 commit comments