From 1313ca8415014d8df40ef8e629521ad6934838e0 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 28 Feb 2022 14:26:10 +0100 Subject: [PATCH] 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. --- crates/project/src/project.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 84b52e94739ded616e0bc268c342c68a766281de..04d83e63615a04a8e6f3b4342b6f9568a63549d0 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -811,24 +811,20 @@ impl Project { path: &ProjectPath, cx: &mut ModelContext, ) -> Option> { - 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(