Skip to content

Commit

Permalink
Auto merge of #16892 - Veykril:crate-graph-non-eager, r=Veykril
Browse files Browse the repository at this point in the history
internal: Don't eagerly try to read crate root file contents before VFS

Fixes #8623
  • Loading branch information
bors committed Mar 19, 2024
2 parents 4e54b4b + 7b91d01 commit 6fce1d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
18 changes: 10 additions & 8 deletions crates/rust-analyzer/src/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,18 @@ 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));
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() {
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()) {
modified_rust_files.push(file.file_id);
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));
}
}

Expand Down
12 changes: 1 addition & 11 deletions crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,21 +535,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)
Expand Down
5 changes: 5 additions & 0 deletions crates/vfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6fce1d7

Please sign in to comment.