diff options
author | Florian Diebold <[email protected]> | 2021-02-12 14:58:29 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-02-12 15:31:16 +0000 |
commit | a7387cae2ca9d5e114246e6fada98bfe7808e1d0 (patch) | |
tree | db0fe8d939afaa10929debf317be670f79909c9f /crates/rust-analyzer/src/main_loop.rs | |
parent | dee5aba43a1b45131bf31268431fa71923f2ef2a (diff) |
Fix slow tests sometimes failing
In some situations we reloaded the workspace in the tests after having reported
to be ready. There's two fixes here:
1. Add a version to the VFS config and include that version in progress reports,
so that we don't think we're done prematurely;
2. Delay status transitions until after changes are applied. Otherwise the last
change during loading can potentially trigger a workspace reload, if it contains
interesting changes.
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index bdffff5ae..2829d5970 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -5,6 +5,7 @@ use std::{ | |||
5 | time::{Duration, Instant}, | 5 | time::{Duration, Instant}, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use always_assert::always; | ||
8 | use crossbeam_channel::{select, Receiver}; | 9 | use crossbeam_channel::{select, Receiver}; |
9 | use ide::PrimeCachesProgress; | 10 | use ide::PrimeCachesProgress; |
10 | use ide::{Canceled, FileId}; | 11 | use ide::{Canceled, FileId}; |
@@ -186,7 +187,7 @@ impl GlobalState { | |||
186 | log::info!("task queue len: {}", task_queue_len); | 187 | log::info!("task queue len: {}", task_queue_len); |
187 | } | 188 | } |
188 | 189 | ||
189 | let prev_status = self.status; | 190 | let mut new_status = self.status; |
190 | match event { | 191 | match event { |
191 | Event::Lsp(msg) => match msg { | 192 | Event::Lsp(msg) => match msg { |
192 | lsp_server::Message::Request(req) => self.on_request(loop_start, req)?, | 193 | lsp_server::Message::Request(req) => self.on_request(loop_start, req)?, |
@@ -298,22 +299,23 @@ impl GlobalState { | |||
298 | } | 299 | } |
299 | } | 300 | } |
300 | } | 301 | } |
301 | vfs::loader::Message::Progress { n_total, n_done } => { | 302 | vfs::loader::Message::Progress { n_total, n_done, config_version } => { |
303 | always!(config_version <= self.vfs_config_version); | ||
302 | if n_total == 0 { | 304 | if n_total == 0 { |
303 | self.transition(Status::Invalid); | 305 | new_status = Status::Invalid; |
304 | } else { | 306 | } else { |
305 | let state = if n_done == 0 { | 307 | let state = if n_done == 0 { |
306 | self.transition(Status::Loading); | 308 | new_status = Status::Loading; |
307 | Progress::Begin | 309 | Progress::Begin |
308 | } else if n_done < n_total { | 310 | } else if n_done < n_total { |
309 | Progress::Report | 311 | Progress::Report |
310 | } else { | 312 | } else { |
311 | assert_eq!(n_done, n_total); | 313 | assert_eq!(n_done, n_total); |
312 | let status = Status::Ready { | 314 | new_status = Status::Ready { |
313 | partial: self.config.load_out_dirs_from_check() | 315 | partial: self.config.load_out_dirs_from_check() |
314 | && self.workspace_build_data.is_none(), | 316 | && self.workspace_build_data.is_none() |
317 | || config_version < self.vfs_config_version, | ||
315 | }; | 318 | }; |
316 | self.transition(status); | ||
317 | Progress::End | 319 | Progress::End |
318 | }; | 320 | }; |
319 | self.report_progress( | 321 | self.report_progress( |
@@ -398,6 +400,10 @@ impl GlobalState { | |||
398 | } | 400 | } |
399 | 401 | ||
400 | let state_changed = self.process_changes(); | 402 | let state_changed = self.process_changes(); |
403 | let prev_status = self.status; | ||
404 | if prev_status != new_status { | ||
405 | self.transition(new_status); | ||
406 | } | ||
401 | let is_ready = matches!(self.status, Status::Ready { .. }); | 407 | let is_ready = matches!(self.status, Status::Ready { .. }); |
402 | if prev_status == Status::Loading && is_ready { | 408 | if prev_status == Status::Loading && is_ready { |
403 | for flycheck in &self.flycheck { | 409 | for flycheck in &self.flycheck { |