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