Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

catch up with main

KCaverlya125e318fee7
diff --cc assets/keymaps/default.json
index 590e0d6234d,38ec8ffb405..9fbe89975fd
--- a/assets/keymaps/default.json
+++ b/assets/keymaps/default.json
@@@ -229,10 -237,16 +237,17 @@@
{
"context": "ProjectSearchBar",
"bindings": {
- "escape": "project_search::ToggleFocus"
+ "escape": "project_search::ToggleFocus",
+ "alt-tab": "project_search::CycleMode",
}
},
+ {
+ "context": "ProjectSearchBar > Editor",
+ "bindings": {
+ "up": "search::PreviousHistoryQuery",
+ "down": "search::NextHistoryQuery"
+ }
+ },
{
"context": "ProjectSearchView",
"bindings": {
diff --cc crates/search/src/project_search.rs
index d3cefa1af1a,1b4e32f4b83..32a301d4f3b
--- a/crates/search/src/project_search.rs
+++ b/crates/search/src/project_search.rs
@@@ -1,19 -1,14 +1,19 @@@
use crate::{
- SearchOptions, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord,
+ NextHistoryQuery, PreviousHistoryQuery, SearchHistory, SearchOptions, SelectNextMatch,
- SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, ToggleWholeWord,
++ SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord,
};
- use anyhow::Result;
+ use anyhow::Context;
use collections::HashMap;
use editor::{
items::active_match_index, scroll::autoscroll::Autoscroll, Anchor, Editor, MultiBuffer,
SelectAll, MAX_TAB_TITLE_LEN,
};
use futures::StreamExt;
- use globset::{Glob, GlobMatcher};
+use gpui::color::Color;
+use gpui::geometry::rect::RectF;
+use gpui::geometry::vector::IntoVector2F;
+use gpui::json::{self, ToJson};
+use gpui::SceneBuilder;
use gpui::{
actions,
elements::*,
@@@ -21,10 -16,12 +21,13 @@@
Action, AnyElement, AnyViewHandle, AppContext, Entity, ModelContext, ModelHandle, Subscription,
Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
};
+use gpui::{scene::Path, LayoutContext};
use menu::Confirm;
use postage::stream::Stream;
- use project::{search::SearchQuery, Entry, Project};
+ use project::{
+ search::{PathMatcher, SearchQuery},
+ Entry, Project,
+ };
use semantic_index::SemanticIndex;
use smallvec::SmallVec;
use std::{
@@@ -68,7 -56,8 +71,9 @@@ pub fn init(cx: &mut AppContext)
cx.add_action(ProjectSearchBar::search_in_new);
cx.add_action(ProjectSearchBar::select_next_match);
cx.add_action(ProjectSearchBar::select_prev_match);
+ cx.add_action(ProjectSearchBar::cycle_mode);
+ cx.add_action(ProjectSearchBar::next_history_query);
+ cx.add_action(ProjectSearchBar::previous_history_query);
cx.capture_action(ProjectSearchBar::tab);
cx.capture_action(ProjectSearchBar::tab_previous);
add_toggle_option_action::<ToggleCaseSensitive>(SearchOptions::CASE_SENSITIVE, cx);
@@@ -369,74 -267,73 +373,117 @@@ impl View for ProjectSearchView
enum Status {}
let theme = theme::current(cx).clone();
- let text = if model.pending_search.is_some() {
+
+ // If Search is Active -> Major: Searching..., Minor: None
+ // If Semantic -> Major: "Search using Natural Language", Minor: {Status}/n{ex...}/n{ex...}
+ // If Regex -> Major: "Search using Regex", Minor: {ex...}
+ // If Text -> Major: "Text search all files and folders", Minor: {...}
+
+ let current_mode = self.current_mode;
+ let major_text = if model.pending_search.is_some() {
Cow::Borrowed("Searching...")
- } else if let Some(semantic) = &self.semantic {
+ } else {
+ match current_mode {
+ SearchMode::Text => Cow::Borrowed("Text search all files and folders"),
+ SearchMode::Semantic => {
+ Cow::Borrowed("Search all files and folders using Natural Language")
+ }
+ SearchMode::Regex => Cow::Borrowed("Regex search all files and folders"),
+ }
+ };
+
+ let semantic_status = if let Some(semantic) = &self.semantic {
if semantic.outstanding_file_count > 0 {
- Cow::Owned(format!(
- "Indexing. {} of {}...",
+ let dots_count = semantic.outstanding_file_count % 3 + 1;
+ let dots: String = std::iter::repeat('.').take(dots_count).collect();
+ format!(
+ "Indexing: {} of {}{dots}",
semantic.file_count - semantic.outstanding_file_count,
semantic.file_count
- ))
+ )
} else {
- Cow::Borrowed("Indexing complete")
+ "Indexing complete".to_string()
}
- } else if self.query_editor.read(cx).text(cx).is_empty() {
- Cow::Borrowed("")
} else {
- Cow::Borrowed("No results")
+ "Indexing: ...".to_string()
+ };
+
+ let minor_text = match current_mode {
+ SearchMode::Semantic => [
+ semantic_status,
+ "ex. 'list all available languages'".to_owned(),
+ ],
+ _ => [
+ "Include/exclude specific paths with the filter option.".to_owned(),
+ "Matching exact word and/or casing is available too.".to_owned(),
+ ],
};
+ let previous_query_keystrokes =
+ cx.binding_for_action(&PreviousHistoryQuery {})
+ .map(|binding| {
+ binding
+ .keystrokes()
+ .iter()
+ .map(|k| k.to_string())
+ .collect::<Vec<_>>()
+ });
+ let next_query_keystrokes =
+ cx.binding_for_action(&NextHistoryQuery {}).map(|binding| {
+ binding
+ .keystrokes()
+ .iter()
+ .map(|k| k.to_string())
+ .collect::<Vec<_>>()
+ });
+ let new_placeholder_text = match (previous_query_keystrokes, next_query_keystrokes) {
+ (Some(previous_query_keystrokes), Some(next_query_keystrokes)) => {
+ format!(
+ "Search ({}/{} for previous/next query)",
+ previous_query_keystrokes.join(" "),
+ next_query_keystrokes.join(" ")
+ )
+ }
+ (None, Some(next_query_keystrokes)) => {
+ format!(
+ "Search ({} for next query)",
+ next_query_keystrokes.join(" ")
+ )
+ }
+ (Some(previous_query_keystrokes), None) => {
+ format!(
+ "Search ({} for previous query)",
+ previous_query_keystrokes.join(" ")
+ )
+ }
+ (None, None) => String::new(),
+ };
+ self.query_editor.update(cx, |editor, cx| {
+ editor.set_placeholder_text(new_placeholder_text, cx);
+ });
+
MouseEventHandler::<Status, _>::new(0, cx, |_, _| {
- Label::new(text, theme.search.results_status.clone())
- .aligned()
+ Flex::column()
+ .with_child(Flex::column().contained().flex(1., true))
+ .with_child(
+ Flex::column()
+ .align_children_center()
+ .with_child(Label::new(
+ major_text,
+ theme.search.major_results_status.clone(),
+ ))
+ .with_children(
+ minor_text.into_iter().map(|x| {
+ Label::new(x, theme.search.minor_results_status.clone())
+ }),
+ )
+ .aligned()
+ .top()
+ .contained()
+ .flex(7., true),
+ )
.contained()
.with_background_color(theme.editor.background)
- .flex(1., true)
})
.on_down(MouseButton::Left, |_, _, cx| {
cx.focus_parent();
@@@ -641,69 -528,6 +688,72 @@@ impl Item for ProjectSearchView
}
impl ProjectSearchView {
++ fn toggle_search_option(&mut self, option: SearchOptions) {
++ self.search_options.toggle(option);
++ }
+ fn activate_search_mode(&mut self, mode: SearchMode, cx: &mut ViewContext<Self>) {
+ self.model.update(cx, |model, _| model.kill_search());
+ self.current_mode = mode;
+
+ match mode {
+ SearchMode::Semantic => {
+ if let Some(semantic_index) = SemanticIndex::global(cx) {
+ // Semantic search uses no options
+ self.search_options = SearchOptions::none();
+
+ let project = self.model.read(cx).project.clone();
+ let index_task = semantic_index.update(cx, |semantic_index, cx| {
+ semantic_index.index_project(project, cx)
+ });
+
+ cx.spawn(|search_view, mut cx| async move {
+ let (files_to_index, mut files_remaining_rx) = index_task.await?;
+
+ search_view.update(&mut cx, |search_view, cx| {
+ cx.notify();
+ search_view.semantic = Some(SemanticSearchState {
+ file_count: files_to_index,
+ outstanding_file_count: files_to_index,
+ _progress_task: cx.spawn(|search_view, mut cx| async move {
+ while let Some(count) = files_remaining_rx.recv().await {
+ search_view
+ .update(&mut cx, |search_view, cx| {
+ if let Some(semantic_search_state) =
+ &mut search_view.semantic
+ {
+ semantic_search_state.outstanding_file_count =
+ count;
+ cx.notify();
+ if count == 0 {
+ return;
+ }
+ }
+ })
+ .ok();
+ }
+ }),
+ });
+ })?;
+ anyhow::Ok(())
+ })
+ .detach_and_log_err(cx);
+ }
+ }
+ SearchMode::Regex => {
+ if !self.is_option_enabled(SearchOptions::REGEX) {
+ self.toggle_search_option(SearchOptions::REGEX);
+ }
+ self.semantic = None;
+ }
+ SearchMode::Text => {
+ if self.is_option_enabled(SearchOptions::REGEX) {
+ self.toggle_search_option(SearchOptions::REGEX);
+ }
+ self.semantic = None;
+ }
+ }
+ cx.notify();
+ }
fn new(model: ModelHandle<ProjectSearch>, cx: &mut ViewContext<Self>) -> Self {
let project;
let excerpts;
@@@ -883,29 -703,18 +932,26 @@@
}
fn search(&mut self, cx: &mut ViewContext<Self>) {
- if let Some(semantic) = &mut self.semantic {
- if semantic.outstanding_file_count > 0 {
- return;
- }
- if let Some(query) = self.build_search_query(cx) {
- self.model
- .update(cx, |model, cx| model.semantic_search(query, cx));
+ let mode = self.current_mode;
+ match mode {
+ SearchMode::Semantic => {
+ if let Some(semantic) = &mut self.semantic {
+ if semantic.outstanding_file_count > 0 {
+ return;
+ }
+
- let query = self.query_editor.read(cx).text(cx);
- if let Some((included_files, exclude_files)) =
- self.get_included_and_excluded_globsets(cx)
- {
- self.model.update(cx, |model, cx| {
- model.semantic_search(query, included_files, exclude_files, cx)
- });
++ if let Some(query) = self.build_search_query(cx) {
++ self.model
++ .update(cx, |model, cx| model.semantic_search(query, cx));
+ }
+ }
}
- }
+
- if let Some(query) = self.build_search_query(cx) {
- self.model.update(cx, |model, cx| model.search(query, cx));
+ _ => {
+ if let Some(query) = self.build_search_query(cx) {
+ self.model.update(cx, |model, cx| model.search(query, cx));
+ }
+ }
}
}