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

Commit 6fce1d7

Browse files
committed
Auto merge of rust-lang#16892 - Veykril:crate-graph-non-eager, r=Veykril
internal: Don't eagerly try to read crate root file contents before VFS Fixes rust-lang/rust-analyzer#8623
2 parents 4e54b4b + 7b91d01 commit 6fce1d7

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
@@ -535,21 +535,11 @@ impl GlobalState {
535535
let (crate_graph, proc_macro_paths, layouts, toolchains) = {
536536
// Create crate graph from all the workspaces
537537
let vfs = &mut self.vfs.write().0;
538-
let loader = &mut self.loader;
539538

540539
let load = |path: &AbsPath| {
541-
let _p = tracing::span!(tracing::Level::DEBUG, "switch_workspaces::load").entered();
542540
let vfs_path = vfs::VfsPath::from(path.to_path_buf());
543541
crate_graph_file_dependencies.insert(vfs_path.clone());
544-
match vfs.file_id(&vfs_path) {
545-
Some(file_id) => Some(file_id),
546-
None => {
547-
// FIXME: Consider not loading this here?
548-
let contents = loader.handle.load_sync(path);
549-
vfs.set_file_contents(vfs_path.clone(), contents);
550-
vfs.file_id(&vfs_path)
551-
}
552-
}
542+
vfs.file_id(&vfs_path)
553543
};
554544

555545
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)