From 6821efc4a83ec91107b1037c9121d5a1fb7e7055 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 28 Sep 2025 13:35:36 +0200 Subject: [PATCH] search: Fix panic in project search due to workspace double lease (#39049) Fixes ZED-1K1 Release Notes: - Fixed panic when spawning a new project search with include file only filtering --- crates/search/src/project_search.rs | 43 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 33ccd095687c448abc5d8b685da22e89ab59cbc8..605c4d4c27d517fbf664c07d893375e728748add 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -958,7 +958,12 @@ impl ProjectSearchView { .and_then(|item| item.downcast::()) { let new_query = search_view.update(cx, |search_view, cx| { - let new_query = search_view.build_search_query(cx); + let open_buffers = if search_view.included_opened_only { + Some(search_view.open_buffers(cx, workspace)) + } else { + None + }; + let new_query = search_view.build_search_query(cx, open_buffers); if new_query.is_some() && let Some(old_query) = search_view.entity.read(cx).active_query.clone() { @@ -1134,7 +1139,14 @@ impl ProjectSearchView { } fn search(&mut self, cx: &mut Context) { - if let Some(query) = self.build_search_query(cx) { + let open_buffers = if self.included_opened_only { + self.workspace + .update(cx, |workspace, cx| self.open_buffers(cx, workspace)) + .ok() + } else { + None + }; + if let Some(query) = self.build_search_query(cx, open_buffers) { self.entity.update(cx, |model, cx| model.search(query, cx)); } } @@ -1143,14 +1155,13 @@ impl ProjectSearchView { self.query_editor.read(cx).text(cx) } - fn build_search_query(&mut self, cx: &mut Context) -> Option { + fn build_search_query( + &mut self, + cx: &mut Context, + open_buffers: Option>>, + ) -> Option { // Do not bail early in this function, as we want to fill out `self.panels_with_errors`. let text = self.search_query_text(cx); - let open_buffers = if self.included_opened_only { - Some(self.open_buffers(cx)) - } else { - None - }; let included_files = self .filters_enabled .then(|| { @@ -1286,17 +1297,13 @@ impl ProjectSearchView { query } - fn open_buffers(&self, cx: &mut Context) -> Vec> { + fn open_buffers(&self, cx: &App, workspace: &Workspace) -> Vec> { let mut buffers = Vec::new(); - self.workspace - .update(cx, |workspace, cx| { - for editor in workspace.items_of_type::(cx) { - if let Some(buffer) = editor.read(cx).buffer().read(cx).as_singleton() { - buffers.push(buffer); - } - } - }) - .ok(); + for editor in workspace.items_of_type::(cx) { + if let Some(buffer) = editor.read(cx).buffer().read(cx).as_singleton() { + buffers.push(buffer); + } + } buffers }