From a3513fb2b2abb28997c9f95b253ff37c7080f903 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 21 May 2025 10:20:54 +0200 Subject: [PATCH] chore: Make terminal_view own the TerminalSlashCommand This reduces 'touch crates/editor/src/editor.rs && cargo +nightly build' from 8.9s to 8.5s. That same scenario used to take 8s less than a week ago. :) --- Cargo.lock | 3 ++- crates/agent/src/agent.rs | 1 - .../src/assistant_slash_command.rs | 14 ++++++++++++++ crates/assistant_slash_commands/Cargo.toml | 1 - .../src/assistant_slash_commands.rs | 18 +----------------- crates/eval/Cargo.toml | 1 + crates/eval/src/eval.rs | 1 + crates/terminal_view/Cargo.toml | 1 + .../src/terminal_slash_command.rs} | 4 ++-- crates/terminal_view/src/terminal_view.rs | 5 +++++ 10 files changed, 27 insertions(+), 22 deletions(-) rename crates/{assistant_slash_commands/src/terminal_command.rs => terminal_view/src/terminal_slash_command.rs} (96%) diff --git a/Cargo.lock b/Cargo.lock index 4a0d318944..5d3571af93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -611,7 +611,6 @@ dependencies = [ "serde_json", "settings", "smol", - "terminal_view", "text", "toml 0.8.20", "ui", @@ -5016,6 +5015,7 @@ dependencies = [ "shellexpand 2.1.2", "smol", "telemetry", + "terminal_view", "toml 0.8.20", "unindent", "util", @@ -15616,6 +15616,7 @@ name = "terminal_view" version = "0.1.0" dependencies = [ "anyhow", + "assistant_slash_command", "async-recursion 1.1.1", "breadcrumbs", "client", diff --git a/crates/agent/src/agent.rs b/crates/agent/src/agent.rs index 352a699443..95ceb26c4f 100644 --- a/crates/agent/src/agent.rs +++ b/crates/agent/src/agent.rs @@ -217,7 +217,6 @@ fn register_slash_commands(cx: &mut App) { slash_command_registry.register_command(assistant_slash_commands::PromptSlashCommand, true); slash_command_registry.register_command(assistant_slash_commands::SelectionCommand, true); slash_command_registry.register_command(assistant_slash_commands::DefaultSlashCommand, false); - slash_command_registry.register_command(assistant_slash_commands::TerminalSlashCommand, true); slash_command_registry.register_command(assistant_slash_commands::NowSlashCommand, false); slash_command_registry .register_command(assistant_slash_commands::DiagnosticsSlashCommand, true); diff --git a/crates/assistant_slash_command/src/assistant_slash_command.rs b/crates/assistant_slash_command/src/assistant_slash_command.rs index ce8318ba12..828f115bf5 100644 --- a/crates/assistant_slash_command/src/assistant_slash_command.rs +++ b/crates/assistant_slash_command/src/assistant_slash_command.rs @@ -9,6 +9,7 @@ use anyhow::Result; use futures::StreamExt; use futures::stream::{self, BoxStream}; use gpui::{App, SharedString, Task, WeakEntity, Window}; +use language::HighlightId; use language::{BufferSnapshot, CodeLabel, LspAdapterDelegate, OffsetRangeExt}; pub use language_model::Role; use serde::{Deserialize, Serialize}; @@ -16,6 +17,7 @@ use std::{ ops::Range, sync::{Arc, atomic::AtomicBool}, }; +use ui::ActiveTheme; use workspace::{Workspace, ui::IconName}; pub fn init(cx: &mut App) { @@ -325,6 +327,18 @@ impl SlashCommandLine { } } +pub fn create_label_for_command(command_name: &str, arguments: &[&str], cx: &App) -> CodeLabel { + let mut label = CodeLabel::default(); + label.push_str(command_name, None); + label.push_str(" ", None); + label.push_str( + &arguments.join(" "), + cx.theme().syntax().highlight_id("comment").map(HighlightId), + ); + label.filter_range = 0..command_name.len(); + label +} + #[cfg(test)] mod tests { use pretty_assertions::assert_eq; diff --git a/crates/assistant_slash_commands/Cargo.toml b/crates/assistant_slash_commands/Cargo.toml index 322e41fdef..92433d905f 100644 --- a/crates/assistant_slash_commands/Cargo.toml +++ b/crates/assistant_slash_commands/Cargo.toml @@ -35,7 +35,6 @@ rope.workspace = true serde.workspace = true serde_json.workspace = true smol.workspace = true -terminal_view.workspace = true text.workspace = true toml.workspace = true ui.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 6ece60dcd3..fa5dd8b683 100644 --- a/crates/assistant_slash_commands/src/assistant_slash_commands.rs +++ b/crates/assistant_slash_commands/src/assistant_slash_commands.rs @@ -12,11 +12,6 @@ mod selection_command; mod streaming_example_command; mod symbols_command; mod tab_command; -mod terminal_command; - -use gpui::App; -use language::{CodeLabel, HighlightId}; -use ui::ActiveTheme as _; pub use crate::cargo_workspace_command::*; pub use crate::context_server_command::*; @@ -32,16 +27,5 @@ pub use crate::selection_command::*; pub use crate::streaming_example_command::*; pub use crate::symbols_command::*; pub use crate::tab_command::*; -pub use crate::terminal_command::*; -pub fn create_label_for_command(command_name: &str, arguments: &[&str], cx: &App) -> CodeLabel { - let mut label = CodeLabel::default(); - label.push_str(command_name, None); - label.push_str(" ", None); - label.push_str( - &arguments.join(" "), - cx.theme().syntax().highlight_id("comment").map(HighlightId), - ); - label.filter_range = 0..command_name.len(); - label -} +use assistant_slash_command::create_label_for_command; diff --git a/crates/eval/Cargo.toml b/crates/eval/Cargo.toml index 0a5779a66a..408463b1bc 100644 --- a/crates/eval/Cargo.toml +++ b/crates/eval/Cargo.toml @@ -61,6 +61,7 @@ settings.workspace = true shellexpand.workspace = true smol.workspace = true telemetry.workspace = true +terminal_view.workspace = true toml.workspace = true unindent.workspace = true util.workspace = true diff --git a/crates/eval/src/eval.rs b/crates/eval/src/eval.rs index 5a05cc9b46..f42d138f28 100644 --- a/crates/eval/src/eval.rs +++ b/crates/eval/src/eval.rs @@ -424,6 +424,7 @@ pub fn init(cx: &mut App) -> Arc { language_models::init(user_store.clone(), client.clone(), fs.clone(), cx); languages::init(languages.clone(), node_runtime.clone(), cx); prompt_store::init(cx); + terminal_view::init(cx); let stdout_is_a_pty = false; let prompt_builder = PromptBuilder::load(fs.clone(), stdout_is_a_pty, cx); agent::init( diff --git a/crates/terminal_view/Cargo.toml b/crates/terminal_view/Cargo.toml index 2096e25fbd..e424d89917 100644 --- a/crates/terminal_view/Cargo.toml +++ b/crates/terminal_view/Cargo.toml @@ -18,6 +18,7 @@ doctest = false [dependencies] anyhow.workspace = true async-recursion.workspace = true +assistant_slash_command.workspace = true breadcrumbs.workspace = true collections.workspace = true db.workspace = true diff --git a/crates/assistant_slash_commands/src/terminal_command.rs b/crates/terminal_view/src/terminal_slash_command.rs similarity index 96% rename from crates/assistant_slash_commands/src/terminal_command.rs rename to crates/terminal_view/src/terminal_slash_command.rs index b521e10f72..ac86eef2bc 100644 --- a/crates/assistant_slash_commands/src/terminal_command.rs +++ b/crates/terminal_view/src/terminal_slash_command.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use std::sync::atomic::AtomicBool; +use crate::{TerminalView, terminal_panel::TerminalPanel}; use anyhow::Result; use assistant_slash_command::{ ArgumentCompletion, SlashCommand, SlashCommandOutput, SlashCommandOutputSection, @@ -8,11 +9,10 @@ use assistant_slash_command::{ }; use gpui::{App, Entity, Task, WeakEntity}; use language::{BufferSnapshot, CodeLabel, LspAdapterDelegate}; -use terminal_view::{TerminalView, terminal_panel::TerminalPanel}; use ui::prelude::*; use workspace::{Workspace, dock::Panel}; -use super::create_label_for_command; +use assistant_slash_command::create_label_for_command; pub struct TerminalSlashCommand; diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index b1fb060db1..e0d6b3d56f 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -2,8 +2,10 @@ mod persistence; pub mod terminal_element; pub mod terminal_panel; pub mod terminal_scrollbar; +mod terminal_slash_command; pub mod terminal_tab_tooltip; +use assistant_slash_command::SlashCommandRegistry; use editor::{Editor, EditorSettings, actions::SelectAll, scroll::ScrollbarAutoHide}; use gpui::{ AnyElement, App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, KeyContext, @@ -29,6 +31,7 @@ use terminal::{ use terminal_element::{TerminalElement, is_blank}; use terminal_panel::TerminalPanel; use terminal_scrollbar::TerminalScrollHandle; +use terminal_slash_command::TerminalSlashCommand; use terminal_tab_tooltip::TerminalTooltip; use ui::{ ContextMenu, Icon, IconName, Label, Scrollbar, ScrollbarState, Tooltip, h_flex, prelude::*, @@ -78,6 +81,7 @@ actions!(terminal, [RerunTask]); impl_actions!(terminal, [SendText, SendKeystroke]); pub fn init(cx: &mut App) { + assistant_slash_command::init(cx); terminal_panel::init(cx); terminal::init(cx); @@ -87,6 +91,7 @@ pub fn init(cx: &mut App) { workspace.register_action(TerminalView::deploy); }) .detach(); + SlashCommandRegistry::global(cx).register_command(TerminalSlashCommand, true); } pub struct BlockProperties {