History

assistant panel: Fix pending completions not being cleaned up (#16201)

Turns out that you could always cancel a completion, even if it was already done and completed, because it was never cleaned up. Release Notes: - N/A

Thorsten Ball committed 2 years ago

Commit b7dcd4e1 parent 8b8335f1 file · +4 −3Browse files

Unified · Split

crates/assistant/src/context.rs+4−3
@@ -1713,6 +1713,8 @@ impl Context { · 1712 unmodified lines
17131713 .insert_message_after(assistant_message.id, Role::User, MessageStatus::Done, cx)
17141714 .unwrap();
17151715
1716+ let pending_completion_id = post_inc(&mut self.completion_count);
1717+
17161718 let task = cx.spawn({
17171719 |this, mut cx| async move {
17181720 let stream = model.stream_completion(request, &cx);
@@ -1761,10 +1763,9 @@ impl Context { · 42 unmodified lines
17611763 })?;
17621764 smol::future::yield_now().await;
17631765 }
1764−
17651766 this.update(&mut cx, |this, cx| {
17661767 this.pending_completions
1767− .retain(|completion| completion.id != this.completion_count);
1768+ .retain(|completion| completion.id != pending_completion_id);
17681769 this.summarize(false, cx);
17691770 })?;
17701771
@@ -1806,7 +1807,7 @@ impl Context { · 35 unmodified lines
18061807 });
18071808
18081809 self.pending_completions.push(PendingCompletion {
1809− id: post_inc(&mut self.completion_count),
1810+ id: pending_completion_id,
18101811 assistant_message_id: assistant_message.id,
18111812 _task: task,
18121813 });