Don't delete buffer state when calling get_open_buffer

...as we might be in the process of completing a request that could
open a buffer. This was causing a failure in the randomized integration
test.
This commit is contained in:
Antonio Scandurra 2022-02-28 14:26:10 +01:00
parent 5f7a759870
commit 1313ca8415

View file

@ -811,24 +811,20 @@ impl Project {
path: &ProjectPath, path: &ProjectPath,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Option<ModelHandle<Buffer>> { ) -> Option<ModelHandle<Buffer>> {
let mut result = None;
let worktree = self.worktree_for_id(path.worktree_id, cx)?; let worktree = self.worktree_for_id(path.worktree_id, cx)?;
self.buffers_state self.buffers_state
.borrow_mut() .borrow()
.open_buffers .open_buffers
.retain(|_, buffer| { .values()
if let Some(buffer) = buffer.upgrade(cx) { .find_map(|buffer| {
if let Some(file) = File::from_dyn(buffer.read(cx).file()) { let buffer = buffer.upgrade(cx)?;
let file = File::from_dyn(buffer.read(cx).file())?;
if file.worktree == worktree && file.path() == &path.path { if file.worktree == worktree && file.path() == &path.path {
result = Some(buffer); Some(buffer)
}
}
true
} else { } else {
false None
} }
}); })
result
} }
fn register_buffer( fn register_buffer(