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