diff options
author | Aleksey Kladov <[email protected]> | 2021-04-06 12:16:35 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-04-06 13:45:31 +0100 |
commit | 8fe20b19d4702fc6d6933c31abddc8539d2581f0 (patch) | |
tree | 8aca2a3aa2b059bb47cc235b1b557d4b4de93a24 /crates/rust-analyzer/src/main_loop.rs | |
parent | 9143e3925cd95d30af72745f25e185f65a686d32 (diff) |
More robust status notifications
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 4a4705e1f..a5655116b 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -21,7 +21,7 @@ use crate::{ | |||
21 | dispatch::{NotificationDispatcher, RequestDispatcher}, | 21 | dispatch::{NotificationDispatcher, RequestDispatcher}, |
22 | document::DocumentData, | 22 | document::DocumentData, |
23 | from_proto, | 23 | from_proto, |
24 | global_state::{file_id_to_url, url_to_file_id, GlobalState, Status}, | 24 | global_state::{file_id_to_url, url_to_file_id, GlobalState}, |
25 | handlers, lsp_ext, | 25 | handlers, lsp_ext, |
26 | lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress}, | 26 | lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress}, |
27 | reload::{BuildDataProgress, ProjectWorkspaceProgress}, | 27 | reload::{BuildDataProgress, ProjectWorkspaceProgress}, |
@@ -189,7 +189,7 @@ impl GlobalState { | |||
189 | log::info!("task queue len: {}", task_queue_len); | 189 | log::info!("task queue len: {}", task_queue_len); |
190 | } | 190 | } |
191 | 191 | ||
192 | let mut new_status = self.status; | 192 | let was_quiescent = self.is_quiescent(); |
193 | match event { | 193 | match event { |
194 | Event::Lsp(msg) => match msg { | 194 | Event::Lsp(msg) => match msg { |
195 | lsp_server::Message::Request(req) => self.on_request(loop_start, req)?, | 195 | lsp_server::Message::Request(req) => self.on_request(loop_start, req)?, |
@@ -314,9 +314,12 @@ impl GlobalState { | |||
314 | } | 314 | } |
315 | } | 315 | } |
316 | vfs::loader::Message::Progress { n_total, n_done, config_version } => { | 316 | vfs::loader::Message::Progress { n_total, n_done, config_version } => { |
317 | always!(config_version <= self.vfs_config_version); | ||
318 | |||
319 | self.vfs_progress_config_version = config_version; | ||
317 | self.vfs_progress_n_total = n_total; | 320 | self.vfs_progress_n_total = n_total; |
318 | self.vfs_progress_n_done = n_done; | 321 | self.vfs_progress_n_done = n_done; |
319 | always!(config_version <= self.vfs_config_version); | 322 | |
320 | let state = if n_done == 0 { | 323 | let state = if n_done == 0 { |
321 | Progress::Begin | 324 | Progress::Begin |
322 | } else if n_done < n_total { | 325 | } else if n_done < n_total { |
@@ -406,18 +409,14 @@ impl GlobalState { | |||
406 | } | 409 | } |
407 | 410 | ||
408 | let state_changed = self.process_changes(); | 411 | let state_changed = self.process_changes(); |
409 | let prev_status = self.status; | 412 | |
410 | if prev_status != new_status { | 413 | if self.is_quiescent() && !was_quiescent { |
411 | self.transition(new_status); | ||
412 | } | ||
413 | let is_ready = matches!(self.status, Status::Ready { .. }); | ||
414 | if prev_status == Status::Loading && is_ready { | ||
415 | for flycheck in &self.flycheck { | 414 | for flycheck in &self.flycheck { |
416 | flycheck.update(); | 415 | flycheck.update(); |
417 | } | 416 | } |
418 | } | 417 | } |
419 | 418 | ||
420 | if is_ready && (state_changed || prev_status == Status::Loading) { | 419 | if self.is_quiescent() && (!was_quiescent || state_changed) { |
421 | self.update_file_notifications_on_threadpool(); | 420 | self.update_file_notifications_on_threadpool(); |
422 | 421 | ||
423 | // Refresh semantic tokens if the client supports it. | 422 | // Refresh semantic tokens if the client supports it. |
@@ -451,6 +450,8 @@ impl GlobalState { | |||
451 | } | 450 | } |
452 | self.fetch_build_data_if_needed(); | 451 | self.fetch_build_data_if_needed(); |
453 | 452 | ||
453 | self.report_new_status_if_needed(); | ||
454 | |||
454 | let loop_duration = loop_start.elapsed(); | 455 | let loop_duration = loop_start.elapsed(); |
455 | if loop_duration > Duration::from_millis(100) { | 456 | if loop_duration > Duration::from_millis(100) { |
456 | log::warn!("overly long loop turn: {:?}", loop_duration); | 457 | log::warn!("overly long loop turn: {:?}", loop_duration); |
@@ -477,7 +478,8 @@ impl GlobalState { | |||
477 | return Ok(()); | 478 | return Ok(()); |
478 | } | 479 | } |
479 | 480 | ||
480 | if self.status == Status::Loading && req.method != "shutdown" { | 481 | // Avoid flashing a bunch of unresolved references during initial load. |
482 | if self.workspaces.is_empty() && !self.is_quiescent() { | ||
481 | self.respond(lsp_server::Response::new_err( | 483 | self.respond(lsp_server::Response::new_err( |
482 | req.id, | 484 | req.id, |
483 | // FIXME: i32 should impl From<ErrorCode> (from() guarantees lossless conversion) | 485 | // FIXME: i32 should impl From<ErrorCode> (from() guarantees lossless conversion) |