Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7b91d01

Browse files
committed
internal: Don't eagerly try to read crate root file contents before VFS
1 parent 399dbc0 commit 7b91d01

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,18 @@ impl GlobalState {
307307
for file in changed_files {
308308
let vfs_path = vfs.file_path(file.file_id);
309309
if let Some(path) = vfs_path.as_path() {
310-
let path = path.to_path_buf();
311-
if reload::should_refresh_for_change(&path, file.kind()) {
312-
workspace_structure_change = Some((path.clone(), false));
310+
has_structure_changes = file.is_created_or_deleted();
311+
312+
if file.is_modified() && path.extension() == Some("rs") {
313+
modified_rust_files.push(file.file_id);
313314
}
315+
316+
let path = path.to_path_buf();
314317
if file.is_created_or_deleted() {
315-
has_structure_changes = true;
316-
workspace_structure_change =
317-
Some((path, self.crate_graph_file_dependencies.contains(vfs_path)));
318-
} else if path.extension() == Some("rs".as_ref()) {
319-
modified_rust_files.push(file.file_id);
318+
workspace_structure_change.get_or_insert((path, false)).1 |=
319+
self.crate_graph_file_dependencies.contains(vfs_path);
320+
} else if reload::should_refresh_for_change(&path, file.kind()) {
321+
workspace_structure_change.get_or_insert((path.clone(), false));
320322
}
321323
}
322324

crates/rust-analyzer/src/reload.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,11 @@ impl GlobalState {
528528
let (crate_graph, proc_macro_paths, layouts, toolchains) = {
529529
// Create crate graph from all the workspaces
530530
let vfs = &mut self.vfs.write().0;
531-
let loader = &mut self.loader;
532531

533532
let load = |path: &AbsPath| {
534-
let _p = tracing::span!(tracing::Level::DEBUG, "switch_workspaces::load").entered();
535533
let vfs_path = vfs::VfsPath::from(path.to_path_buf());
536534
crate_graph_file_dependencies.insert(vfs_path.clone());
537-
match vfs.file_id(&vfs_path) {
538-
Some(file_id) => Some(file_id),
539-
None => {
540-
// FIXME: Consider not loading this here?
541-
let contents = loader.handle.load_sync(path);
542-
vfs.set_file_contents(vfs_path.clone(), contents);
543-
vfs.file_id(&vfs_path)
544-
}
545-
}
535+
vfs.file_id(&vfs_path)
546536
};
547537

548538
ws_to_crate_graph(&self.workspaces, self.config.extra_env(), load)

crates/vfs/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ impl ChangedFile {
121121
matches!(self.change, Change::Create(_) | Change::Delete)
122122
}
123123

124+
/// Returns `true` if the change is [`Modify`](ChangeKind::Modify).
125+
pub fn is_modified(&self) -> bool {
126+
matches!(self.change, Change::Modify(_))
127+
}
128+
124129
pub fn kind(&self) -> ChangeKind {
125130
match self.change {
126131
Change::Create(_) => ChangeKind::Create,

0 commit comments

Comments
 (0)