Skip to content

Commit f540d1c

Browse files
committed
fix: Fix source root panic in global state when checking out older git revs
1 parent 58660de commit f540d1c

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,25 +180,15 @@ impl GlobalState {
180180
// A file was added or deleted
181181
let mut has_structure_changes = false;
182182

183-
let change = {
183+
let (change, changed_files) = {
184184
let mut change = Change::new();
185185
let (vfs, line_endings_map) = &mut *self.vfs.write();
186186
let changed_files = vfs.take_changes();
187187
if changed_files.is_empty() {
188188
return false;
189189
}
190190

191-
for file in changed_files {
192-
if !file.is_created_or_deleted() {
193-
// FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/11357
194-
let crates = self.analysis_host.raw_database().relevant_crates(file.file_id);
195-
let crate_graph = self.analysis_host.raw_database().crate_graph();
196-
197-
if crates.iter().any(|&krate| !crate_graph[krate].proc_macro.is_empty()) {
198-
self.proc_macro_changed = true;
199-
}
200-
}
201-
191+
for file in &changed_files {
202192
if let Some(path) = vfs.file_path(file.file_id).as_path() {
203193
let path = path.to_path_buf();
204194
if reload::should_refresh_for_change(&path, file.change_kind) {
@@ -212,14 +202,11 @@ impl GlobalState {
212202

213203
let text = if file.exists() {
214204
let bytes = vfs.file_contents(file.file_id).to_vec();
215-
match String::from_utf8(bytes).ok() {
216-
Some(text) => {
217-
let (text, line_endings) = LineEndings::normalize(text);
218-
line_endings_map.insert(file.file_id, line_endings);
219-
Some(Arc::new(text))
220-
}
221-
None => None,
222-
}
205+
String::from_utf8(bytes).ok().and_then(|text| {
206+
let (text, line_endings) = LineEndings::normalize(text);
207+
line_endings_map.insert(file.file_id, line_endings);
208+
Some(Arc::new(text))
209+
})
223210
} else {
224211
None
225212
};
@@ -229,10 +216,19 @@ impl GlobalState {
229216
let roots = self.source_root_config.partition(vfs);
230217
change.set_roots(roots);
231218
}
232-
change
219+
(change, changed_files)
233220
};
234221

235222
self.analysis_host.apply_change(change);
223+
224+
let raw_database = &self.analysis_host.raw_database();
225+
self.proc_macro_changed =
226+
changed_files.iter().filter(|file| !file.is_created_or_deleted()).any(|file| {
227+
let crates = raw_database.relevant_crates(file.file_id);
228+
let crate_graph = raw_database.crate_graph();
229+
230+
crates.iter().any(|&krate| !crate_graph[krate].is_proc_macro)
231+
});
236232
true
237233
}
238234

0 commit comments

Comments
 (0)