Move prediction diff computation to background thread (#21862)

Release Notes:

- N/A

Co-authored-by: Thorsten <thorsten@zed.dev>
Co-authored-by: Cole <cole@zed.dev>
Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-12-11 17:12:58 +01:00 committed by GitHub
parent e8c72d91c3
commit dd66a20d78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,7 +7,8 @@ use client::Client;
use collections::{HashMap, HashSet, VecDeque};
use futures::AsyncReadExt;
use gpui::{
actions, AppContext, Context, EntityId, Global, Model, ModelContext, Subscription, Task,
actions, AppContext, AsyncAppContext, Context, EntityId, Global, Model, ModelContext,
Subscription, Task,
};
use http_client::{HttpClient, Method};
use language::{
@ -313,7 +314,9 @@ impl Zeta {
path,
input_events,
input_excerpt,
)?;
&cx,
)
.await?;
this.update(&mut cx, |this, cx| {
this.recent_completions
@ -543,7 +546,10 @@ and then another
path: Arc<Path>,
input_events: String,
input_excerpt: String,
) -> Result<InlineCompletion> {
cx: &AsyncAppContext,
) -> Task<Result<InlineCompletion>> {
let snapshot = snapshot.clone();
cx.background_executor().spawn(async move {
let content = output_excerpt.replace(CURSOR_MARKER, "");
let codefence_start = content
@ -563,7 +569,7 @@ and then another
.text_for_range(excerpt_range.clone())
.collect::<String>();
let edits = Self::compute_edits(old_text, new_text, excerpt_range.start, snapshot);
let edits = Self::compute_edits(old_text, new_text, excerpt_range.start, &snapshot);
Ok(InlineCompletion {
id: InlineCompletionId::new(),
@ -575,6 +581,7 @@ and then another
input_excerpt: input_excerpt.into(),
output_excerpt: output_excerpt.into(),
})
})
}
pub fn compute_edits(