This commit is contained in:
Cole Miller 2025-08-08 01:29:07 -04:00
parent d6022dc87c
commit fbd27148d5
2 changed files with 30 additions and 30 deletions

View file

@ -6,7 +6,6 @@ use anyhow::{Context as _, Result};
use assistant_tool::ActionLog; use assistant_tool::ActionLog;
use buffer_diff::BufferDiff; use buffer_diff::BufferDiff;
use editor::{Bias, MultiBuffer, PathKey}; use editor::{Bias, MultiBuffer, PathKey};
use futures::future::{Fuse, FusedFuture};
use futures::{FutureExt, channel::oneshot, future::BoxFuture}; use futures::{FutureExt, channel::oneshot, future::BoxFuture};
use gpui::{AppContext, Context, Entity, EventEmitter, SharedString, Task}; use gpui::{AppContext, Context, Entity, EventEmitter, SharedString, Task};
use itertools::Itertools; use itertools::Itertools;
@ -580,7 +579,7 @@ pub struct AcpThread {
project: Entity<Project>, project: Entity<Project>,
action_log: Entity<ActionLog>, action_log: Entity<ActionLog>,
shared_buffers: HashMap<Entity<Buffer>, BufferSnapshot>, shared_buffers: HashMap<Entity<Buffer>, BufferSnapshot>,
send_task: Option<Fuse<Task<()>>>, send_task: Option<Task<()>>,
connection: Rc<dyn AgentConnection>, connection: Rc<dyn AgentConnection>,
session_id: acp::SessionId, session_id: acp::SessionId,
} }
@ -670,11 +669,7 @@ impl AcpThread {
} }
pub fn status(&self) -> ThreadStatus { pub fn status(&self) -> ThreadStatus {
if self if self.send_task.as_ref().map_or(false, |t| !t.is_finished()) {
.send_task
.as_ref()
.map_or(false, |t| !t.is_terminated())
{
if self.waiting_for_tool_confirmation() { if self.waiting_for_tool_confirmation() {
ThreadStatus::WaitingForToolConfirmation ThreadStatus::WaitingForToolConfirmation
} else { } else {
@ -1049,31 +1044,28 @@ impl AcpThread {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
let cancel_task = self.cancel(cx); let cancel_task = self.cancel(cx);
self.send_task = Some( self.send_task = Some(cx.spawn(async move |this, cx| {
cx.spawn(async move |this, cx| { async {
async { cancel_task.await;
cancel_task.await;
let result = this let result = this
.update(cx, |this, cx| { .update(cx, |this, cx| {
this.connection.prompt( this.connection.prompt(
acp::PromptRequest { acp::PromptRequest {
prompt: message, prompt: message,
session_id: this.session_id.clone(), session_id: this.session_id.clone(),
}, },
cx, cx,
) )
})? })?
.await; .await;
tx.send(result).log_err(); tx.send(result).log_err();
anyhow::Ok(()) anyhow::Ok(())
} }
.await .await
.log_err(); .log_err();
}) }));
.fuse(),
);
cx.spawn(async move |this, cx| match rx.await { cx.spawn(async move |this, cx| match rx.await {
Ok(Err(e)) => { Ok(Err(e)) => {

View file

@ -79,6 +79,14 @@ impl<T> Task<T> {
Task(TaskState::Spawned(task)) => task.detach(), Task(TaskState::Spawned(task)) => task.detach(),
} }
} }
/// Whether the task has run to completion.
pub fn is_finished(&self) -> bool {
match self {
Task(TaskState::Ready(_)) => true,
Task(TaskState::Spawned(task)) => task.is_finished(),
}
}
} }
impl<E, T> Task<Result<T, E>> impl<E, T> Task<Result<T, E>>