From 6885b28c22a9ed1c8e54b7e37a7a49040e7de0c4 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Tue, 18 Feb 2025 18:29:12 -0300 Subject: [PATCH] assistant2: Deploy inline assistant in PromptEditor (#25094) Release Notes: - N/A Co-authored-by: Danilo Leal --- crates/assistant2/src/assistant_panel.rs | 4 ++++ crates/assistant2/src/inline_assistant.rs | 24 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/assistant2/src/assistant_panel.rs b/crates/assistant2/src/assistant_panel.rs index f32104867a..e12100907f 100644 --- a/crates/assistant2/src/assistant_panel.rs +++ b/crates/assistant2/src/assistant_panel.rs @@ -478,6 +478,10 @@ impl AssistantPanel { .update(cx, |this, cx| this.delete_thread(thread_id, cx)) .detach_and_log_err(cx); } + + pub(crate) fn active_context_editor(&self) -> Option> { + self.context_editor.clone() + } } impl Focusable for AssistantPanel { diff --git a/crates/assistant2/src/inline_assistant.rs b/crates/assistant2/src/inline_assistant.rs index 1f2189df82..6d76526d06 100644 --- a/crates/assistant2/src/inline_assistant.rs +++ b/crates/assistant2/src/inline_assistant.rs @@ -228,8 +228,12 @@ impl InlineAssistant { return; } - let Some(inline_assist_target) = Self::resolve_inline_assist_target(workspace, window, cx) - else { + let Some(inline_assist_target) = Self::resolve_inline_assist_target( + workspace, + workspace.panel::(cx), + window, + cx, + ) else { return; }; @@ -1383,6 +1387,7 @@ impl InlineAssistant { fn resolve_inline_assist_target( workspace: &mut Workspace, + assistant_panel: Option>, window: &mut Window, cx: &mut App, ) -> Option { @@ -1402,7 +1407,20 @@ impl InlineAssistant { } } - if let Some(workspace_editor) = workspace + let context_editor = assistant_panel + .and_then(|panel| panel.read(cx).active_context_editor()) + .and_then(|editor| { + let editor = &editor.read(cx).editor().clone(); + if editor.read(cx).is_focused(window) { + Some(editor.clone()) + } else { + None + } + }); + + if let Some(context_editor) = context_editor { + Some(InlineAssistTarget::Editor(context_editor)) + } else if let Some(workspace_editor) = workspace .active_item(cx) .and_then(|item| item.act_as::(cx)) {