assistant: Track completions for each CodegenAlternative (#19999)
Some checks are pending
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run

Release Notes:

- N/A

Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
This commit is contained in:
Adam Wolff 2024-11-10 08:22:24 -08:00 committed by GitHub
parent ebdc255b73
commit da7670cd6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2562,6 +2562,7 @@ pub struct CodegenAlternative {
line_operations: Vec<LineOperation>,
request: Option<LanguageModelRequest>,
elapsed_time: Option<f64>,
completion: Option<String>,
message_id: Option<String>,
}
@ -2637,6 +2638,7 @@ impl CodegenAlternative {
range,
request: None,
elapsed_time: None,
completion: None,
}
}
@ -2849,6 +2851,9 @@ impl CodegenAlternative {
self.diff = Diff::default();
self.status = CodegenStatus::Pending;
let mut edit_start = self.range.start.to_offset(&snapshot);
let completion = Arc::new(Mutex::new(String::new()));
let completion_clone = completion.clone();
self.generation = cx.spawn(|codegen, mut cx| {
async move {
let stream = stream.await;
@ -2880,6 +2885,7 @@ impl CodegenAlternative {
response_latency = Some(request_start.elapsed());
}
let chunk = chunk?;
completion_clone.lock().push_str(&chunk);
let mut lines = chunk.split('\n').peekable();
while let Some(line) = lines.next() {
@ -3049,6 +3055,7 @@ impl CodegenAlternative {
this.status = CodegenStatus::Done;
}
this.elapsed_time = Some(elapsed_time);
this.completion = Some(completion.lock().clone());
cx.emit(CodegenEvent::Finished);
cx.notify();
})