update project search to only show semantic button visible with semantic_index enabled

This commit is contained in:
KCaverly 2023-07-25 16:26:37 -04:00
parent e8210b827d
commit 75999204ad
2 changed files with 24 additions and 6 deletions

View File

@ -996,6 +996,10 @@ impl ProjectSearchBar {
SearchOption::Regex => &mut search_view.regex, SearchOption::Regex => &mut search_view.regex,
}; };
*value = !*value; *value = !*value;
if value.clone() {
search_view.semantic = None;
}
search_view.search(cx); search_view.search(cx);
}); });
cx.notify(); cx.notify();
@ -1012,6 +1016,9 @@ impl ProjectSearchBar {
search_view.semantic = None; search_view.semantic = None;
} else if let Some(semantic_index) = SemanticIndex::global(cx) { } else if let Some(semantic_index) = SemanticIndex::global(cx) {
// TODO: confirm that it's ok to send this project // TODO: confirm that it's ok to send this project
search_view.regex = false;
search_view.case_sensitive = false;
search_view.whole_word = false;
let project = search_view.model.read(cx).project.clone(); let project = search_view.model.read(cx).project.clone();
let index_task = semantic_index.update(cx, |semantic_index, cx| { let index_task = semantic_index.update(cx, |semantic_index, cx| {
@ -1266,9 +1273,14 @@ impl View for ProjectSearchBar {
.with_child(self.render_nav_button(">", Direction::Next, cx)) .with_child(self.render_nav_button(">", Direction::Next, cx))
.aligned(), .aligned(),
) )
.with_child( .with_child({
Flex::row() let row = if SemanticIndex::enabled(cx) {
.with_child(self.render_semantic_search_button(cx)) Flex::row().with_child(self.render_semantic_search_button(cx))
} else {
Flex::row()
};
let row = row
.with_child(self.render_option_button( .with_child(self.render_option_button(
"Case", "Case",
SearchOption::CaseSensitive, SearchOption::CaseSensitive,
@ -1286,8 +1298,10 @@ impl View for ProjectSearchBar {
)) ))
.contained() .contained()
.with_style(theme.search.option_button_group) .with_style(theme.search.option_button_group)
.aligned(), .aligned();
)
row
})
.contained() .contained()
.with_margin_bottom(row_spacing), .with_margin_bottom(row_spacing),
) )

View File

@ -1,7 +1,7 @@
mod db; mod db;
mod embedding; mod embedding;
mod parsing; mod parsing;
mod semantic_index_settings; pub mod semantic_index_settings;
#[cfg(test)] #[cfg(test)]
mod semantic_index_tests; mod semantic_index_tests;
@ -183,6 +183,10 @@ impl SemanticIndex {
} }
} }
pub fn enabled(cx: &AppContext) -> bool {
settings::get::<SemanticIndexSettings>(cx).enabled
}
async fn new( async fn new(
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
database_url: PathBuf, database_url: PathBuf,