From d157e3598d2431b6a6aadd4fdd16ffc0897b51ad Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 3 Aug 2023 19:27:27 +0200 Subject: [PATCH] Query semantic_permissioned on demand. Co-authored-by: Kyle --- crates/search/src/project_search.rs | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 1a2320bda3..014ec13197 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -129,7 +129,7 @@ pub struct ProjectSearchView { query_editor: ViewHandle, results_editor: ViewHandle, semantic_state: Option, - semantic_permissioned: bool, + semantic_permissioned: Option, search_options: SearchOptions, panels_with_errors: HashSet, active_match_index: Option, @@ -763,7 +763,7 @@ impl ProjectSearchView { SearchMode::Semantic => { // let semantic_permissioned = self.semantic_permissioned.await; // if semantic_permissioned.is_ok_and(|permission| !permission) { - if !self.semantic_permissioned { + if !self.semantic_permissioned(cx) { // TODO: Change this to read from the project name let project = self.model.read(cx).project.clone(); let project_name = project @@ -786,7 +786,7 @@ impl ProjectSearchView { cx.spawn(|search_view, mut cx| async move { if answer.next().await == Some(0) { search_view.update(&mut cx, |search_view, cx| { - search_view.semantic_permissioned = true; + search_view.semantic_permissioned = Some(true); search_view.index_project(cx); })?; anyhow::Ok(()) @@ -901,14 +901,6 @@ impl ProjectSearchView { }) .detach(); let filters_enabled = false; - let semantic_permissioned = SemanticIndex::global(cx) - .and_then(|semantic| { - smol::block_on( - semantic.update(cx, |this, cx| this.project_previously_indexed(project, cx)), - ) - .ok() - }) - .unwrap_or_default(); // Check if Worktrees have all been previously indexed let mut this = ProjectSearchView { @@ -917,7 +909,7 @@ impl ProjectSearchView { query_editor, results_editor, semantic_state: None, - semantic_permissioned, + semantic_permissioned: None, search_options: options, panels_with_errors: HashSet::new(), active_match_index: None, @@ -930,7 +922,20 @@ impl ProjectSearchView { this.model_changed(cx); this } - + fn semantic_permissioned(&mut self, cx: &mut ViewContext) -> bool { + *self.semantic_permissioned.get_or_insert_with(|| { + SemanticIndex::global(cx) + .and_then(|semantic| { + let project = self.model.read(cx).project.clone(); + smol::block_on( + semantic + .update(cx, |this, cx| this.project_previously_indexed(project, cx)), + ) + .ok() + }) + .unwrap_or_default() + }) + } pub fn new_search_in_directory( workspace: &mut Workspace, dir_entry: &Entry,