From 912e6e809191ed338ee8467630112c7e608ce0bf Mon Sep 17 00:00:00 2001 From: KCaverly Date: Wed, 20 Sep 2023 09:48:27 -0400 Subject: [PATCH] create initial action for Semantic search mode --- crates/search/src/project_search.rs | 27 +++++++++++++++++++++++++-- crates/search/src/search.rs | 2 +- crates/zed/src/main.rs | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 1944219117..eca99fa16d 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -2,8 +2,8 @@ use crate::{ history::SearchHistory, mode::{SearchMode, Side}, search_bar::{render_nav_button, render_option_button_icon, render_search_mode_button}, - ActivateRegexMode, CycleMode, NextHistoryQuery, PreviousHistoryQuery, SearchOptions, - SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, + ActivateRegexMode, ActivateSemanticMode, CycleMode, NextHistoryQuery, PreviousHistoryQuery, + SearchOptions, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, }; use anyhow::{Context, Result}; use collections::HashMap; @@ -63,6 +63,12 @@ pub fn init(cx: &mut AppContext) { cx.add_action(ProjectSearchBar::next_history_query); cx.add_action(ProjectSearchBar::previous_history_query); cx.add_action(ProjectSearchBar::activate_regex_mode); + + // This action should only be registered if the semantic index is enabled + if SemanticIndex::enabled(cx) { + cx.add_action(ProjectSearchBar::activate_semantic_mode); + } + cx.capture_action(ProjectSearchBar::tab); cx.capture_action(ProjectSearchBar::tab_previous); add_toggle_option_action::(SearchOptions::CASE_SENSITIVE, cx); @@ -1348,6 +1354,23 @@ impl ProjectSearchBar { } } + fn activate_semantic_mode( + pane: &mut Pane, + _: &ActivateSemanticMode, + cx: &mut ViewContext, + ) { + if let Some(search_view) = pane + .active_item() + .and_then(|item| item.downcast::()) + { + search_view.update(cx, |view, cx| { + view.activate_search_mode(SearchMode::Semantic, cx) + }); + } else { + cx.propagate_action(); + } + } + fn toggle_filters(&mut self, cx: &mut ViewContext) -> bool { if let Some(search_view) = self.active_project_search.as_ref() { search_view.update(cx, |search_view, cx| { diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index dabbc720ce..ba06b3f9c7 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -39,7 +39,7 @@ actions!( ActivateSemanticMode, ActivateRegexMode, ReplaceAll, - ReplaceNext + ReplaceNext, ] ); diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index d22e26c1f5..98bf600a61 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -156,8 +156,8 @@ fn main() { project_panel::init(Assets, cx); channel::init(&client); diagnostics::init(cx); - search::init(cx); semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx); + search::init(cx); vim::init(cx); terminal_view::init(cx); copilot::init(copilot_language_server_id, http.clone(), node_runtime, cx);