diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 43 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 9 |
2 files changed, 26 insertions, 26 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 7825b0077..d35963e95 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -208,6 +208,9 @@ pub fn main_loop( | |||
208 | ) | 208 | ) |
209 | }; | 209 | }; |
210 | 210 | ||
211 | loop_state.roots_total = world_state.vfs.read().n_roots(); | ||
212 | loop_state.roots_scanned = 0; | ||
213 | |||
211 | let pool = ThreadPool::default(); | 214 | let pool = ThreadPool::default(); |
212 | let (task_sender, task_receiver) = unbounded::<Task>(); | 215 | let (task_sender, task_receiver) = unbounded::<Task>(); |
213 | let (libdata_sender, libdata_receiver) = unbounded::<LibraryData>(); | 216 | let (libdata_sender, libdata_receiver) = unbounded::<LibraryData>(); |
@@ -333,7 +336,10 @@ struct LoopState { | |||
333 | in_flight_libraries: usize, | 336 | in_flight_libraries: usize, |
334 | pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>, | 337 | pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>, |
335 | workspace_loaded: bool, | 338 | workspace_loaded: bool, |
336 | roots_scanned_progress: Option<usize>, | 339 | |
340 | roots_progress_reported: Option<usize>, | ||
341 | roots_scanned: usize, | ||
342 | roots_total: usize, | ||
337 | } | 343 | } |
338 | 344 | ||
339 | impl LoopState { | 345 | impl LoopState { |
@@ -377,6 +383,7 @@ fn loop_turn( | |||
377 | world_state.add_lib(lib); | 383 | world_state.add_lib(lib); |
378 | world_state.maybe_collect_garbage(); | 384 | world_state.maybe_collect_garbage(); |
379 | loop_state.in_flight_libraries -= 1; | 385 | loop_state.in_flight_libraries -= 1; |
386 | loop_state.roots_scanned += 1; | ||
380 | } | 387 | } |
381 | Event::CheckWatcher(task) => on_check_task(task, world_state, task_sender)?, | 388 | Event::CheckWatcher(task) => on_check_task(task, world_state, task_sender)?, |
382 | Event::Msg(msg) => match msg { | 389 | Event::Msg(msg) => match msg { |
@@ -408,7 +415,7 @@ fn loop_turn( | |||
408 | }; | 415 | }; |
409 | 416 | ||
410 | let mut state_changed = false; | 417 | let mut state_changed = false; |
411 | if let Some(changes) = world_state.process_changes() { | 418 | if let Some(changes) = world_state.process_changes(&mut loop_state.roots_scanned) { |
412 | state_changed = true; | 419 | state_changed = true; |
413 | loop_state.pending_libraries.extend(changes); | 420 | loop_state.pending_libraries.extend(changes); |
414 | } | 421 | } |
@@ -427,8 +434,11 @@ fn loop_turn( | |||
427 | }); | 434 | }); |
428 | } | 435 | } |
429 | 436 | ||
437 | let show_progress = !loop_state.workspace_loaded | ||
438 | && world_state.feature_flags.get("notifications.workspace-loaded"); | ||
439 | |||
430 | if !loop_state.workspace_loaded | 440 | if !loop_state.workspace_loaded |
431 | && world_state.roots_to_scan == 0 | 441 | && loop_state.roots_scanned == loop_state.roots_total |
432 | && loop_state.pending_libraries.is_empty() | 442 | && loop_state.pending_libraries.is_empty() |
433 | && loop_state.in_flight_libraries == 0 | 443 | && loop_state.in_flight_libraries == 0 |
434 | { | 444 | { |
@@ -439,9 +449,10 @@ fn loop_turn( | |||
439 | let snap = world_state.snapshot(); | 449 | let snap = world_state.snapshot(); |
440 | move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) | 450 | move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) |
441 | }); | 451 | }); |
442 | send_startup_progress(&connection.sender, loop_state, world_state); | 452 | } |
443 | } else if !loop_state.workspace_loaded { | 453 | |
444 | send_startup_progress(&connection.sender, loop_state, world_state); | 454 | if show_progress { |
455 | send_startup_progress(&connection.sender, loop_state); | ||
445 | } | 456 | } |
446 | 457 | ||
447 | if state_changed { | 458 | if state_changed { |
@@ -706,21 +717,13 @@ fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender<Message>, state: | |||
706 | } | 717 | } |
707 | } | 718 | } |
708 | 719 | ||
709 | fn send_startup_progress( | 720 | fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) { |
710 | sender: &Sender<Message>, | 721 | let total: usize = loop_state.roots_total; |
711 | loop_state: &mut LoopState, | 722 | let prev = loop_state.roots_progress_reported; |
712 | world_state: &WorldState, | 723 | let progress = loop_state.roots_scanned; |
713 | ) { | 724 | loop_state.roots_progress_reported = Some(progress); |
714 | if !world_state.feature_flags.get("notifications.workspace-loaded") { | ||
715 | return; | ||
716 | } | ||
717 | |||
718 | let total: usize = world_state.workspaces.iter().map(|it| it.n_packages()).sum(); | ||
719 | let prev_progress = loop_state.roots_scanned_progress; | ||
720 | let progress = total - world_state.roots_to_scan; | ||
721 | loop_state.roots_scanned_progress = Some(progress); | ||
722 | 725 | ||
723 | match (prev_progress, loop_state.workspace_loaded) { | 726 | match (prev, loop_state.workspace_loaded) { |
724 | (None, false) => { | 727 | (None, false) => { |
725 | let work_done_progress_create = request_new::<req::WorkDoneProgressCreate>( | 728 | let work_done_progress_create = request_new::<req::WorkDoneProgressCreate>( |
726 | loop_state.next_request_id(), | 729 | loop_state.next_request_id(), |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 64a7b907e..5680397ed 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -51,8 +51,6 @@ pub struct Options { | |||
51 | pub struct WorldState { | 51 | pub struct WorldState { |
52 | pub options: Options, | 52 | pub options: Options, |
53 | pub feature_flags: Arc<FeatureFlags>, | 53 | pub feature_flags: Arc<FeatureFlags>, |
54 | //FIXME: this belongs to `LoopState` rather than to `WorldState` | ||
55 | pub roots_to_scan: usize, | ||
56 | pub roots: Vec<PathBuf>, | 54 | pub roots: Vec<PathBuf>, |
57 | pub workspaces: Arc<Vec<ProjectWorkspace>>, | 55 | pub workspaces: Arc<Vec<ProjectWorkspace>>, |
58 | pub analysis_host: AnalysisHost, | 56 | pub analysis_host: AnalysisHost, |
@@ -123,7 +121,7 @@ impl WorldState { | |||
123 | let (task_sender, task_receiver) = unbounded(); | 121 | let (task_sender, task_receiver) = unbounded(); |
124 | let task_sender = Box::new(move |t| task_sender.send(t).unwrap()); | 122 | let task_sender = Box::new(move |t| task_sender.send(t).unwrap()); |
125 | let (mut vfs, vfs_roots) = Vfs::new(roots, task_sender, watch); | 123 | let (mut vfs, vfs_roots) = Vfs::new(roots, task_sender, watch); |
126 | let roots_to_scan = vfs_roots.len(); | 124 | |
127 | for r in vfs_roots { | 125 | for r in vfs_roots { |
128 | let vfs_root_path = vfs.root2path(r); | 126 | let vfs_root_path = vfs.root2path(r); |
129 | let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it)); | 127 | let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it)); |
@@ -190,7 +188,6 @@ impl WorldState { | |||
190 | WorldState { | 188 | WorldState { |
191 | options, | 189 | options, |
192 | feature_flags: Arc::new(feature_flags), | 190 | feature_flags: Arc::new(feature_flags), |
193 | roots_to_scan, | ||
194 | roots: folder_roots, | 191 | roots: folder_roots, |
195 | workspaces: Arc::new(workspaces), | 192 | workspaces: Arc::new(workspaces), |
196 | analysis_host, | 193 | analysis_host, |
@@ -206,6 +203,7 @@ impl WorldState { | |||
206 | /// FIXME: better API here | 203 | /// FIXME: better API here |
207 | pub fn process_changes( | 204 | pub fn process_changes( |
208 | &mut self, | 205 | &mut self, |
206 | roots_scanned: &mut usize, | ||
209 | ) -> Option<Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>> { | 207 | ) -> Option<Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>> { |
210 | let changes = self.vfs.write().commit_changes(); | 208 | let changes = self.vfs.write().commit_changes(); |
211 | if changes.is_empty() { | 209 | if changes.is_empty() { |
@@ -219,7 +217,7 @@ impl WorldState { | |||
219 | let root_path = self.vfs.read().root2path(root); | 217 | let root_path = self.vfs.read().root2path(root); |
220 | let is_local = self.roots.iter().any(|r| root_path.starts_with(r)); | 218 | let is_local = self.roots.iter().any(|r| root_path.starts_with(r)); |
221 | if is_local { | 219 | if is_local { |
222 | self.roots_to_scan -= 1; | 220 | *roots_scanned += 1; |
223 | for (file, path, text) in files { | 221 | for (file, path, text) in files { |
224 | change.add_file(SourceRootId(root.0), FileId(file.0), path, text); | 222 | change.add_file(SourceRootId(root.0), FileId(file.0), path, text); |
225 | } | 223 | } |
@@ -247,7 +245,6 @@ impl WorldState { | |||
247 | } | 245 | } |
248 | 246 | ||
249 | pub fn add_lib(&mut self, data: LibraryData) { | 247 | pub fn add_lib(&mut self, data: LibraryData) { |
250 | self.roots_to_scan -= 1; | ||
251 | let mut change = AnalysisChange::new(); | 248 | let mut change = AnalysisChange::new(); |
252 | change.add_library(data); | 249 | change.add_library(data); |
253 | self.analysis_host.apply_change(change); | 250 | self.analysis_host.apply_change(change); |