mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-13 05:42:59 +00:00
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:
parent
e8c72d91c3
commit
dd66a20d78
1 changed files with 34 additions and 27 deletions
|
@ -7,7 +7,8 @@ use client::Client;
|
||||||
use collections::{HashMap, HashSet, VecDeque};
|
use collections::{HashMap, HashSet, VecDeque};
|
||||||
use futures::AsyncReadExt;
|
use futures::AsyncReadExt;
|
||||||
use gpui::{
|
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 http_client::{HttpClient, Method};
|
||||||
use language::{
|
use language::{
|
||||||
|
@ -313,7 +314,9 @@ impl Zeta {
|
||||||
path,
|
path,
|
||||||
input_events,
|
input_events,
|
||||||
input_excerpt,
|
input_excerpt,
|
||||||
)?;
|
&cx,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.recent_completions
|
this.recent_completions
|
||||||
|
@ -543,37 +546,41 @@ and then another
|
||||||
path: Arc<Path>,
|
path: Arc<Path>,
|
||||||
input_events: String,
|
input_events: String,
|
||||||
input_excerpt: String,
|
input_excerpt: String,
|
||||||
) -> Result<InlineCompletion> {
|
cx: &AsyncAppContext,
|
||||||
let content = output_excerpt.replace(CURSOR_MARKER, "");
|
) -> Task<Result<InlineCompletion>> {
|
||||||
|
let snapshot = snapshot.clone();
|
||||||
|
cx.background_executor().spawn(async move {
|
||||||
|
let content = output_excerpt.replace(CURSOR_MARKER, "");
|
||||||
|
|
||||||
let codefence_start = content
|
let codefence_start = content
|
||||||
.find(EDITABLE_REGION_START_MARKER)
|
.find(EDITABLE_REGION_START_MARKER)
|
||||||
.context("could not find start marker")?;
|
.context("could not find start marker")?;
|
||||||
let content = &content[codefence_start..];
|
let content = &content[codefence_start..];
|
||||||
|
|
||||||
let newline_ix = content.find('\n').context("could not find newline")?;
|
let newline_ix = content.find('\n').context("could not find newline")?;
|
||||||
let content = &content[newline_ix + 1..];
|
let content = &content[newline_ix + 1..];
|
||||||
|
|
||||||
let codefence_end = content
|
let codefence_end = content
|
||||||
.rfind(&format!("\n{EDITABLE_REGION_END_MARKER}"))
|
.rfind(&format!("\n{EDITABLE_REGION_END_MARKER}"))
|
||||||
.context("could not find end marker")?;
|
.context("could not find end marker")?;
|
||||||
let new_text = &content[..codefence_end];
|
let new_text = &content[..codefence_end];
|
||||||
|
|
||||||
let old_text = snapshot
|
let old_text = snapshot
|
||||||
.text_for_range(excerpt_range.clone())
|
.text_for_range(excerpt_range.clone())
|
||||||
.collect::<String>();
|
.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 {
|
Ok(InlineCompletion {
|
||||||
id: InlineCompletionId::new(),
|
id: InlineCompletionId::new(),
|
||||||
path,
|
path,
|
||||||
excerpt_range,
|
excerpt_range,
|
||||||
edits: edits.into(),
|
edits: edits.into(),
|
||||||
snapshot: snapshot.clone(),
|
snapshot: snapshot.clone(),
|
||||||
input_events: input_events.into(),
|
input_events: input_events.into(),
|
||||||
input_excerpt: input_excerpt.into(),
|
input_excerpt: input_excerpt.into(),
|
||||||
output_excerpt: output_excerpt.into(),
|
output_excerpt: output_excerpt.into(),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue