diff options
author | Jonas Schievink <[email protected]> | 2020-11-02 16:06:49 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-11-02 16:24:35 +0000 |
commit | 6e8ddac165777a0811336c2aef71840459c5f997 (patch) | |
tree | 22a3b25d152e6f8398a4f8de518cea84829b3c3e /crates | |
parent | cb04f0c019bdd77406a7feb6ae7f4a17924d0693 (diff) |
Coalesce prime_caches updates
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 53f8ca194..403904479 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -190,15 +190,35 @@ impl GlobalState { | |||
190 | } | 190 | } |
191 | lsp_server::Message::Response(resp) => self.complete_request(resp), | 191 | lsp_server::Message::Response(resp) => self.complete_request(resp), |
192 | }, | 192 | }, |
193 | Event::Task(task) => match task { | 193 | Event::Task(mut task) => { |
194 | Task::Response(response) => self.respond(response), | 194 | let _p = profile::span("GlobalState::handle_event/task"); |
195 | Task::Diagnostics(diagnostics_per_file) => { | 195 | let mut prime_caches_started = false; |
196 | for (file_id, diagnostics) in diagnostics_per_file { | 196 | let mut prime_caches_progress = None; |
197 | self.diagnostics.set_native_diagnostics(file_id, diagnostics) | 197 | loop { |
198 | match task { | ||
199 | Task::Response(response) => self.respond(response), | ||
200 | Task::Diagnostics(diagnostics_per_file) => { | ||
201 | for (file_id, diagnostics) in diagnostics_per_file { | ||
202 | self.diagnostics.set_native_diagnostics(file_id, diagnostics) | ||
203 | } | ||
204 | } | ||
205 | Task::Workspaces(workspaces) => self.switch_workspaces(workspaces), | ||
206 | Task::PrimeCaches(progress) => { | ||
207 | if let PrimeCachesProgress::Started = progress { | ||
208 | prime_caches_started = true; | ||
209 | } | ||
210 | |||
211 | prime_caches_progress = Some(progress); | ||
212 | } | ||
198 | } | 213 | } |
214 | // Coalesce multiple task events into one loop turn | ||
215 | task = match self.task_pool.receiver.try_recv() { | ||
216 | Ok(task) => task, | ||
217 | Err(_) => break, | ||
218 | }; | ||
199 | } | 219 | } |
200 | Task::Workspaces(workspaces) => self.switch_workspaces(workspaces), | 220 | |
201 | Task::PrimeCaches(progress) => { | 221 | if let Some(progress) = prime_caches_progress { |
202 | let (state, message, fraction); | 222 | let (state, message, fraction); |
203 | match progress { | 223 | match progress { |
204 | PrimeCachesProgress::Started => { | 224 | PrimeCachesProgress::Started => { |
@@ -218,9 +238,15 @@ impl GlobalState { | |||
218 | } | 238 | } |
219 | }; | 239 | }; |
220 | 240 | ||
221 | self.report_progress("indexing", state, message, Some(fraction)); | 241 | if state != Progress::Begin && prime_caches_started { |
242 | // Progress indicator needs to be created first. | ||
243 | self.report_progress("indexing", Progress::Begin, None, Some(0.0)); | ||
244 | } | ||
245 | |||
246 | self.report_progress("indexing", state, message.clone(), Some(fraction)); | ||
247 | eprintln!("progress reported: {:?}", message); | ||
222 | } | 248 | } |
223 | }, | 249 | } |
224 | Event::Vfs(mut task) => { | 250 | Event::Vfs(mut task) => { |
225 | let _p = profile::span("GlobalState::handle_event/vfs"); | 251 | let _p = profile::span("GlobalState::handle_event/vfs"); |
226 | loop { | 252 | loop { |