acp: Fix slash command hint showing up after sending message (#40109)

Release Notes:

- N/A
This commit is contained in:
Bennet Fenner
2025-10-13 17:20:16 +02:00
committed by GitHub
parent 46fff9979d
commit 23fe74ebc5
5 changed files with 34 additions and 31 deletions
@@ -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 => {}
+12 -3
View File
@@ -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<Self>) {
pub fn send(&mut self, cx: &mut Context<Self>) {
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>) {
self.send(cx);
}
fn cancel(&mut self, _: &editor::actions::Cancel, _: &mut Window, cx: &mut Context<Self>) {
cx.emit(MessageEditorEvent::Cancel)
}
@@ -1288,7 +1297,7 @@ impl Render for MessageEditor {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> 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()
+18 -22
View File
@@ -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<InlayId>>(),
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<InlayId>>(),
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::<Vec<_>>(),
cx,
) {
ControlFlow::Break(Some(InlaySplice {
@@ -5332,13 +5316,25 @@ impl Editor {
}
}
fn visible_inlay_hints(&self, cx: &Context<Editor>) -> Vec<Inlay> {
pub fn clear_inlay_hints(&self, cx: &mut Context<Editor>) {
self.splice_inlays(
&self
.visible_inlay_hints(cx)
.map(|inlay| inlay.id)
.collect::<Vec<_>>(),
Vec::new(),
cx,
);
}
fn visible_inlay_hints<'a>(
&'a self,
cx: &'a Context<Editor>,
) -> impl Iterator<Item = &'a Inlay> {
self.display_map
.read(cx)
.current_inlays()
.filter(move |inlay| matches!(inlay.id, InlayId::Hint(_)))
.cloned()
.collect()
}
pub fn visible_excerpts(
-1
View File
@@ -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)
+1 -2
View File
@@ -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::<Vec<_>>())?;
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<Editor>) -> Vec<String> {
editor
.visible_inlay_hints(cx)
.into_iter()
.map(|hint| hint.text().to_string())
.collect()
}