@@ -77,7 +77,7 @@ pub(crate) enum PrimeCachesProgress {
77
77
78
78
impl fmt:: Debug for Event {
79
79
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
80
- let debug_verbose_not = |not : & Notification , f : & mut fmt:: Formatter < ' _ > | {
80
+ let debug_non_verbose = |not : & Notification , f : & mut fmt:: Formatter < ' _ > | {
81
81
f. debug_struct ( "Notification" ) . field ( "method" , & not. method ) . finish ( )
82
82
} ;
83
83
@@ -86,7 +86,7 @@ impl fmt::Debug for Event {
86
86
if notification_is :: < lsp_types:: notification:: DidOpenTextDocument > ( not)
87
87
|| notification_is :: < lsp_types:: notification:: DidChangeTextDocument > ( not)
88
88
{
89
- return debug_verbose_not ( not, f) ;
89
+ return debug_non_verbose ( not, f) ;
90
90
}
91
91
}
92
92
Event :: Task ( Task :: Response ( resp) ) => {
@@ -112,38 +112,7 @@ impl GlobalState {
112
112
self . update_status_or_notify ( ) ;
113
113
114
114
if self . config . did_save_text_document_dynamic_registration ( ) {
115
- let save_registration_options = lsp_types:: TextDocumentSaveRegistrationOptions {
116
- include_text : Some ( false ) ,
117
- text_document_registration_options : lsp_types:: TextDocumentRegistrationOptions {
118
- document_selector : Some ( vec ! [
119
- lsp_types:: DocumentFilter {
120
- language: None ,
121
- scheme: None ,
122
- pattern: Some ( "**/*.rs" . into( ) ) ,
123
- } ,
124
- lsp_types:: DocumentFilter {
125
- language: None ,
126
- scheme: None ,
127
- pattern: Some ( "**/Cargo.toml" . into( ) ) ,
128
- } ,
129
- lsp_types:: DocumentFilter {
130
- language: None ,
131
- scheme: None ,
132
- pattern: Some ( "**/Cargo.lock" . into( ) ) ,
133
- } ,
134
- ] ) ,
135
- } ,
136
- } ;
137
-
138
- let registration = lsp_types:: Registration {
139
- id : "textDocument/didSave" . to_string ( ) ,
140
- method : "textDocument/didSave" . to_string ( ) ,
141
- register_options : Some ( serde_json:: to_value ( save_registration_options) . unwrap ( ) ) ,
142
- } ;
143
- self . send_request :: < lsp_types:: request:: RegisterCapability > (
144
- lsp_types:: RegistrationParams { registrations : vec ! [ registration] } ,
145
- |_, _| ( ) ,
146
- ) ;
115
+ self . register_did_save_capability ( ) ;
147
116
}
148
117
149
118
self . fetch_workspaces_queue . request_op ( "startup" . to_string ( ) , ( ) ) ;
@@ -152,17 +121,54 @@ impl GlobalState {
152
121
}
153
122
154
123
while let Some ( event) = self . next_event ( & inbox) {
155
- if let Event :: Lsp ( lsp_server:: Message :: Notification ( not) ) = & event {
156
- if not. method == lsp_types:: notification:: Exit :: METHOD {
157
- return Ok ( ( ) ) ;
158
- }
124
+ if matches ! (
125
+ & event,
126
+ Event :: Lsp ( lsp_server:: Message :: Notification ( Notification { method, .. } ) )
127
+ if method == lsp_types:: notification:: Exit :: METHOD
128
+ ) {
129
+ return Ok ( ( ) ) ;
159
130
}
160
- self . handle_event ( event) ?
131
+ self . handle_event ( event) ?;
161
132
}
162
133
163
134
Err ( "client exited without proper shutdown sequence" . into ( ) )
164
135
}
165
136
137
+ fn register_did_save_capability ( & mut self ) {
138
+ let save_registration_options = lsp_types:: TextDocumentSaveRegistrationOptions {
139
+ include_text : Some ( false ) ,
140
+ text_document_registration_options : lsp_types:: TextDocumentRegistrationOptions {
141
+ document_selector : Some ( vec ! [
142
+ lsp_types:: DocumentFilter {
143
+ language: None ,
144
+ scheme: None ,
145
+ pattern: Some ( "**/*.rs" . into( ) ) ,
146
+ } ,
147
+ lsp_types:: DocumentFilter {
148
+ language: None ,
149
+ scheme: None ,
150
+ pattern: Some ( "**/Cargo.toml" . into( ) ) ,
151
+ } ,
152
+ lsp_types:: DocumentFilter {
153
+ language: None ,
154
+ scheme: None ,
155
+ pattern: Some ( "**/Cargo.lock" . into( ) ) ,
156
+ } ,
157
+ ] ) ,
158
+ } ,
159
+ } ;
160
+
161
+ let registration = lsp_types:: Registration {
162
+ id : "textDocument/didSave" . to_string ( ) ,
163
+ method : "textDocument/didSave" . to_string ( ) ,
164
+ register_options : Some ( serde_json:: to_value ( save_registration_options) . unwrap ( ) ) ,
165
+ } ;
166
+ self . send_request :: < lsp_types:: request:: RegisterCapability > (
167
+ lsp_types:: RegistrationParams { registrations : vec ! [ registration] } ,
168
+ |_, _| ( ) ,
169
+ ) ;
170
+ }
171
+
166
172
fn next_event ( & self , inbox : & Receiver < lsp_server:: Message > ) -> Option < Event > {
167
173
select ! {
168
174
recv( inbox) -> msg =>
@@ -184,20 +190,20 @@ impl GlobalState {
184
190
// NOTE: don't count blocking select! call as a loop-turn time
185
191
let _p = profile:: span ( "GlobalState::handle_event" ) ;
186
192
187
- let event_dbg = format ! ( "{event:?}" ) ;
188
- tracing:: debug!( "{:?} handle_event({:?})" , loop_start, event) ;
189
- let task_queue_len = self . task_pool . handle . len ( ) ;
190
- if task_queue_len > 0 {
191
- tracing:: info!( "task queue len: {}" , task_queue_len) ;
193
+ let event_dbg_msg = format ! ( "{event:?}" ) ;
194
+ tracing:: debug!( "{:?} handle_event({})" , loop_start, event_dbg_msg) ;
195
+ if tracing:: enabled!( tracing:: Level :: INFO ) {
196
+ let task_queue_len = self . task_pool . handle . len ( ) ;
197
+ if task_queue_len > 0 {
198
+ tracing:: info!( "task queue len: {}" , task_queue_len) ;
199
+ }
192
200
}
193
201
194
202
let was_quiescent = self . is_quiescent ( ) ;
195
203
match event {
196
204
Event :: Lsp ( msg) => match msg {
197
205
lsp_server:: Message :: Request ( req) => self . on_new_request ( loop_start, req) ,
198
- lsp_server:: Message :: Notification ( not) => {
199
- self . on_notification ( not) ?;
200
- }
206
+ lsp_server:: Message :: Notification ( not) => self . on_notification ( not) ?,
201
207
lsp_server:: Message :: Response ( resp) => self . complete_request ( resp) ,
202
208
} ,
203
209
Event :: Task ( task) => {
@@ -291,7 +297,8 @@ impl GlobalState {
291
297
}
292
298
}
293
299
294
- if !was_quiescent || state_changed {
300
+ let client_refresh = !was_quiescent || state_changed;
301
+ if client_refresh {
295
302
// Refresh semantic tokens if the client supports it.
296
303
if self . config . semantic_tokens_refresh ( ) {
297
304
self . semantic_tokens_cache . lock ( ) . clear ( ) ;
@@ -309,9 +316,9 @@ impl GlobalState {
309
316
}
310
317
}
311
318
312
- if ( !was_quiescent || state_changed || memdocs_added_or_removed)
313
- && self . config . publish_diagnostics ( )
314
- {
319
+ let update_diagnostics = ( !was_quiescent || state_changed || memdocs_added_or_removed)
320
+ && self . config . publish_diagnostics ( ) ;
321
+ if update_diagnostics {
315
322
self . update_diagnostics ( )
316
323
}
317
324
}
@@ -371,38 +378,40 @@ impl GlobalState {
371
378
}
372
379
373
380
if let Some ( ( cause, ( ) ) ) = self . prime_caches_queue . should_start_op ( ) {
374
- tracing:: debug!( %cause, "will prime caches" ) ;
375
- let num_worker_threads = self . config . prime_caches_num_threads ( ) ;
376
-
377
- self . task_pool . handle . spawn_with_sender ( {
378
- let analysis = self . snapshot ( ) . analysis ;
379
- move |sender| {
380
- sender. send ( Task :: PrimeCaches ( PrimeCachesProgress :: Begin ) ) . unwrap ( ) ;
381
- let res = analysis. parallel_prime_caches ( num_worker_threads, |progress| {
382
- let report = PrimeCachesProgress :: Report ( progress) ;
383
- sender. send ( Task :: PrimeCaches ( report) ) . unwrap ( ) ;
384
- } ) ;
385
- sender
386
- . send ( Task :: PrimeCaches ( PrimeCachesProgress :: End {
387
- cancelled : res. is_err ( ) ,
388
- } ) )
389
- . unwrap ( ) ;
390
- }
391
- } ) ;
381
+ self . prime_caches ( cause) ;
392
382
}
393
383
394
384
self . update_status_or_notify ( ) ;
395
385
396
386
let loop_duration = loop_start. elapsed ( ) ;
397
387
if loop_duration > Duration :: from_millis ( 100 ) && was_quiescent {
398
- tracing:: warn!( "overly long loop turn took {loop_duration:?}: {event_dbg }" ) ;
388
+ tracing:: warn!( "overly long loop turn took {loop_duration:?}: {event_dbg_msg }" ) ;
399
389
self . poke_rust_analyzer_developer ( format ! (
400
- "overly long loop turn took {loop_duration:?}: {event_dbg }"
390
+ "overly long loop turn took {loop_duration:?}: {event_dbg_msg }"
401
391
) ) ;
402
392
}
403
393
Ok ( ( ) )
404
394
}
405
395
396
+ fn prime_caches ( & mut self , cause : String ) {
397
+ tracing:: debug!( %cause, "will prime caches" ) ;
398
+ let num_worker_threads = self . config . prime_caches_num_threads ( ) ;
399
+
400
+ self . task_pool . handle . spawn_with_sender ( {
401
+ let analysis = self . snapshot ( ) . analysis ;
402
+ move |sender| {
403
+ sender. send ( Task :: PrimeCaches ( PrimeCachesProgress :: Begin ) ) . unwrap ( ) ;
404
+ let res = analysis. parallel_prime_caches ( num_worker_threads, |progress| {
405
+ let report = PrimeCachesProgress :: Report ( progress) ;
406
+ sender. send ( Task :: PrimeCaches ( report) ) . unwrap ( ) ;
407
+ } ) ;
408
+ sender
409
+ . send ( Task :: PrimeCaches ( PrimeCachesProgress :: End { cancelled : res. is_err ( ) } ) )
410
+ . unwrap ( ) ;
411
+ }
412
+ } ) ;
413
+ }
414
+
406
415
fn update_status_or_notify ( & mut self ) {
407
416
let status = self . current_status ( ) ;
408
417
if self . last_reported_status . as_ref ( ) != Some ( & status) {
0 commit comments