diff --git a/crates/assistant/src/assistant.rs b/crates/assistant/src/assistant.rs index adb560793f650c642f1fbe3ea2077bf86f54ccf0..28be7e98b97dda4c53973d3f23ba340ef2367351 100644 --- a/crates/assistant/src/assistant.rs +++ b/crates/assistant/src/assistant.rs @@ -65,7 +65,7 @@ actions!( ] ); -const DEFAULT_CONTEXT_LINES: usize = 20; +const DEFAULT_CONTEXT_LINES: usize = 50; #[derive(Clone, Default, Deserialize, PartialEq)] pub struct InlineAssist { diff --git a/crates/assistant/src/slash_command/terminal_command.rs b/crates/assistant/src/slash_command/terminal_command.rs index 84e57bb93ad8c9b0b8a00131e9b82e4edc4ae685..6b899493fb620affd69cbee7dc6d6b85d824e13f 100644 --- a/crates/assistant/src/slash_command/terminal_command.rs +++ b/crates/assistant/src/slash_command/terminal_command.rs @@ -5,7 +5,7 @@ use anyhow::Result; use assistant_slash_command::{ ArgumentCompletion, SlashCommand, SlashCommandOutput, SlashCommandOutputSection, }; -use gpui::{AppContext, Task, WeakView}; +use gpui::{AppContext, Task, View, WeakView}; use language::{CodeLabel, LspAdapterDelegate}; use terminal_view::{terminal_panel::TerminalPanel, TerminalView}; use ui::prelude::*; @@ -42,21 +42,12 @@ impl SlashCommand for TerminalSlashCommand { fn complete_argument( self: Arc, - arguments: &[String], + _arguments: &[String], _cancel: Arc, _workspace: Option>, _cx: &mut WindowContext, ) -> Task>> { - let completions = if arguments.iter().any(|arg| arg == LINE_COUNT_ARG) { - Vec::new() - } else { - vec![ArgumentCompletion { - label: LINE_COUNT_ARG.into(), - new_text: LINE_COUNT_ARG.to_string(), - run_command: false, - }] - }; - Task::ready(Ok(completions)) + Task::ready(Ok(Vec::new())) } fn run( @@ -69,24 +60,15 @@ impl SlashCommand for TerminalSlashCommand { let Some(workspace) = workspace.upgrade() else { return Task::ready(Err(anyhow::anyhow!("workspace was dropped"))); }; - let Some(terminal_panel) = workspace.read(cx).panel::(cx) else { - return Task::ready(Err(anyhow::anyhow!("no terminal panel open"))); - }; - let Some(active_terminal) = terminal_panel.read(cx).pane().and_then(|pane| { - pane.read(cx) - .active_item() - .and_then(|t| t.downcast::()) - }) else { + + let Some(active_terminal) = resolve_active_terminal(&workspace, cx) else { return Task::ready(Err(anyhow::anyhow!("no active terminal"))); }; - let mut line_count = DEFAULT_CONTEXT_LINES; - if arguments.get(0).map(|s| s.as_str()) == Some(LINE_COUNT_ARG) { - if let Some(parsed_line_count) = arguments.get(1).and_then(|s| s.parse::().ok()) - { - line_count = parsed_line_count; - } - } + let line_count = arguments + .get(0) + .and_then(|s| s.parse::().ok()) + .unwrap_or(DEFAULT_CONTEXT_LINES); let lines = active_terminal .read(cx) @@ -110,3 +92,23 @@ impl SlashCommand for TerminalSlashCommand { })) } } + +fn resolve_active_terminal( + workspace: &View, + cx: &WindowContext, +) -> Option> { + if let Some(terminal_view) = workspace + .read(cx) + .active_item(cx) + .and_then(|item| item.act_as::(cx)) + { + return Some(terminal_view); + } + + let terminal_panel = workspace.read(cx).panel::(cx)?; + terminal_panel.read(cx).pane().and_then(|pane| { + pane.read(cx) + .active_item() + .and_then(|t| t.downcast::()) + }) +}