Skip to content

Commit

Permalink
assistant: Track completions for each CodegenAlternative (#19999)
Browse files Browse the repository at this point in the history
Release Notes:

- N/A

Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
  • Loading branch information
wolffiex and bennetbo authored Nov 10, 2024
1 parent ebdc255 commit da7670c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/assistant/src/inline_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand Down Expand Up @@ -2637,6 +2638,7 @@ impl CodegenAlternative {
range,
request: None,
elapsed_time: None,
completion: None,
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
})
Expand Down

0 comments on commit da7670c

Please sign in to comment.