acp thread view: Always use editors for user messages (#36256)
This means the cursor will be at the position you clicked: https://github.com/user-attachments/assets/0693950d-7513-4d90-88e2-55817df7213a Release Notes: - N/A
This commit is contained in:
parent
239e479aed
commit
9eb1ff2726
6 changed files with 671 additions and 374 deletions
|
@ -109,7 +109,7 @@ pub enum AgentThreadEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AgentThreadEntry {
|
impl AgentThreadEntry {
|
||||||
fn to_markdown(&self, cx: &App) -> String {
|
pub fn to_markdown(&self, cx: &App) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::UserMessage(message) => message.to_markdown(cx),
|
Self::UserMessage(message) => message.to_markdown(cx),
|
||||||
Self::AssistantMessage(message) => message.to_markdown(cx),
|
Self::AssistantMessage(message) => message.to_markdown(cx),
|
||||||
|
@ -117,6 +117,14 @@ impl AgentThreadEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn user_message(&self) -> Option<&UserMessage> {
|
||||||
|
if let AgentThreadEntry::UserMessage(message) = self {
|
||||||
|
Some(message)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn diffs(&self) -> impl Iterator<Item = &Entity<Diff>> {
|
pub fn diffs(&self) -> impl Iterator<Item = &Entity<Diff>> {
|
||||||
if let AgentThreadEntry::ToolCall(call) = self {
|
if let AgentThreadEntry::ToolCall(call) = self {
|
||||||
itertools::Either::Left(call.diffs())
|
itertools::Either::Left(call.diffs())
|
||||||
|
|
|
@ -80,11 +80,6 @@ impl MentionSet {
|
||||||
.chain(self.images.drain().map(|(id, _)| id))
|
.chain(self.images.drain().map(|(id, _)| id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
|
||||||
self.fetch_results.clear();
|
|
||||||
self.uri_by_crease_id.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn contents(
|
pub fn contents(
|
||||||
&self,
|
&self,
|
||||||
project: Entity<Project>,
|
project: Entity<Project>,
|
||||||
|
|
|
@ -1,45 +1,141 @@
|
||||||
use std::{collections::HashMap, ops::Range};
|
use std::ops::Range;
|
||||||
|
|
||||||
use acp_thread::AcpThread;
|
use acp_thread::{AcpThread, AgentThreadEntry};
|
||||||
use editor::{Editor, EditorMode, MinimapVisibility, MultiBuffer};
|
use agent::{TextThreadStore, ThreadStore};
|
||||||
|
use collections::HashMap;
|
||||||
|
use editor::{Editor, EditorMode, MinimapVisibility};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyEntity, App, AppContext as _, Entity, EntityId, TextStyleRefinement, WeakEntity, Window,
|
AnyEntity, App, AppContext as _, Entity, EntityId, EventEmitter, TextStyleRefinement,
|
||||||
|
WeakEntity, Window,
|
||||||
};
|
};
|
||||||
use language::language_settings::SoftWrap;
|
use language::language_settings::SoftWrap;
|
||||||
|
use project::Project;
|
||||||
use settings::Settings as _;
|
use settings::Settings as _;
|
||||||
use terminal_view::TerminalView;
|
use terminal_view::TerminalView;
|
||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::TextSize;
|
use ui::{Context, TextSize};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
#[derive(Default)]
|
use crate::acp::message_editor::{MessageEditor, MessageEditorEvent};
|
||||||
|
|
||||||
pub struct EntryViewState {
|
pub struct EntryViewState {
|
||||||
|
workspace: WeakEntity<Workspace>,
|
||||||
|
project: Entity<Project>,
|
||||||
|
thread_store: Entity<ThreadStore>,
|
||||||
|
text_thread_store: Entity<TextThreadStore>,
|
||||||
entries: Vec<Entry>,
|
entries: Vec<Entry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EntryViewState {
|
impl EntryViewState {
|
||||||
|
pub fn new(
|
||||||
|
workspace: WeakEntity<Workspace>,
|
||||||
|
project: Entity<Project>,
|
||||||
|
thread_store: Entity<ThreadStore>,
|
||||||
|
text_thread_store: Entity<TextThreadStore>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
workspace,
|
||||||
|
project,
|
||||||
|
thread_store,
|
||||||
|
text_thread_store,
|
||||||
|
entries: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn entry(&self, index: usize) -> Option<&Entry> {
|
pub fn entry(&self, index: usize) -> Option<&Entry> {
|
||||||
self.entries.get(index)
|
self.entries.get(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sync_entry(
|
pub fn sync_entry(
|
||||||
&mut self,
|
&mut self,
|
||||||
workspace: WeakEntity<Workspace>,
|
|
||||||
thread: Entity<AcpThread>,
|
|
||||||
index: usize,
|
index: usize,
|
||||||
|
thread: &Entity<AcpThread>,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
debug_assert!(index <= self.entries.len());
|
let Some(thread_entry) = thread.read(cx).entries().get(index) else {
|
||||||
let entry = if let Some(entry) = self.entries.get_mut(index) {
|
return;
|
||||||
entry
|
|
||||||
} else {
|
|
||||||
self.entries.push(Entry::default());
|
|
||||||
self.entries.last_mut().unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
entry.sync_diff_multibuffers(&thread, index, window, cx);
|
match thread_entry {
|
||||||
entry.sync_terminals(&workspace, &thread, index, window, cx);
|
AgentThreadEntry::UserMessage(message) => {
|
||||||
|
let has_id = message.id.is_some();
|
||||||
|
let chunks = message.chunks.clone();
|
||||||
|
let message_editor = cx.new(|cx| {
|
||||||
|
let mut editor = MessageEditor::new(
|
||||||
|
self.workspace.clone(),
|
||||||
|
self.project.clone(),
|
||||||
|
self.thread_store.clone(),
|
||||||
|
self.text_thread_store.clone(),
|
||||||
|
editor::EditorMode::AutoHeight {
|
||||||
|
min_lines: 1,
|
||||||
|
max_lines: None,
|
||||||
|
},
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
if !has_id {
|
||||||
|
editor.set_read_only(true, cx);
|
||||||
|
}
|
||||||
|
editor.set_message(chunks, window, cx);
|
||||||
|
editor
|
||||||
|
});
|
||||||
|
cx.subscribe(&message_editor, move |_, editor, event, cx| {
|
||||||
|
cx.emit(EntryViewEvent {
|
||||||
|
entry_index: index,
|
||||||
|
view_event: ViewEvent::MessageEditorEvent(editor, *event),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
self.set_entry(index, Entry::UserMessage(message_editor));
|
||||||
|
}
|
||||||
|
AgentThreadEntry::ToolCall(tool_call) => {
|
||||||
|
let terminals = tool_call.terminals().cloned().collect::<Vec<_>>();
|
||||||
|
let diffs = tool_call.diffs().cloned().collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let views = if let Some(Entry::Content(views)) = self.entries.get_mut(index) {
|
||||||
|
views
|
||||||
|
} else {
|
||||||
|
self.set_entry(index, Entry::empty());
|
||||||
|
let Some(Entry::Content(views)) = self.entries.get_mut(index) else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
views
|
||||||
|
};
|
||||||
|
|
||||||
|
for terminal in terminals {
|
||||||
|
views.entry(terminal.entity_id()).or_insert_with(|| {
|
||||||
|
create_terminal(
|
||||||
|
self.workspace.clone(),
|
||||||
|
self.project.clone(),
|
||||||
|
terminal.clone(),
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.into_any()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for diff in diffs {
|
||||||
|
views
|
||||||
|
.entry(diff.entity_id())
|
||||||
|
.or_insert_with(|| create_editor_diff(diff.clone(), window, cx).into_any());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AgentThreadEntry::AssistantMessage(_) => {
|
||||||
|
if index == self.entries.len() {
|
||||||
|
self.entries.push(Entry::empty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_entry(&mut self, index: usize, entry: Entry) {
|
||||||
|
if index == self.entries.len() {
|
||||||
|
self.entries.push(entry);
|
||||||
|
} else {
|
||||||
|
self.entries[index] = entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, range: Range<usize>) {
|
pub fn remove(&mut self, range: Range<usize>) {
|
||||||
|
@ -48,26 +144,51 @@ impl EntryViewState {
|
||||||
|
|
||||||
pub fn settings_changed(&mut self, cx: &mut App) {
|
pub fn settings_changed(&mut self, cx: &mut App) {
|
||||||
for entry in self.entries.iter() {
|
for entry in self.entries.iter() {
|
||||||
for view in entry.views.values() {
|
match entry {
|
||||||
if let Ok(diff_editor) = view.clone().downcast::<Editor>() {
|
Entry::UserMessage { .. } => {}
|
||||||
diff_editor.update(cx, |diff_editor, cx| {
|
Entry::Content(response_views) => {
|
||||||
diff_editor
|
for view in response_views.values() {
|
||||||
.set_text_style_refinement(diff_editor_text_style_refinement(cx));
|
if let Ok(diff_editor) = view.clone().downcast::<Editor>() {
|
||||||
cx.notify();
|
diff_editor.update(cx, |diff_editor, cx| {
|
||||||
})
|
diff_editor.set_text_style_refinement(
|
||||||
|
diff_editor_text_style_refinement(cx),
|
||||||
|
);
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Entry {
|
impl EventEmitter<EntryViewEvent> for EntryViewState {}
|
||||||
views: HashMap<EntityId, AnyEntity>,
|
|
||||||
|
pub struct EntryViewEvent {
|
||||||
|
pub entry_index: usize,
|
||||||
|
pub view_event: ViewEvent,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ViewEvent {
|
||||||
|
MessageEditorEvent(Entity<MessageEditor>, MessageEditorEvent),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Entry {
|
||||||
|
UserMessage(Entity<MessageEditor>),
|
||||||
|
Content(HashMap<EntityId, AnyEntity>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entry {
|
impl Entry {
|
||||||
pub fn editor_for_diff(&self, diff: &Entity<MultiBuffer>) -> Option<Entity<Editor>> {
|
pub fn message_editor(&self) -> Option<&Entity<MessageEditor>> {
|
||||||
self.views
|
match self {
|
||||||
|
Self::UserMessage(editor) => Some(editor),
|
||||||
|
Entry::Content(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn editor_for_diff(&self, diff: &Entity<acp_thread::Diff>) -> Option<Entity<Editor>> {
|
||||||
|
self.content_map()?
|
||||||
.get(&diff.entity_id())
|
.get(&diff.entity_id())
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|entity| entity.downcast::<Editor>().unwrap())
|
.map(|entity| entity.downcast::<Editor>().unwrap())
|
||||||
|
@ -77,118 +198,88 @@ impl Entry {
|
||||||
&self,
|
&self,
|
||||||
terminal: &Entity<acp_thread::Terminal>,
|
terminal: &Entity<acp_thread::Terminal>,
|
||||||
) -> Option<Entity<TerminalView>> {
|
) -> Option<Entity<TerminalView>> {
|
||||||
self.views
|
self.content_map()?
|
||||||
.get(&terminal.entity_id())
|
.get(&terminal.entity_id())
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|entity| entity.downcast::<TerminalView>().unwrap())
|
.map(|entity| entity.downcast::<TerminalView>().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_diff_multibuffers(
|
fn content_map(&self) -> Option<&HashMap<EntityId, AnyEntity>> {
|
||||||
&mut self,
|
match self {
|
||||||
thread: &Entity<AcpThread>,
|
Self::Content(map) => Some(map),
|
||||||
index: usize,
|
_ => None,
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut App,
|
|
||||||
) {
|
|
||||||
let Some(entry) = thread.read(cx).entries().get(index) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let multibuffers = entry
|
|
||||||
.diffs()
|
|
||||||
.map(|diff| diff.read(cx).multibuffer().clone());
|
|
||||||
|
|
||||||
let multibuffers = multibuffers.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for multibuffer in multibuffers {
|
|
||||||
if self.views.contains_key(&multibuffer.entity_id()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let editor = cx.new(|cx| {
|
|
||||||
let mut editor = Editor::new(
|
|
||||||
EditorMode::Full {
|
|
||||||
scale_ui_elements_with_buffer_font_size: false,
|
|
||||||
show_active_line_background: false,
|
|
||||||
sized_by_content: true,
|
|
||||||
},
|
|
||||||
multibuffer.clone(),
|
|
||||||
None,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
editor.set_show_gutter(false, cx);
|
|
||||||
editor.disable_inline_diagnostics();
|
|
||||||
editor.disable_expand_excerpt_buttons(cx);
|
|
||||||
editor.set_show_vertical_scrollbar(false, cx);
|
|
||||||
editor.set_minimap_visibility(MinimapVisibility::Disabled, window, cx);
|
|
||||||
editor.set_soft_wrap_mode(SoftWrap::None, cx);
|
|
||||||
editor.scroll_manager.set_forbid_vertical_scroll(true);
|
|
||||||
editor.set_show_indent_guides(false, cx);
|
|
||||||
editor.set_read_only(true);
|
|
||||||
editor.set_show_breakpoints(false, cx);
|
|
||||||
editor.set_show_code_actions(false, cx);
|
|
||||||
editor.set_show_git_diff_gutter(false, cx);
|
|
||||||
editor.set_expand_all_diff_hunks(cx);
|
|
||||||
editor.set_text_style_refinement(diff_editor_text_style_refinement(cx));
|
|
||||||
editor
|
|
||||||
});
|
|
||||||
|
|
||||||
let entity_id = multibuffer.entity_id();
|
|
||||||
self.views.insert(entity_id, editor.into_any());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_terminals(
|
fn empty() -> Self {
|
||||||
&mut self,
|
Self::Content(HashMap::default())
|
||||||
workspace: &WeakEntity<Workspace>,
|
|
||||||
thread: &Entity<AcpThread>,
|
|
||||||
index: usize,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut App,
|
|
||||||
) {
|
|
||||||
let Some(entry) = thread.read(cx).entries().get(index) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let terminals = entry
|
|
||||||
.terminals()
|
|
||||||
.map(|terminal| terminal.clone())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for terminal in terminals {
|
|
||||||
if self.views.contains_key(&terminal.entity_id()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(strong_workspace) = workspace.upgrade() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let terminal_view = cx.new(|cx| {
|
|
||||||
let mut view = TerminalView::new(
|
|
||||||
terminal.read(cx).inner().clone(),
|
|
||||||
workspace.clone(),
|
|
||||||
None,
|
|
||||||
strong_workspace.read(cx).project().downgrade(),
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
view.set_embedded_mode(Some(1000), cx);
|
|
||||||
view
|
|
||||||
});
|
|
||||||
|
|
||||||
let entity_id = terminal.entity_id();
|
|
||||||
self.views.insert(entity_id, terminal_view.into_any());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn len(&self) -> usize {
|
pub fn has_content(&self) -> bool {
|
||||||
self.views.len()
|
match self {
|
||||||
|
Self::Content(map) => !map.is_empty(),
|
||||||
|
Self::UserMessage(_) => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_terminal(
|
||||||
|
workspace: WeakEntity<Workspace>,
|
||||||
|
project: Entity<Project>,
|
||||||
|
terminal: Entity<acp_thread::Terminal>,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> Entity<TerminalView> {
|
||||||
|
cx.new(|cx| {
|
||||||
|
let mut view = TerminalView::new(
|
||||||
|
terminal.read(cx).inner().clone(),
|
||||||
|
workspace.clone(),
|
||||||
|
None,
|
||||||
|
project.downgrade(),
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
view.set_embedded_mode(Some(1000), cx);
|
||||||
|
view
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_editor_diff(
|
||||||
|
diff: Entity<acp_thread::Diff>,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> Entity<Editor> {
|
||||||
|
cx.new(|cx| {
|
||||||
|
let mut editor = Editor::new(
|
||||||
|
EditorMode::Full {
|
||||||
|
scale_ui_elements_with_buffer_font_size: false,
|
||||||
|
show_active_line_background: false,
|
||||||
|
sized_by_content: true,
|
||||||
|
},
|
||||||
|
diff.read(cx).multibuffer().clone(),
|
||||||
|
None,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
editor.set_show_gutter(false, cx);
|
||||||
|
editor.disable_inline_diagnostics();
|
||||||
|
editor.disable_expand_excerpt_buttons(cx);
|
||||||
|
editor.set_show_vertical_scrollbar(false, cx);
|
||||||
|
editor.set_minimap_visibility(MinimapVisibility::Disabled, window, cx);
|
||||||
|
editor.set_soft_wrap_mode(SoftWrap::None, cx);
|
||||||
|
editor.scroll_manager.set_forbid_vertical_scroll(true);
|
||||||
|
editor.set_show_indent_guides(false, cx);
|
||||||
|
editor.set_read_only(true);
|
||||||
|
editor.set_show_breakpoints(false, cx);
|
||||||
|
editor.set_show_code_actions(false, cx);
|
||||||
|
editor.set_show_git_diff_gutter(false, cx);
|
||||||
|
editor.set_expand_all_diff_hunks(cx);
|
||||||
|
editor.set_text_style_refinement(diff_editor_text_style_refinement(cx));
|
||||||
|
editor
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn diff_editor_text_style_refinement(cx: &mut App) -> TextStyleRefinement {
|
fn diff_editor_text_style_refinement(cx: &mut App) -> TextStyleRefinement {
|
||||||
TextStyleRefinement {
|
TextStyleRefinement {
|
||||||
font_size: Some(
|
font_size: Some(
|
||||||
|
@ -201,26 +292,20 @@ fn diff_editor_text_style_refinement(cx: &mut App) -> TextStyleRefinement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Entry {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
// Avoid allocating in the heap by default
|
|
||||||
views: HashMap::with_capacity(0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{path::Path, rc::Rc};
|
use std::{path::Path, rc::Rc};
|
||||||
|
|
||||||
use acp_thread::{AgentConnection, StubAgentConnection};
|
use acp_thread::{AgentConnection, StubAgentConnection};
|
||||||
|
use agent::{TextThreadStore, ThreadStore};
|
||||||
use agent_client_protocol as acp;
|
use agent_client_protocol as acp;
|
||||||
use agent_settings::AgentSettings;
|
use agent_settings::AgentSettings;
|
||||||
use buffer_diff::{DiffHunkStatus, DiffHunkStatusKind};
|
use buffer_diff::{DiffHunkStatus, DiffHunkStatusKind};
|
||||||
use editor::{EditorSettings, RowInfo};
|
use editor::{EditorSettings, RowInfo};
|
||||||
use fs::FakeFs;
|
use fs::FakeFs;
|
||||||
use gpui::{SemanticVersion, TestAppContext};
|
use gpui::{AppContext as _, SemanticVersion, TestAppContext};
|
||||||
|
|
||||||
|
use crate::acp::entry_view_state::EntryViewState;
|
||||||
use multi_buffer::MultiBufferRow;
|
use multi_buffer::MultiBufferRow;
|
||||||
use pretty_assertions::assert_matches;
|
use pretty_assertions::assert_matches;
|
||||||
use project::Project;
|
use project::Project;
|
||||||
|
@ -230,8 +315,6 @@ mod tests {
|
||||||
use util::path;
|
use util::path;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
use crate::acp::entry_view_state::EntryViewState;
|
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_diff_sync(cx: &mut TestAppContext) {
|
async fn test_diff_sync(cx: &mut TestAppContext) {
|
||||||
init_test(cx);
|
init_test(cx);
|
||||||
|
@ -269,7 +352,7 @@ mod tests {
|
||||||
.update(|_, cx| {
|
.update(|_, cx| {
|
||||||
connection
|
connection
|
||||||
.clone()
|
.clone()
|
||||||
.new_thread(project, Path::new(path!("/project")), cx)
|
.new_thread(project.clone(), Path::new(path!("/project")), cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -279,12 +362,23 @@ mod tests {
|
||||||
connection.send_update(session_id, acp::SessionUpdate::ToolCall(tool_call), cx)
|
connection.send_update(session_id, acp::SessionUpdate::ToolCall(tool_call), cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut view_state = EntryViewState::default();
|
let thread_store = cx.new(|cx| ThreadStore::fake(project.clone(), cx));
|
||||||
cx.update(|window, cx| {
|
let text_thread_store = cx.new(|cx| TextThreadStore::fake(project.clone(), cx));
|
||||||
view_state.sync_entry(workspace.downgrade(), thread.clone(), 0, window, cx);
|
|
||||||
|
let view_state = cx.new(|_cx| {
|
||||||
|
EntryViewState::new(
|
||||||
|
workspace.downgrade(),
|
||||||
|
project.clone(),
|
||||||
|
thread_store,
|
||||||
|
text_thread_store,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let multibuffer = thread.read_with(cx, |thread, cx| {
|
view_state.update_in(cx, |view_state, window, cx| {
|
||||||
|
view_state.sync_entry(0, &thread, window, cx)
|
||||||
|
});
|
||||||
|
|
||||||
|
let diff = thread.read_with(cx, |thread, _cx| {
|
||||||
thread
|
thread
|
||||||
.entries()
|
.entries()
|
||||||
.get(0)
|
.get(0)
|
||||||
|
@ -292,15 +386,14 @@ mod tests {
|
||||||
.diffs()
|
.diffs()
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read(cx)
|
|
||||||
.multibuffer()
|
|
||||||
.clone()
|
.clone()
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.run_until_parked();
|
cx.run_until_parked();
|
||||||
|
|
||||||
let entry = view_state.entry(0).unwrap();
|
let diff_editor = view_state.read_with(cx, |view_state, _cx| {
|
||||||
let diff_editor = entry.editor_for_diff(&multibuffer).unwrap();
|
view_state.entry(0).unwrap().editor_for_diff(&diff).unwrap()
|
||||||
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
diff_editor.read_with(cx, |editor, cx| editor.text(cx)),
|
diff_editor.read_with(cx, |editor, cx| editor.text(cx)),
|
||||||
"hi world\nhello world"
|
"hi world\nhello world"
|
||||||
|
|
|
@ -52,9 +52,11 @@ pub struct MessageEditor {
|
||||||
text_thread_store: Entity<TextThreadStore>,
|
text_thread_store: Entity<TextThreadStore>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub enum MessageEditorEvent {
|
pub enum MessageEditorEvent {
|
||||||
Send,
|
Send,
|
||||||
Cancel,
|
Cancel,
|
||||||
|
Focus,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter<MessageEditorEvent> for MessageEditor {}
|
impl EventEmitter<MessageEditorEvent> for MessageEditor {}
|
||||||
|
@ -101,6 +103,11 @@ impl MessageEditor {
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cx.on_focus(&editor.focus_handle(cx), window, |_, _, cx| {
|
||||||
|
cx.emit(MessageEditorEvent::Focus)
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
editor,
|
editor,
|
||||||
project,
|
project,
|
||||||
|
@ -386,11 +393,11 @@ impl MessageEditor {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chat(&mut self, _: &Chat, _: &mut Window, cx: &mut Context<Self>) {
|
fn send(&mut self, _: &Chat, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
cx.emit(MessageEditorEvent::Send)
|
cx.emit(MessageEditorEvent::Send)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancel(&mut self, _: &menu::Cancel, _: &mut Window, cx: &mut Context<Self>) {
|
fn cancel(&mut self, _: &editor::actions::Cancel, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
cx.emit(MessageEditorEvent::Cancel)
|
cx.emit(MessageEditorEvent::Cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,6 +503,13 @@ impl MessageEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_read_only(&mut self, read_only: bool, cx: &mut Context<Self>) {
|
||||||
|
self.editor.update(cx, |message_editor, cx| {
|
||||||
|
message_editor.set_read_only(read_only);
|
||||||
|
cx.notify()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn insert_image(
|
fn insert_image(
|
||||||
&mut self,
|
&mut self,
|
||||||
excerpt_id: ExcerptId,
|
excerpt_id: ExcerptId,
|
||||||
|
@ -572,6 +586,8 @@ impl MessageEditor {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
|
self.clear(window, cx);
|
||||||
|
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let mut mentions = Vec::new();
|
let mut mentions = Vec::new();
|
||||||
let mut images = Vec::new();
|
let mut images = Vec::new();
|
||||||
|
@ -609,7 +625,6 @@ impl MessageEditor {
|
||||||
editor.buffer().read(cx).snapshot(cx)
|
editor.buffer().read(cx).snapshot(cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
self.mention_set.clear();
|
|
||||||
for (range, mention_uri) in mentions {
|
for (range, mention_uri) in mentions {
|
||||||
let anchor = snapshot.anchor_before(range.start);
|
let anchor = snapshot.anchor_before(range.start);
|
||||||
let crease_id = crate::context_picker::insert_crease_for_mention(
|
let crease_id = crate::context_picker::insert_crease_for_mention(
|
||||||
|
@ -679,6 +694,11 @@ impl MessageEditor {
|
||||||
editor.set_text(text, window, cx);
|
editor.set_text(text, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn text(&self, cx: &App) -> String {
|
||||||
|
self.editor.read(cx).text(cx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Focusable for MessageEditor {
|
impl Focusable for MessageEditor {
|
||||||
|
@ -691,7 +711,7 @@ impl Render for MessageEditor {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
div()
|
div()
|
||||||
.key_context("MessageEditor")
|
.key_context("MessageEditor")
|
||||||
.on_action(cx.listener(Self::chat))
|
.on_action(cx.listener(Self::send))
|
||||||
.on_action(cx.listener(Self::cancel))
|
.on_action(cx.listener(Self::cancel))
|
||||||
.capture_action(cx.listener(Self::paste))
|
.capture_action(cx.listener(Self::paste))
|
||||||
.flex_1()
|
.flex_1()
|
||||||
|
|
|
@ -45,6 +45,7 @@ use zed_actions::assistant::OpenRulesLibrary;
|
||||||
|
|
||||||
use super::entry_view_state::EntryViewState;
|
use super::entry_view_state::EntryViewState;
|
||||||
use crate::acp::AcpModelSelectorPopover;
|
use crate::acp::AcpModelSelectorPopover;
|
||||||
|
use crate::acp::entry_view_state::{EntryViewEvent, ViewEvent};
|
||||||
use crate::acp::message_editor::{MessageEditor, MessageEditorEvent};
|
use crate::acp::message_editor::{MessageEditor, MessageEditorEvent};
|
||||||
use crate::agent_diff::AgentDiff;
|
use crate::agent_diff::AgentDiff;
|
||||||
use crate::profile_selector::{ProfileProvider, ProfileSelector};
|
use crate::profile_selector::{ProfileProvider, ProfileSelector};
|
||||||
|
@ -101,10 +102,8 @@ pub struct AcpThreadView {
|
||||||
agent: Rc<dyn AgentServer>,
|
agent: Rc<dyn AgentServer>,
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: WeakEntity<Workspace>,
|
||||||
project: Entity<Project>,
|
project: Entity<Project>,
|
||||||
thread_store: Entity<ThreadStore>,
|
|
||||||
text_thread_store: Entity<TextThreadStore>,
|
|
||||||
thread_state: ThreadState,
|
thread_state: ThreadState,
|
||||||
entry_view_state: EntryViewState,
|
entry_view_state: Entity<EntryViewState>,
|
||||||
message_editor: Entity<MessageEditor>,
|
message_editor: Entity<MessageEditor>,
|
||||||
model_selector: Option<Entity<AcpModelSelectorPopover>>,
|
model_selector: Option<Entity<AcpModelSelectorPopover>>,
|
||||||
profile_selector: Option<Entity<ProfileSelector>>,
|
profile_selector: Option<Entity<ProfileSelector>>,
|
||||||
|
@ -120,16 +119,9 @@ pub struct AcpThreadView {
|
||||||
plan_expanded: bool,
|
plan_expanded: bool,
|
||||||
editor_expanded: bool,
|
editor_expanded: bool,
|
||||||
terminal_expanded: bool,
|
terminal_expanded: bool,
|
||||||
editing_message: Option<EditingMessage>,
|
editing_message: Option<usize>,
|
||||||
_cancel_task: Option<Task<()>>,
|
_cancel_task: Option<Task<()>>,
|
||||||
_subscriptions: [Subscription; 2],
|
_subscriptions: [Subscription; 3],
|
||||||
}
|
|
||||||
|
|
||||||
struct EditingMessage {
|
|
||||||
index: usize,
|
|
||||||
message_id: UserMessageId,
|
|
||||||
editor: Entity<MessageEditor>,
|
|
||||||
_subscription: Subscription,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ThreadState {
|
enum ThreadState {
|
||||||
|
@ -176,24 +168,32 @@ impl AcpThreadView {
|
||||||
|
|
||||||
let list_state = ListState::new(0, gpui::ListAlignment::Bottom, px(2048.0));
|
let list_state = ListState::new(0, gpui::ListAlignment::Bottom, px(2048.0));
|
||||||
|
|
||||||
|
let entry_view_state = cx.new(|_| {
|
||||||
|
EntryViewState::new(
|
||||||
|
workspace.clone(),
|
||||||
|
project.clone(),
|
||||||
|
thread_store.clone(),
|
||||||
|
text_thread_store.clone(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let subscriptions = [
|
let subscriptions = [
|
||||||
cx.observe_global_in::<SettingsStore>(window, Self::settings_changed),
|
cx.observe_global_in::<SettingsStore>(window, Self::settings_changed),
|
||||||
cx.subscribe_in(&message_editor, window, Self::on_message_editor_event),
|
cx.subscribe_in(&message_editor, window, Self::handle_message_editor_event),
|
||||||
|
cx.subscribe_in(&entry_view_state, window, Self::handle_entry_view_event),
|
||||||
];
|
];
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
agent: agent.clone(),
|
agent: agent.clone(),
|
||||||
workspace: workspace.clone(),
|
workspace: workspace.clone(),
|
||||||
project: project.clone(),
|
project: project.clone(),
|
||||||
thread_store,
|
entry_view_state,
|
||||||
text_thread_store,
|
|
||||||
thread_state: Self::initial_state(agent, workspace, project, window, cx),
|
thread_state: Self::initial_state(agent, workspace, project, window, cx),
|
||||||
message_editor,
|
message_editor,
|
||||||
model_selector: None,
|
model_selector: None,
|
||||||
profile_selector: None,
|
profile_selector: None,
|
||||||
notifications: Vec::new(),
|
notifications: Vec::new(),
|
||||||
notification_subscriptions: HashMap::default(),
|
notification_subscriptions: HashMap::default(),
|
||||||
entry_view_state: EntryViewState::default(),
|
|
||||||
list_state: list_state.clone(),
|
list_state: list_state.clone(),
|
||||||
scrollbar_state: ScrollbarState::new(list_state).parent_entity(&cx.entity()),
|
scrollbar_state: ScrollbarState::new(list_state).parent_entity(&cx.entity()),
|
||||||
thread_error: None,
|
thread_error: None,
|
||||||
|
@ -414,7 +414,7 @@ impl AcpThreadView {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_message_editor_event(
|
pub fn handle_message_editor_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &Entity<MessageEditor>,
|
_: &Entity<MessageEditor>,
|
||||||
event: &MessageEditorEvent,
|
event: &MessageEditorEvent,
|
||||||
|
@ -424,6 +424,28 @@ impl AcpThreadView {
|
||||||
match event {
|
match event {
|
||||||
MessageEditorEvent::Send => self.send(window, cx),
|
MessageEditorEvent::Send => self.send(window, cx),
|
||||||
MessageEditorEvent::Cancel => self.cancel_generation(cx),
|
MessageEditorEvent::Cancel => self.cancel_generation(cx),
|
||||||
|
MessageEditorEvent::Focus => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_entry_view_event(
|
||||||
|
&mut self,
|
||||||
|
_: &Entity<EntryViewState>,
|
||||||
|
event: &EntryViewEvent,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
match &event.view_event {
|
||||||
|
ViewEvent::MessageEditorEvent(_editor, MessageEditorEvent::Focus) => {
|
||||||
|
self.editing_message = Some(event.entry_index);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
ViewEvent::MessageEditorEvent(editor, MessageEditorEvent::Send) => {
|
||||||
|
self.regenerate(event.entry_index, editor, window, cx);
|
||||||
|
}
|
||||||
|
ViewEvent::MessageEditorEvent(_editor, MessageEditorEvent::Cancel) => {
|
||||||
|
self.cancel_editing(&Default::default(), window, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,27 +516,56 @@ impl AcpThreadView {
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancel_editing(&mut self, _: &ClickEvent, _window: &mut Window, cx: &mut Context<Self>) {
|
fn cancel_editing(&mut self, _: &ClickEvent, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
self.editing_message.take();
|
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn regenerate(&mut self, _: &ClickEvent, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
let Some(editing_message) = self.editing_message.take() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let Some(thread) = self.thread().cloned() else {
|
let Some(thread) = self.thread().cloned() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let rewind = thread.update(cx, |thread, cx| {
|
if let Some(index) = self.editing_message.take() {
|
||||||
thread.rewind(editing_message.message_id, cx)
|
if let Some(editor) = self
|
||||||
});
|
.entry_view_state
|
||||||
|
.read(cx)
|
||||||
|
.entry(index)
|
||||||
|
.and_then(|e| e.message_editor())
|
||||||
|
.cloned()
|
||||||
|
{
|
||||||
|
editor.update(cx, |editor, cx| {
|
||||||
|
if let Some(user_message) = thread
|
||||||
|
.read(cx)
|
||||||
|
.entries()
|
||||||
|
.get(index)
|
||||||
|
.and_then(|e| e.user_message())
|
||||||
|
{
|
||||||
|
editor.set_message(user_message.chunks.clone(), window, cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
self.focus_handle(cx).focus(window);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn regenerate(
|
||||||
|
&mut self,
|
||||||
|
entry_ix: usize,
|
||||||
|
message_editor: &Entity<MessageEditor>,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
let Some(thread) = self.thread().cloned() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(rewind) = thread.update(cx, |thread, cx| {
|
||||||
|
let user_message_id = thread.entries().get(entry_ix)?.user_message()?.id.clone()?;
|
||||||
|
Some(thread.rewind(user_message_id, cx))
|
||||||
|
}) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let contents =
|
||||||
|
message_editor.update(cx, |message_editor, cx| message_editor.contents(window, cx));
|
||||||
|
|
||||||
let contents = editing_message
|
|
||||||
.editor
|
|
||||||
.update(cx, |message_editor, cx| message_editor.contents(window, cx));
|
|
||||||
let task = cx.foreground_executor().spawn(async move {
|
let task = cx.foreground_executor().spawn(async move {
|
||||||
rewind.await?;
|
rewind.await?;
|
||||||
contents.await
|
contents.await
|
||||||
|
@ -570,27 +621,20 @@ impl AcpThreadView {
|
||||||
AcpThreadEvent::NewEntry => {
|
AcpThreadEvent::NewEntry => {
|
||||||
let len = thread.read(cx).entries().len();
|
let len = thread.read(cx).entries().len();
|
||||||
let index = len - 1;
|
let index = len - 1;
|
||||||
self.entry_view_state.sync_entry(
|
self.entry_view_state.update(cx, |view_state, cx| {
|
||||||
self.workspace.clone(),
|
view_state.sync_entry(index, &thread, window, cx)
|
||||||
thread.clone(),
|
});
|
||||||
index,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
self.list_state.splice(index..index, 1);
|
self.list_state.splice(index..index, 1);
|
||||||
}
|
}
|
||||||
AcpThreadEvent::EntryUpdated(index) => {
|
AcpThreadEvent::EntryUpdated(index) => {
|
||||||
self.entry_view_state.sync_entry(
|
self.entry_view_state.update(cx, |view_state, cx| {
|
||||||
self.workspace.clone(),
|
view_state.sync_entry(*index, &thread, window, cx)
|
||||||
thread.clone(),
|
});
|
||||||
*index,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
self.list_state.splice(*index..index + 1, 1);
|
self.list_state.splice(*index..index + 1, 1);
|
||||||
}
|
}
|
||||||
AcpThreadEvent::EntriesRemoved(range) => {
|
AcpThreadEvent::EntriesRemoved(range) => {
|
||||||
self.entry_view_state.remove(range.clone());
|
self.entry_view_state
|
||||||
|
.update(cx, |view_state, _cx| view_state.remove(range.clone()));
|
||||||
self.list_state.splice(range.clone(), 0);
|
self.list_state.splice(range.clone(), 0);
|
||||||
}
|
}
|
||||||
AcpThreadEvent::ToolAuthorizationRequired => {
|
AcpThreadEvent::ToolAuthorizationRequired => {
|
||||||
|
@ -722,29 +766,15 @@ impl AcpThreadView {
|
||||||
.border_1()
|
.border_1()
|
||||||
.border_color(cx.theme().colors().border)
|
.border_color(cx.theme().colors().border)
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.id("message")
|
|
||||||
.on_click(cx.listener({
|
|
||||||
move |this, _, window, cx| {
|
|
||||||
this.start_editing_message(entry_ix, window, cx)
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.children(
|
.children(
|
||||||
if let Some(editing) = self.editing_message.as_ref()
|
self.entry_view_state
|
||||||
&& Some(&editing.message_id) == message.id.as_ref()
|
.read(cx)
|
||||||
{
|
.entry(entry_ix)
|
||||||
Some(
|
.and_then(|entry| entry.message_editor())
|
||||||
self.render_edit_message_editor(editing, cx)
|
.map(|editor| {
|
||||||
.into_any_element(),
|
self.render_sent_message_editor(entry_ix, editor, cx)
|
||||||
)
|
.into_any_element()
|
||||||
} else {
|
}),
|
||||||
message.content.markdown().map(|md| {
|
|
||||||
self.render_markdown(
|
|
||||||
md.clone(),
|
|
||||||
user_message_markdown_style(window, cx),
|
|
||||||
)
|
|
||||||
.into_any_element()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into_any(),
|
.into_any(),
|
||||||
|
@ -819,8 +849,8 @@ impl AcpThreadView {
|
||||||
primary
|
primary
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(editing) = self.editing_message.as_ref()
|
if let Some(editing_index) = self.editing_message.as_ref()
|
||||||
&& editing.index < entry_ix
|
&& *editing_index < entry_ix
|
||||||
{
|
{
|
||||||
let backdrop = div()
|
let backdrop = div()
|
||||||
.id(("backdrop", entry_ix))
|
.id(("backdrop", entry_ix))
|
||||||
|
@ -834,8 +864,8 @@ impl AcpThreadView {
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.relative()
|
.relative()
|
||||||
.child(backdrop)
|
|
||||||
.child(primary)
|
.child(primary)
|
||||||
|
.child(backdrop)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
} else {
|
} else {
|
||||||
primary
|
primary
|
||||||
|
@ -1256,9 +1286,7 @@ impl AcpThreadView {
|
||||||
Empty.into_any_element()
|
Empty.into_any_element()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToolCallContent::Diff(diff) => {
|
ToolCallContent::Diff(diff) => self.render_diff_editor(entry_ix, &diff, cx),
|
||||||
self.render_diff_editor(entry_ix, &diff.read(cx).multibuffer(), cx)
|
|
||||||
}
|
|
||||||
ToolCallContent::Terminal(terminal) => {
|
ToolCallContent::Terminal(terminal) => {
|
||||||
self.render_terminal_tool_call(entry_ix, terminal, tool_call, window, cx)
|
self.render_terminal_tool_call(entry_ix, terminal, tool_call, window, cx)
|
||||||
}
|
}
|
||||||
|
@ -1405,7 +1433,7 @@ impl AcpThreadView {
|
||||||
fn render_diff_editor(
|
fn render_diff_editor(
|
||||||
&self,
|
&self,
|
||||||
entry_ix: usize,
|
entry_ix: usize,
|
||||||
multibuffer: &Entity<MultiBuffer>,
|
diff: &Entity<acp_thread::Diff>,
|
||||||
cx: &Context<Self>,
|
cx: &Context<Self>,
|
||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
v_flex()
|
v_flex()
|
||||||
|
@ -1413,8 +1441,8 @@ impl AcpThreadView {
|
||||||
.border_t_1()
|
.border_t_1()
|
||||||
.border_color(self.tool_card_border_color(cx))
|
.border_color(self.tool_card_border_color(cx))
|
||||||
.child(
|
.child(
|
||||||
if let Some(entry) = self.entry_view_state.entry(entry_ix)
|
if let Some(entry) = self.entry_view_state.read(cx).entry(entry_ix)
|
||||||
&& let Some(editor) = entry.editor_for_diff(&multibuffer)
|
&& let Some(editor) = entry.editor_for_diff(&diff)
|
||||||
{
|
{
|
||||||
editor.clone().into_any_element()
|
editor.clone().into_any_element()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1617,6 +1645,7 @@ impl AcpThreadView {
|
||||||
|
|
||||||
let terminal_view = self
|
let terminal_view = self
|
||||||
.entry_view_state
|
.entry_view_state
|
||||||
|
.read(cx)
|
||||||
.entry(entry_ix)
|
.entry(entry_ix)
|
||||||
.and_then(|entry| entry.terminal(&terminal));
|
.and_then(|entry| entry.terminal(&terminal));
|
||||||
let show_output = self.terminal_expanded && terminal_view.is_some();
|
let show_output = self.terminal_expanded && terminal_view.is_some();
|
||||||
|
@ -2485,82 +2514,38 @@ impl AcpThreadView {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_editing_message(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
|
fn render_sent_message_editor(
|
||||||
let Some(thread) = self.thread() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let Some(AgentThreadEntry::UserMessage(message)) = thread.read(cx).entries().get(index)
|
|
||||||
else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let Some(message_id) = message.id.clone() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
self.list_state.scroll_to_reveal_item(index);
|
|
||||||
|
|
||||||
let chunks = message.chunks.clone();
|
|
||||||
let editor = cx.new(|cx| {
|
|
||||||
let mut editor = MessageEditor::new(
|
|
||||||
self.workspace.clone(),
|
|
||||||
self.project.clone(),
|
|
||||||
self.thread_store.clone(),
|
|
||||||
self.text_thread_store.clone(),
|
|
||||||
editor::EditorMode::AutoHeight {
|
|
||||||
min_lines: 1,
|
|
||||||
max_lines: None,
|
|
||||||
},
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
editor.set_message(chunks, window, cx);
|
|
||||||
editor
|
|
||||||
});
|
|
||||||
let subscription =
|
|
||||||
cx.subscribe_in(&editor, window, |this, _, event, window, cx| match event {
|
|
||||||
MessageEditorEvent::Send => {
|
|
||||||
this.regenerate(&Default::default(), window, cx);
|
|
||||||
}
|
|
||||||
MessageEditorEvent::Cancel => {
|
|
||||||
this.cancel_editing(&Default::default(), window, cx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
editor.focus_handle(cx).focus(window);
|
|
||||||
|
|
||||||
self.editing_message.replace(EditingMessage {
|
|
||||||
index: index,
|
|
||||||
message_id: message_id.clone(),
|
|
||||||
editor,
|
|
||||||
_subscription: subscription,
|
|
||||||
});
|
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_edit_message_editor(&self, editing: &EditingMessage, cx: &Context<Self>) -> Div {
|
|
||||||
v_flex()
|
|
||||||
.w_full()
|
|
||||||
.gap_2()
|
|
||||||
.child(editing.editor.clone())
|
|
||||||
.child(
|
|
||||||
h_flex()
|
|
||||||
.gap_1()
|
|
||||||
.child(
|
|
||||||
Icon::new(IconName::Warning)
|
|
||||||
.color(Color::Warning)
|
|
||||||
.size(IconSize::XSmall),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Label::new("Editing will restart the thread from this point.")
|
|
||||||
.color(Color::Muted)
|
|
||||||
.size(LabelSize::XSmall),
|
|
||||||
)
|
|
||||||
.child(self.render_editing_message_editor_buttons(editing, cx)),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_editing_message_editor_buttons(
|
|
||||||
&self,
|
&self,
|
||||||
editing: &EditingMessage,
|
entry_ix: usize,
|
||||||
|
editor: &Entity<MessageEditor>,
|
||||||
|
cx: &Context<Self>,
|
||||||
|
) -> Div {
|
||||||
|
v_flex().w_full().gap_2().child(editor.clone()).when(
|
||||||
|
self.editing_message == Some(entry_ix),
|
||||||
|
|el| {
|
||||||
|
el.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.child(
|
||||||
|
Icon::new(IconName::Warning)
|
||||||
|
.color(Color::Warning)
|
||||||
|
.size(IconSize::XSmall),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Label::new("Editing will restart the thread from this point.")
|
||||||
|
.color(Color::Muted)
|
||||||
|
.size(LabelSize::XSmall),
|
||||||
|
)
|
||||||
|
.child(self.render_sent_message_editor_buttons(entry_ix, editor, cx)),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_sent_message_editor_buttons(
|
||||||
|
&self,
|
||||||
|
entry_ix: usize,
|
||||||
|
editor: &Entity<MessageEditor>,
|
||||||
cx: &Context<Self>,
|
cx: &Context<Self>,
|
||||||
) -> Div {
|
) -> Div {
|
||||||
h_flex()
|
h_flex()
|
||||||
|
@ -2573,7 +2558,7 @@ impl AcpThreadView {
|
||||||
.icon_color(Color::Error)
|
.icon_color(Color::Error)
|
||||||
.icon_size(IconSize::Small)
|
.icon_size(IconSize::Small)
|
||||||
.tooltip({
|
.tooltip({
|
||||||
let focus_handle = editing.editor.focus_handle(cx);
|
let focus_handle = editor.focus_handle(cx);
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
Tooltip::for_action_in(
|
Tooltip::for_action_in(
|
||||||
"Cancel Edit",
|
"Cancel Edit",
|
||||||
|
@ -2588,12 +2573,12 @@ impl AcpThreadView {
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
IconButton::new("confirm-edit-message", IconName::Return)
|
IconButton::new("confirm-edit-message", IconName::Return)
|
||||||
.disabled(editing.editor.read(cx).is_empty(cx))
|
.disabled(editor.read(cx).is_empty(cx))
|
||||||
.shape(ui::IconButtonShape::Square)
|
.shape(ui::IconButtonShape::Square)
|
||||||
.icon_color(Color::Muted)
|
.icon_color(Color::Muted)
|
||||||
.icon_size(IconSize::Small)
|
.icon_size(IconSize::Small)
|
||||||
.tooltip({
|
.tooltip({
|
||||||
let focus_handle = editing.editor.focus_handle(cx);
|
let focus_handle = editor.focus_handle(cx);
|
||||||
move |window, cx| {
|
move |window, cx| {
|
||||||
Tooltip::for_action_in(
|
Tooltip::for_action_in(
|
||||||
"Regenerate",
|
"Regenerate",
|
||||||
|
@ -2604,7 +2589,12 @@ impl AcpThreadView {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on_click(cx.listener(Self::regenerate)),
|
.on_click(cx.listener({
|
||||||
|
let editor = editor.clone();
|
||||||
|
move |this, _, window, cx| {
|
||||||
|
this.regenerate(entry_ix, &editor, window, cx);
|
||||||
|
}
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3137,7 +3127,9 @@ impl AcpThreadView {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn settings_changed(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
fn settings_changed(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
self.entry_view_state.settings_changed(cx);
|
self.entry_view_state.update(cx, |entry_view_state, cx| {
|
||||||
|
entry_view_state.settings_changed(cx);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn insert_dragged_files(
|
pub(crate) fn insert_dragged_files(
|
||||||
|
@ -3152,9 +3144,7 @@ impl AcpThreadView {
|
||||||
drop(added_worktrees);
|
drop(added_worktrees);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl AcpThreadView {
|
|
||||||
fn render_thread_error(&self, window: &mut Window, cx: &mut Context<'_, Self>) -> Option<Div> {
|
fn render_thread_error(&self, window: &mut Window, cx: &mut Context<'_, Self>) -> Option<Div> {
|
||||||
let content = match self.thread_error.as_ref()? {
|
let content = match self.thread_error.as_ref()? {
|
||||||
ThreadError::Other(error) => self.render_any_thread_error(error.clone(), cx),
|
ThreadError::Other(error) => self.render_any_thread_error(error.clone(), cx),
|
||||||
|
@ -3439,35 +3429,6 @@ impl Render for AcpThreadView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn user_message_markdown_style(window: &Window, cx: &App) -> MarkdownStyle {
|
|
||||||
let mut style = default_markdown_style(false, window, cx);
|
|
||||||
let mut text_style = window.text_style();
|
|
||||||
let theme_settings = ThemeSettings::get_global(cx);
|
|
||||||
|
|
||||||
let buffer_font = theme_settings.buffer_font.family.clone();
|
|
||||||
let buffer_font_size = TextSize::Small.rems(cx);
|
|
||||||
|
|
||||||
text_style.refine(&TextStyleRefinement {
|
|
||||||
font_family: Some(buffer_font),
|
|
||||||
font_size: Some(buffer_font_size.into()),
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
style.base_text_style = text_style;
|
|
||||||
style.link_callback = Some(Rc::new(move |url, cx| {
|
|
||||||
if MentionUri::parse(url).is_ok() {
|
|
||||||
let colors = cx.theme().colors();
|
|
||||||
Some(TextStyleRefinement {
|
|
||||||
background_color: Some(colors.element_background),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
style
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_markdown_style(buffer_font: bool, window: &Window, cx: &App) -> MarkdownStyle {
|
fn default_markdown_style(buffer_font: bool, window: &Window, cx: &App) -> MarkdownStyle {
|
||||||
let theme_settings = ThemeSettings::get_global(cx);
|
let theme_settings = ThemeSettings::get_global(cx);
|
||||||
let colors = cx.theme().colors();
|
let colors = cx.theme().colors();
|
||||||
|
@ -3626,12 +3587,13 @@ pub(crate) mod tests {
|
||||||
use agent_client_protocol::SessionId;
|
use agent_client_protocol::SessionId;
|
||||||
use editor::EditorSettings;
|
use editor::EditorSettings;
|
||||||
use fs::FakeFs;
|
use fs::FakeFs;
|
||||||
use gpui::{SemanticVersion, TestAppContext, VisualTestContext};
|
use gpui::{EventEmitter, SemanticVersion, TestAppContext, VisualTestContext};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use workspace::Item;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -3778,6 +3740,50 @@ pub(crate) mod tests {
|
||||||
(thread_view, cx)
|
(thread_view, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_to_workspace(thread_view: Entity<AcpThreadView>, cx: &mut VisualTestContext) {
|
||||||
|
let workspace = thread_view.read_with(cx, |thread_view, _cx| thread_view.workspace.clone());
|
||||||
|
|
||||||
|
workspace
|
||||||
|
.update_in(cx, |workspace, window, cx| {
|
||||||
|
workspace.add_item_to_active_pane(
|
||||||
|
Box::new(cx.new(|_| ThreadViewItem(thread_view.clone()))),
|
||||||
|
None,
|
||||||
|
true,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ThreadViewItem(Entity<AcpThreadView>);
|
||||||
|
|
||||||
|
impl Item for ThreadViewItem {
|
||||||
|
type Event = ();
|
||||||
|
|
||||||
|
fn include_in_nav_history() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tab_content_text(&self, _detail: usize, _cx: &App) -> SharedString {
|
||||||
|
"Test".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<()> for ThreadViewItem {}
|
||||||
|
|
||||||
|
impl Focusable for ThreadViewItem {
|
||||||
|
fn focus_handle(&self, cx: &App) -> FocusHandle {
|
||||||
|
self.0.read(cx).focus_handle(cx).clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ThreadViewItem {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.0.clone().into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct StubAgentServer<C> {
|
struct StubAgentServer<C> {
|
||||||
connection: C,
|
connection: C,
|
||||||
}
|
}
|
||||||
|
@ -3799,19 +3805,19 @@ pub(crate) mod tests {
|
||||||
C: 'static + AgentConnection + Send + Clone,
|
C: 'static + AgentConnection + Send + Clone,
|
||||||
{
|
{
|
||||||
fn logo(&self) -> ui::IconName {
|
fn logo(&self) -> ui::IconName {
|
||||||
unimplemented!()
|
ui::IconName::Ai
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
unimplemented!()
|
"Test"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn empty_state_headline(&self) -> &'static str {
|
fn empty_state_headline(&self) -> &'static str {
|
||||||
unimplemented!()
|
"Test"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn empty_state_message(&self) -> &'static str {
|
fn empty_state_message(&self) -> &'static str {
|
||||||
unimplemented!()
|
"Test"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connect(
|
fn connect(
|
||||||
|
@ -3960,9 +3966,17 @@ pub(crate) mod tests {
|
||||||
assert_eq!(thread.entries().len(), 2);
|
assert_eq!(thread.entries().len(), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
thread_view.read_with(cx, |view, _| {
|
thread_view.read_with(cx, |view, cx| {
|
||||||
assert_eq!(view.entry_view_state.entry(0).unwrap().len(), 0);
|
view.entry_view_state.read_with(cx, |entry_view_state, _| {
|
||||||
assert_eq!(view.entry_view_state.entry(1).unwrap().len(), 1);
|
assert!(
|
||||||
|
entry_view_state
|
||||||
|
.entry(0)
|
||||||
|
.unwrap()
|
||||||
|
.message_editor()
|
||||||
|
.is_some()
|
||||||
|
);
|
||||||
|
assert!(entry_view_state.entry(1).unwrap().has_content());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Second user message
|
// Second user message
|
||||||
|
@ -3991,18 +4005,31 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
let second_user_message_id = thread.read_with(cx, |thread, _| {
|
let second_user_message_id = thread.read_with(cx, |thread, _| {
|
||||||
assert_eq!(thread.entries().len(), 4);
|
assert_eq!(thread.entries().len(), 4);
|
||||||
let AgentThreadEntry::UserMessage(user_message) = thread.entries().get(2).unwrap()
|
let AgentThreadEntry::UserMessage(user_message) = &thread.entries()[2] else {
|
||||||
else {
|
|
||||||
panic!();
|
panic!();
|
||||||
};
|
};
|
||||||
user_message.id.clone().unwrap()
|
user_message.id.clone().unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
thread_view.read_with(cx, |view, _| {
|
thread_view.read_with(cx, |view, cx| {
|
||||||
assert_eq!(view.entry_view_state.entry(0).unwrap().len(), 0);
|
view.entry_view_state.read_with(cx, |entry_view_state, _| {
|
||||||
assert_eq!(view.entry_view_state.entry(1).unwrap().len(), 1);
|
assert!(
|
||||||
assert_eq!(view.entry_view_state.entry(2).unwrap().len(), 0);
|
entry_view_state
|
||||||
assert_eq!(view.entry_view_state.entry(3).unwrap().len(), 1);
|
.entry(0)
|
||||||
|
.unwrap()
|
||||||
|
.message_editor()
|
||||||
|
.is_some()
|
||||||
|
);
|
||||||
|
assert!(entry_view_state.entry(1).unwrap().has_content());
|
||||||
|
assert!(
|
||||||
|
entry_view_state
|
||||||
|
.entry(2)
|
||||||
|
.unwrap()
|
||||||
|
.message_editor()
|
||||||
|
.is_some()
|
||||||
|
);
|
||||||
|
assert!(entry_view_state.entry(3).unwrap().has_content());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rewind to first message
|
// Rewind to first message
|
||||||
|
@ -4017,13 +4044,169 @@ pub(crate) mod tests {
|
||||||
assert_eq!(thread.entries().len(), 2);
|
assert_eq!(thread.entries().len(), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
thread_view.read_with(cx, |view, _| {
|
thread_view.read_with(cx, |view, cx| {
|
||||||
assert_eq!(view.entry_view_state.entry(0).unwrap().len(), 0);
|
view.entry_view_state.read_with(cx, |entry_view_state, _| {
|
||||||
assert_eq!(view.entry_view_state.entry(1).unwrap().len(), 1);
|
assert!(
|
||||||
|
entry_view_state
|
||||||
|
.entry(0)
|
||||||
|
.unwrap()
|
||||||
|
.message_editor()
|
||||||
|
.is_some()
|
||||||
|
);
|
||||||
|
assert!(entry_view_state.entry(1).unwrap().has_content());
|
||||||
|
|
||||||
// Old views should be dropped
|
// Old views should be dropped
|
||||||
assert!(view.entry_view_state.entry(2).is_none());
|
assert!(entry_view_state.entry(2).is_none());
|
||||||
assert!(view.entry_view_state.entry(3).is_none());
|
assert!(entry_view_state.entry(3).is_none());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_message_editing_cancel(cx: &mut TestAppContext) {
|
||||||
|
init_test(cx);
|
||||||
|
|
||||||
|
let connection = StubAgentConnection::new();
|
||||||
|
|
||||||
|
connection.set_next_prompt_updates(vec![acp::SessionUpdate::AgentMessageChunk {
|
||||||
|
content: acp::ContentBlock::Text(acp::TextContent {
|
||||||
|
text: "Response".into(),
|
||||||
|
annotations: None,
|
||||||
|
}),
|
||||||
|
}]);
|
||||||
|
|
||||||
|
let (thread_view, cx) = setup_thread_view(StubAgentServer::new(connection), cx).await;
|
||||||
|
add_to_workspace(thread_view.clone(), cx);
|
||||||
|
|
||||||
|
let message_editor = cx.read(|cx| thread_view.read(cx).message_editor.clone());
|
||||||
|
message_editor.update_in(cx, |editor, window, cx| {
|
||||||
|
editor.set_text("Original message to edit", window, cx);
|
||||||
|
});
|
||||||
|
thread_view.update_in(cx, |thread_view, window, cx| {
|
||||||
|
thread_view.send(window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
let user_message_editor = thread_view.read_with(cx, |view, cx| {
|
||||||
|
assert_eq!(view.editing_message, None);
|
||||||
|
|
||||||
|
view.entry_view_state
|
||||||
|
.read(cx)
|
||||||
|
.entry(0)
|
||||||
|
.unwrap()
|
||||||
|
.message_editor()
|
||||||
|
.unwrap()
|
||||||
|
.clone()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Focus
|
||||||
|
cx.focus(&user_message_editor);
|
||||||
|
thread_view.read_with(cx, |view, _cx| {
|
||||||
|
assert_eq!(view.editing_message, Some(0));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Edit
|
||||||
|
user_message_editor.update_in(cx, |editor, window, cx| {
|
||||||
|
editor.set_text("Edited message content", window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Cancel
|
||||||
|
user_message_editor.update_in(cx, |_editor, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(editor::actions::Cancel), cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
thread_view.read_with(cx, |view, _cx| {
|
||||||
|
assert_eq!(view.editing_message, None);
|
||||||
|
});
|
||||||
|
|
||||||
|
user_message_editor.read_with(cx, |editor, cx| {
|
||||||
|
assert_eq!(editor.text(cx), "Original message to edit");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_message_editing_regenerate(cx: &mut TestAppContext) {
|
||||||
|
init_test(cx);
|
||||||
|
|
||||||
|
let connection = StubAgentConnection::new();
|
||||||
|
|
||||||
|
connection.set_next_prompt_updates(vec![acp::SessionUpdate::AgentMessageChunk {
|
||||||
|
content: acp::ContentBlock::Text(acp::TextContent {
|
||||||
|
text: "Response".into(),
|
||||||
|
annotations: None,
|
||||||
|
}),
|
||||||
|
}]);
|
||||||
|
|
||||||
|
let (thread_view, cx) =
|
||||||
|
setup_thread_view(StubAgentServer::new(connection.clone()), cx).await;
|
||||||
|
add_to_workspace(thread_view.clone(), cx);
|
||||||
|
|
||||||
|
let message_editor = cx.read(|cx| thread_view.read(cx).message_editor.clone());
|
||||||
|
message_editor.update_in(cx, |editor, window, cx| {
|
||||||
|
editor.set_text("Original message to edit", window, cx);
|
||||||
|
});
|
||||||
|
thread_view.update_in(cx, |thread_view, window, cx| {
|
||||||
|
thread_view.send(window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
let user_message_editor = thread_view.read_with(cx, |view, cx| {
|
||||||
|
assert_eq!(view.editing_message, None);
|
||||||
|
assert_eq!(view.thread().unwrap().read(cx).entries().len(), 2);
|
||||||
|
|
||||||
|
view.entry_view_state
|
||||||
|
.read(cx)
|
||||||
|
.entry(0)
|
||||||
|
.unwrap()
|
||||||
|
.message_editor()
|
||||||
|
.unwrap()
|
||||||
|
.clone()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Focus
|
||||||
|
cx.focus(&user_message_editor);
|
||||||
|
|
||||||
|
// Edit
|
||||||
|
user_message_editor.update_in(cx, |editor, window, cx| {
|
||||||
|
editor.set_text("Edited message content", window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Send
|
||||||
|
connection.set_next_prompt_updates(vec![acp::SessionUpdate::AgentMessageChunk {
|
||||||
|
content: acp::ContentBlock::Text(acp::TextContent {
|
||||||
|
text: "New Response".into(),
|
||||||
|
annotations: None,
|
||||||
|
}),
|
||||||
|
}]);
|
||||||
|
|
||||||
|
user_message_editor.update_in(cx, |_editor, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(Chat), cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
thread_view.read_with(cx, |view, cx| {
|
||||||
|
assert_eq!(view.editing_message, None);
|
||||||
|
|
||||||
|
let entries = view.thread().unwrap().read(cx).entries();
|
||||||
|
assert_eq!(entries.len(), 2);
|
||||||
|
assert_eq!(
|
||||||
|
entries[0].to_markdown(cx),
|
||||||
|
"## User\n\nEdited message content\n\n"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
entries[1].to_markdown(cx),
|
||||||
|
"## Assistant\n\nNew Response\n\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
let new_editor = view.entry_view_state.read_with(cx, |state, _cx| {
|
||||||
|
assert!(!state.entry(1).unwrap().has_content());
|
||||||
|
state.entry(0).unwrap().message_editor().unwrap().clone()
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(new_editor.read(cx).text(cx), "Edited message content");
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -818,12 +818,10 @@ impl AgentPanel {
|
||||||
ActiveView::Thread { thread, .. } => {
|
ActiveView::Thread { thread, .. } => {
|
||||||
thread.update(cx, |thread, cx| thread.cancel_last_completion(window, cx));
|
thread.update(cx, |thread, cx| thread.cancel_last_completion(window, cx));
|
||||||
}
|
}
|
||||||
ActiveView::ExternalAgentThread { thread_view, .. } => {
|
ActiveView::ExternalAgentThread { .. }
|
||||||
thread_view.update(cx, |thread_element, cx| {
|
| ActiveView::TextThread { .. }
|
||||||
thread_element.cancel_generation(cx)
|
| ActiveView::History
|
||||||
});
|
| ActiveView::Configuration => {}
|
||||||
}
|
|
||||||
ActiveView::TextThread { .. } | ActiveView::History | ActiveView::Configuration => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue