1
1
use std:: {
2
2
path:: { PathBuf , Path } ,
3
3
time:: Instant ,
4
+ sync:: Arc ,
4
5
} ;
5
6
6
- use ra_db:: { SourceDatabase , salsa:: { Database , Durability } } ;
7
- use ra_ide_api:: { AnalysisHost , Analysis , LineCol , FilePosition } ;
7
+ use ra_db:: { SourceDatabase , FileId , salsa:: { Database , Durability } } ;
8
+ use ra_ide_api:: { AnalysisHost , Analysis , LineCol , FilePosition , AnalysisChange } ;
8
9
9
10
use crate :: Result ;
10
11
@@ -16,7 +17,7 @@ pub(crate) enum Op {
16
17
pub ( crate ) fn run ( verbose : bool , path : & Path , op : Op ) -> Result < ( ) > {
17
18
let start = Instant :: now ( ) ;
18
19
eprint ! ( "loading: " ) ;
19
- let ( host, roots) = ra_batch:: load_cargo ( path) ?;
20
+ let ( mut host, roots) = ra_batch:: load_cargo ( path) ?;
20
21
let db = host. raw_database ( ) ;
21
22
eprintln ! ( "{:?}\n " , start. elapsed( ) ) ;
22
23
@@ -44,7 +45,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
44
45
45
46
match op {
46
47
Op :: Highlight { .. } => {
47
- let res = do_work ( & host, |analysis| {
48
+ let res = do_work ( & mut host, file_id , |analysis| {
48
49
analysis. diagnostics ( file_id) . unwrap ( ) ;
49
50
analysis. highlight_as_html ( file_id, false ) . unwrap ( )
50
51
} ) ;
@@ -59,7 +60,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
59
60
. offset ( LineCol { line, col_utf16 : column } ) ;
60
61
let file_postion = FilePosition { file_id, offset } ;
61
62
62
- let res = do_work ( & host, |analysis| analysis. completions ( file_postion) ) ;
63
+ let res = do_work ( & mut host, file_id , |analysis| analysis. completions ( file_postion) ) ;
63
64
if verbose {
64
65
println ! ( "\n {:#?}" , res) ;
65
66
}
@@ -68,7 +69,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
68
69
Ok ( ( ) )
69
70
}
70
71
71
- fn do_work < F : Fn ( & Analysis ) -> T , T > ( host : & AnalysisHost , work : F ) -> T {
72
+ fn do_work < F : Fn ( & Analysis ) -> T , T > ( host : & mut AnalysisHost , file_id : FileId , work : F ) -> T {
72
73
{
73
74
let start = Instant :: now ( ) ;
74
75
eprint ! ( "from scratch: " ) ;
@@ -88,6 +89,19 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T {
88
89
work ( & host. analysis ( ) ) ;
89
90
eprintln ! ( "{:?}" , start. elapsed( ) ) ;
90
91
}
92
+ {
93
+ let start = Instant :: now ( ) ;
94
+ eprint ! ( "comment change: " ) ;
95
+ {
96
+ let mut text = host. analysis ( ) . file_text ( file_id) . to_string ( ) ;
97
+ text. push_str ( "\n /* Hello world */\n " ) ;
98
+ let mut change = AnalysisChange :: new ( ) ;
99
+ change. change_file ( file_id, Arc :: new ( text) ) ;
100
+ host. apply_change ( change) ;
101
+ }
102
+ work ( & host. analysis ( ) ) ;
103
+ eprintln ! ( "{:?}" , start. elapsed( ) ) ;
104
+ }
91
105
{
92
106
let start = Instant :: now ( ) ;
93
107
eprint ! ( "const change: " ) ;
0 commit comments