diff --git a/crates/agent_ui/src/acp/completion_provider.rs b/crates/agent_ui/src/acp/completion_provider.rs index 8cbae5a5420a2f89d0f7ca478ae77a5d5d350411..40ac1aae99704c2b800a5b6cb6ccc71c426dbbe9 100644 --- a/crates/agent_ui/src/acp/completion_provider.rs +++ b/crates/agent_ui/src/acp/completion_provider.rs @@ -27,7 +27,7 @@ use util::rel_path::RelPath; use workspace::Workspace; use crate::AgentPanel; -use crate::acp::message_editor::{MessageEditor, MessageEditorEvent}; +use crate::acp::message_editor::MessageEditor; use crate::context_picker::file_context_picker::{FileMatch, search_files}; use crate::context_picker::rules_context_picker::{RulesContextEntry, search_rules}; use crate::context_picker::symbol_context_picker::SymbolMatch; @@ -759,13 +759,13 @@ impl CompletionProvider for ContextPickerCompletionProvider { let editor = editor.clone(); move |cx| { editor - .update(cx, |_editor, cx| { + .update(cx, |editor, cx| { match intent { CompletionIntent::Complete | CompletionIntent::CompleteWithInsert | CompletionIntent::CompleteWithReplace => { if !is_missing_argument { - cx.emit(MessageEditorEvent::Send); + editor.send(cx); } } CompletionIntent::Compose => {} diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rs index 626c9f3bb7bc3d9c146f584bb9acbc999c25c879..d16e22b662a2dfeff0f9991fe5680756b6d02877 100644 --- a/crates/agent_ui/src/acp/message_editor.rs +++ b/crates/agent_ui/src/acp/message_editor.rs @@ -141,7 +141,9 @@ impl MessageEditor { subscriptions.push(cx.subscribe_in(&editor, window, { move |this, editor, event, window, cx| { - if let EditorEvent::Edited { .. } = event { + if let EditorEvent::Edited { .. } = event + && !editor.read(cx).read_only(cx) + { let snapshot = editor.update(cx, |editor, cx| { let new_hints = this .command_hint(editor.buffer(), cx) @@ -823,13 +825,20 @@ impl MessageEditor { }); } - fn send(&mut self, _: &Chat, _: &mut Window, cx: &mut Context) { + pub fn send(&mut self, cx: &mut Context) { if self.is_empty(cx) { return; } + self.editor.update(cx, |editor, cx| { + editor.clear_inlay_hints(cx); + }); cx.emit(MessageEditorEvent::Send) } + fn chat(&mut self, _: &Chat, _: &mut Window, cx: &mut Context) { + self.send(cx); + } + fn cancel(&mut self, _: &editor::actions::Cancel, _: &mut Window, cx: &mut Context) { cx.emit(MessageEditorEvent::Cancel) } @@ -1288,7 +1297,7 @@ impl Render for MessageEditor { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { div() .key_context("MessageEditor") - .on_action(cx.listener(Self::send)) + .on_action(cx.listener(Self::chat)) .on_action(cx.listener(Self::cancel)) .capture_action(cx.listener(Self::paste)) .flex_1() diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5b609301da326c7fe64964afb3eba29d96af8807..01dd446bed4523405585c21128b43adc60362268 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5243,15 +5243,7 @@ impl Editor { if enabled { (InvalidationStrategy::RefreshRequested, None) } else { - self.splice_inlays( - &self - .visible_inlay_hints(cx) - .iter() - .map(|inlay| inlay.id) - .collect::>(), - Vec::new(), - cx, - ); + self.clear_inlay_hints(cx); return; } } @@ -5263,15 +5255,7 @@ impl Editor { if enabled { (InvalidationStrategy::RefreshRequested, None) } else { - self.splice_inlays( - &self - .visible_inlay_hints(cx) - .iter() - .map(|inlay| inlay.id) - .collect::>(), - Vec::new(), - cx, - ); + self.clear_inlay_hints(cx); return; } } else { @@ -5282,7 +5266,7 @@ impl Editor { match self.inlay_hint_cache.update_settings( &self.buffer, new_settings, - self.visible_inlay_hints(cx), + self.visible_inlay_hints(cx).cloned().collect::>(), cx, ) { ControlFlow::Break(Some(InlaySplice { @@ -5332,13 +5316,25 @@ impl Editor { } } - fn visible_inlay_hints(&self, cx: &Context) -> Vec { + pub fn clear_inlay_hints(&self, cx: &mut Context) { + self.splice_inlays( + &self + .visible_inlay_hints(cx) + .map(|inlay| inlay.id) + .collect::>(), + Vec::new(), + cx, + ); + } + + fn visible_inlay_hints<'a>( + &'a self, + cx: &'a Context, + ) -> impl Iterator { self.display_map .read(cx) .current_inlays() .filter(move |inlay| matches!(inlay.id, InlayId::Hint(_))) - .cloned() - .collect() } pub fn visible_excerpts( diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rs index d2073633dd149f9536838732f25ee89aa630a57c..9b6247a9715b9431530177032a8adfaedfe6f53e 100644 --- a/crates/editor/src/hover_links.rs +++ b/crates/editor/src/hover_links.rs @@ -307,7 +307,6 @@ pub fn update_inlay_link_and_hover_points( buffer_snapshot.anchor_after(point_for_position.next_valid.to_point(snapshot)); if let Some(hovered_hint) = editor .visible_inlay_hints(cx) - .into_iter() .skip_while(|hint| { hint.position .cmp(&previous_valid_anchor, &buffer_snapshot) diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index 9a1e07ba3946d0f2b05e2096201287334dd02534..fe2ab972ef6920a8530b493d09f7d0e279e147a5 100644 --- a/crates/editor/src/inlay_hint_cache.rs +++ b/crates/editor/src/inlay_hint_cache.rs @@ -1013,7 +1013,7 @@ fn fetch_and_update_hints( .cloned() })?; - let visible_hints = editor.update(cx, |editor, cx| editor.visible_inlay_hints(cx))?; + let visible_hints = editor.update(cx, |editor, cx| editor.visible_inlay_hints(cx).cloned().collect::>())?; let new_hints = match inlay_hints_fetch_task { Some(fetch_task) => { log::debug!( @@ -3570,7 +3570,6 @@ pub mod tests { pub fn visible_hint_labels(editor: &Editor, cx: &Context) -> Vec { editor .visible_inlay_hints(cx) - .into_iter() .map(|hint| hint.text().to_string()) .collect() }