From 68d453da52df43390be0d69ab33d42f78a694e43 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 28 Mar 2025 09:40:31 -0400 Subject: [PATCH] assistant: Remove `/search` (#27661) This PR removes the `/search` command. This was feature-flagged and was never released to the general public. Release Notes: - N/A --- Cargo.lock | 3 - crates/assistant/Cargo.toml | 2 - crates/assistant/src/assistant.rs | 37 ---- crates/assistant_slash_commands/Cargo.toml | 1 - .../src/assistant_slash_commands.rs | 2 - .../src/search_command.rs | 181 ------------------ 6 files changed, 226 deletions(-) delete mode 100644 crates/assistant_slash_commands/src/search_command.rs diff --git a/Cargo.lock b/Cargo.lock index c8ce787a0b..24972889bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -413,7 +413,6 @@ dependencies = [ "menu", "multi_buffer", "parking_lot", - "paths", "pretty_assertions", "project", "prompt_library", @@ -423,7 +422,6 @@ dependencies = [ "rope", "schemars", "search", - "semantic_index", "serde", "serde_json_lenient", "settings", @@ -675,7 +673,6 @@ dependencies = [ "project", "prompt_store", "rope", - "semantic_index", "serde", "serde_json", "settings", diff --git a/crates/assistant/Cargo.toml b/crates/assistant/Cargo.toml index 8fbfb43136..c99af4f515 100644 --- a/crates/assistant/Cargo.toml +++ b/crates/assistant/Cargo.toml @@ -48,7 +48,6 @@ lsp.workspace = true menu.workspace = true multi_buffer.workspace = true parking_lot.workspace = true -paths.workspace = true project.workspace = true prompt_library.workspace = true prompt_store.workspace = true @@ -56,7 +55,6 @@ proto.workspace = true rope.workspace = true schemars.workspace = true search.workspace = true -semantic_index.workspace = true serde.workspace = true settings.workspace = true smol.workspace = true diff --git a/crates/assistant/src/assistant.rs b/crates/assistant/src/assistant.rs index ddd9c2974c..a236d1ff72 100644 --- a/crates/assistant/src/assistant.rs +++ b/crates/assistant/src/assistant.rs @@ -10,7 +10,6 @@ use std::sync::Arc; use assistant_settings::AssistantSettings; use assistant_slash_command::SlashCommandRegistry; -use assistant_slash_commands::SearchSlashCommandFeatureFlag; use client::Client; use command_palette_hooks::CommandPaletteFilter; use feature_flags::FeatureFlagAppExt; @@ -20,7 +19,6 @@ use language_model::{ LanguageModelId, LanguageModelProviderId, LanguageModelRegistry, LanguageModelResponseMessage, }; use prompt_store::PromptBuilder; -use semantic_index::{CloudEmbeddingProvider, SemanticDb}; use serde::Deserialize; use settings::{Settings, SettingsStore}; @@ -102,30 +100,6 @@ pub fn init( AssistantSettings::register(cx); SlashCommandSettings::register(cx); - cx.spawn({ - let client = client.clone(); - async move |cx| { - let is_search_slash_command_enabled = cx - .update(|cx| cx.wait_for_flag::())? - .await; - - if !is_search_slash_command_enabled { - return Ok(()); - } - - let embedding_provider = CloudEmbeddingProvider::new(client.clone()); - let semantic_index = SemanticDb::new( - paths::embeddings_dir().join("semantic-index-db.0.mdb"), - Arc::new(embedding_provider), - cx, - ) - .await?; - - cx.update(|cx| cx.set_global(semantic_index)) - } - }) - .detach(); - assistant_context_editor::init(client.clone(), cx); prompt_library::init(cx); init_language_model_settings(cx); @@ -244,17 +218,6 @@ fn register_slash_commands(cx: &mut App) { update_slash_commands_from_settings(cx); cx.observe_global::(update_slash_commands_from_settings) .detach(); - - cx.observe_flag::({ - let slash_command_registry = slash_command_registry.clone(); - move |is_enabled, _cx| { - if is_enabled { - slash_command_registry - .register_command(assistant_slash_commands::SearchSlashCommand, true); - } - } - }) - .detach(); } fn update_slash_commands_from_settings(cx: &mut App) { diff --git a/crates/assistant_slash_commands/Cargo.toml b/crates/assistant_slash_commands/Cargo.toml index aeaf7f1030..680833498e 100644 --- a/crates/assistant_slash_commands/Cargo.toml +++ b/crates/assistant_slash_commands/Cargo.toml @@ -32,7 +32,6 @@ language.workspace = true project.workspace = true prompt_store.workspace = true rope.workspace = true -semantic_index.workspace = true serde.workspace = true serde_json.workspace = true smol.workspace = true diff --git a/crates/assistant_slash_commands/src/assistant_slash_commands.rs b/crates/assistant_slash_commands/src/assistant_slash_commands.rs index b3e5bb045b..6ece60dcd3 100644 --- a/crates/assistant_slash_commands/src/assistant_slash_commands.rs +++ b/crates/assistant_slash_commands/src/assistant_slash_commands.rs @@ -8,7 +8,6 @@ mod fetch_command; mod file_command; mod now_command; mod prompt_command; -mod search_command; mod selection_command; mod streaming_example_command; mod symbols_command; @@ -29,7 +28,6 @@ pub use crate::fetch_command::*; pub use crate::file_command::*; pub use crate::now_command::*; pub use crate::prompt_command::*; -pub use crate::search_command::*; pub use crate::selection_command::*; pub use crate::streaming_example_command::*; pub use crate::symbols_command::*; diff --git a/crates/assistant_slash_commands/src/search_command.rs b/crates/assistant_slash_commands/src/search_command.rs deleted file mode 100644 index 270b0b7424..0000000000 --- a/crates/assistant_slash_commands/src/search_command.rs +++ /dev/null @@ -1,181 +0,0 @@ -use anyhow::Result; -use assistant_slash_command::{ - ArgumentCompletion, SlashCommand, SlashCommandOutput, SlashCommandOutputSection, - SlashCommandResult, -}; -use feature_flags::FeatureFlag; -use gpui::{App, Task, WeakEntity}; -use language::{CodeLabel, LspAdapterDelegate}; -use semantic_index::{LoadedSearchResult, SemanticDb}; -use std::{ - fmt::Write, - sync::{atomic::AtomicBool, Arc}, -}; -use ui::{prelude::*, IconName}; -use workspace::Workspace; - -use crate::create_label_for_command; -use crate::file_command::{build_entry_output_section, codeblock_fence_for_path}; - -pub struct SearchSlashCommandFeatureFlag; - -impl FeatureFlag for SearchSlashCommandFeatureFlag { - const NAME: &'static str = "search-slash-command"; - - fn enabled_for_staff() -> bool { - false - } -} - -pub struct SearchSlashCommand; - -impl SlashCommand for SearchSlashCommand { - fn name(&self) -> String { - "search".into() - } - - fn label(&self, cx: &App) -> CodeLabel { - create_label_for_command("search", &["--n"], cx) - } - - fn description(&self) -> String { - "Search your project semantically".into() - } - - fn icon(&self) -> IconName { - IconName::SearchCode - } - - fn menu_text(&self) -> String { - self.description() - } - - fn requires_argument(&self) -> bool { - true - } - - fn complete_argument( - self: Arc, - _arguments: &[String], - _cancel: Arc, - _workspace: Option>, - _window: &mut Window, - _cx: &mut App, - ) -> Task>> { - Task::ready(Ok(Vec::new())) - } - - fn run( - self: Arc, - arguments: &[String], - _context_slash_command_output_sections: &[SlashCommandOutputSection], - _context_buffer: language::BufferSnapshot, - workspace: WeakEntity, - _delegate: Option>, - window: &mut Window, - cx: &mut App, - ) -> Task { - let Some(workspace) = workspace.upgrade() else { - return Task::ready(Err(anyhow::anyhow!("workspace was dropped"))); - }; - if arguments.is_empty() { - return Task::ready(Err(anyhow::anyhow!("missing search query"))); - }; - - let mut limit = None; - let mut query = String::new(); - for part in arguments { - if let Some(parameter) = part.strip_prefix("--") { - if let Ok(count) = parameter.parse::() { - limit = Some(count); - continue; - } - } - - query.push_str(part); - query.push(' '); - } - query.pop(); - - if query.is_empty() { - return Task::ready(Err(anyhow::anyhow!("missing search query"))); - } - - let project = workspace.read(cx).project().clone(); - let fs = project.read(cx).fs().clone(); - let Some(project_index) = - cx.update_global(|index: &mut SemanticDb, cx| index.project_index(project, cx)) - else { - return Task::ready(Err(anyhow::anyhow!("no project indexer"))); - }; - - window.spawn(cx, async move |cx| { - let results = project_index - .read_with(cx, |project_index, cx| { - project_index.search(vec![query.clone()], limit.unwrap_or(5), cx) - })? - .await?; - - let loaded_results = SemanticDb::load_results(results, &fs, &cx).await?; - - let output = cx - .background_spawn(async move { - let mut text = format!("Search results for {query}:\n"); - let mut sections = Vec::new(); - for loaded_result in &loaded_results { - add_search_result_section(loaded_result, &mut text, &mut sections); - } - - let query = SharedString::from(query); - sections.push(SlashCommandOutputSection { - range: 0..text.len(), - icon: IconName::MagnifyingGlass, - label: query, - metadata: None, - }); - - SlashCommandOutput { - text, - sections, - run_commands_in_text: false, - } - .to_event_stream() - }) - .await; - - Ok(output) - }) - } -} - -pub fn add_search_result_section( - loaded_result: &LoadedSearchResult, - text: &mut String, - sections: &mut Vec>, -) { - let LoadedSearchResult { - path, - full_path, - excerpt_content, - row_range, - .. - } = loaded_result; - let section_start_ix = text.len(); - text.push_str(&codeblock_fence_for_path( - Some(&path), - Some(row_range.clone()), - )); - - text.push_str(&excerpt_content); - if !text.ends_with('\n') { - text.push('\n'); - } - writeln!(text, "```\n").unwrap(); - let section_end_ix = text.len() - 1; - sections.push(build_entry_output_section( - section_start_ix..section_end_ix, - Some(&full_path), - false, - Some(row_range.start() + 1..row_range.end() + 1), - )); -}