create initial action for Semantic search mode

This commit is contained in:
KCaverly 2023-09-20 09:48:27 -04:00
parent a366ad02ce
commit 912e6e8091
3 changed files with 27 additions and 4 deletions

View File

@ -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::<ToggleCaseSensitive>(SearchOptions::CASE_SENSITIVE, cx);
@ -1348,6 +1354,23 @@ impl ProjectSearchBar {
}
}
fn activate_semantic_mode(
pane: &mut Pane,
_: &ActivateSemanticMode,
cx: &mut ViewContext<Pane>,
) {
if let Some(search_view) = pane
.active_item()
.and_then(|item| item.downcast::<ProjectSearchView>())
{
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<Self>) -> bool {
if let Some(search_view) = self.active_project_search.as_ref() {
search_view.update(cx, |search_view, cx| {

View File

@ -39,7 +39,7 @@ actions!(
ActivateSemanticMode,
ActivateRegexMode,
ReplaceAll,
ReplaceNext
ReplaceNext,
]
);

View File

@ -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);