From 7b91d01360288a5877fd3415a9e66d347681675b Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 19 Mar 2024 16:12:56 +0100 Subject: [PATCH] internal: Don't eagerly try to read crate root file contents before VFS --- crates/rust-analyzer/src/global_state.rs | 20 +++++++++++--------- crates/rust-analyzer/src/reload.rs | 12 +----------- crates/vfs/src/lib.rs | 5 +++++ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 1b4c33d858..8516ffa0df 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -307,17 +307,19 @@ impl GlobalState { for file in changed_files { let vfs_path = vfs.file_path(file.file_id); if let Some(path) = vfs_path.as_path() { - let path = path.to_path_buf(); - if reload::should_refresh_for_change(&path, file.kind()) { - workspace_structure_change = Some((path.clone(), false)); - } - if file.is_created_or_deleted() { - has_structure_changes = true; - workspace_structure_change = - Some((path, self.crate_graph_file_dependencies.contains(vfs_path))); - } else if path.extension() == Some("rs".as_ref()) { + has_structure_changes = file.is_created_or_deleted(); + + if file.is_modified() && path.extension() == Some("rs") { modified_rust_files.push(file.file_id); } + + let path = path.to_path_buf(); + if file.is_created_or_deleted() { + workspace_structure_change.get_or_insert((path, false)).1 |= + self.crate_graph_file_dependencies.contains(vfs_path); + } else if reload::should_refresh_for_change(&path, file.kind()) { + workspace_structure_change.get_or_insert((path.clone(), false)); + } } // Clear native diagnostics when their file gets deleted diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 967904a01a..507f584ff7 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -528,21 +528,11 @@ impl GlobalState { let (crate_graph, proc_macro_paths, layouts, toolchains) = { // Create crate graph from all the workspaces let vfs = &mut self.vfs.write().0; - let loader = &mut self.loader; let load = |path: &AbsPath| { - let _p = tracing::span!(tracing::Level::DEBUG, "switch_workspaces::load").entered(); let vfs_path = vfs::VfsPath::from(path.to_path_buf()); crate_graph_file_dependencies.insert(vfs_path.clone()); - match vfs.file_id(&vfs_path) { - Some(file_id) => Some(file_id), - None => { - // FIXME: Consider not loading this here? - let contents = loader.handle.load_sync(path); - vfs.set_file_contents(vfs_path.clone(), contents); - vfs.file_id(&vfs_path) - } - } + vfs.file_id(&vfs_path) }; ws_to_crate_graph(&self.workspaces, self.config.extra_env(), load) diff --git a/crates/vfs/src/lib.rs b/crates/vfs/src/lib.rs index 824ce39870..9d723f8143 100644 --- a/crates/vfs/src/lib.rs +++ b/crates/vfs/src/lib.rs @@ -121,6 +121,11 @@ impl ChangedFile { matches!(self.change, Change::Create(_) | Change::Delete) } + /// Returns `true` if the change is [`Modify`](ChangeKind::Modify). + pub fn is_modified(&self) -> bool { + matches!(self.change, Change::Modify(_)) + } + pub fn kind(&self) -> ChangeKind { match self.change { Change::Create(_) => ChangeKind::Create,