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
115use anyhow:: { format_err, Result } ;
126use ra_db:: {
@@ -18,13 +12,13 @@ use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosit
1812use crate :: cli:: { load_cargo:: load_cargo, Verbosity } ;
1913
2014pub enum BenchWhat {
21- Highlight { path : PathBuf } ,
15+ Highlight { path : AbsPathBuf } ,
2216 Complete ( Position ) ,
2317 GotoDef ( Position ) ,
2418}
2519
2620pub 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 ( "\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+ }
142150 {
143151 let start = Instant :: now ( ) ;
144152 eprint ! ( "const change: " ) ;
0 commit comments