Include prediction ID on edit prediction accepted/discarded events (#24480)

This PR updates the edit predictions to include the prediction ID
returned from the server on the resulting telemetry events indicating
whether the prediction was accepted or discarded.

The `prediction_id` on the events can then be correlated with the
`request_id` on the server-side prediction events.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-02-07 17:06:37 -05:00 committed by GitHub
parent ed5656813c
commit e17e838c07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 47 additions and 20 deletions

View file

@ -490,6 +490,7 @@ enum InlineCompletion {
struct InlineCompletionState {
inlay_ids: Vec<InlayId>,
completion: InlineCompletion,
completion_id: Option<SharedString>,
invalidation_range: Range<Anchor>,
}
@ -4893,7 +4894,11 @@ impl Editor {
return;
};
self.report_inline_completion_event(true, cx);
self.report_inline_completion_event(
active_inline_completion.completion_id.clone(),
true,
cx,
);
match &active_inline_completion.completion {
InlineCompletion::Move { target, .. } => {
@ -4942,7 +4947,11 @@ impl Editor {
return;
}
self.report_inline_completion_event(true, cx);
self.report_inline_completion_event(
active_inline_completion.completion_id.clone(),
true,
cx,
);
match &active_inline_completion.completion {
InlineCompletion::Move { target, .. } => {
@ -5000,7 +5009,12 @@ impl Editor {
cx: &mut Context<Self>,
) -> bool {
if should_report_inline_completion_event {
self.report_inline_completion_event(false, cx);
let completion_id = self
.active_inline_completion
.as_ref()
.and_then(|active_completion| active_completion.completion_id.clone());
self.report_inline_completion_event(completion_id, false, cx);
}
if let Some(provider) = self.edit_prediction_provider() {
@ -5010,7 +5024,7 @@ impl Editor {
self.take_active_inline_completion(cx)
}
fn report_inline_completion_event(&self, accepted: bool, cx: &App) {
fn report_inline_completion_event(&self, id: Option<SharedString>, accepted: bool, cx: &App) {
let Some(provider) = self.edit_prediction_provider() else {
return;
};
@ -5035,6 +5049,7 @@ impl Editor {
telemetry::event!(
event_type,
provider = provider.name(),
prediction_id = id,
suggestion_accepted = accepted,
file_extension = extension,
);
@ -5250,6 +5265,7 @@ impl Editor {
self.active_inline_completion = Some(InlineCompletionState {
inlay_ids,
completion,
completion_id: inline_completion.id,
invalidation_range,
});

View file

@ -333,6 +333,7 @@ fn propose_edits<T: ToOffset>(
cx.update(|_, cx| {
provider.update(cx, |provider, _| {
provider.set_inline_completion(Some(inline_completion::InlineCompletion {
id: None,
edits: edits.collect(),
edit_preview: None,
}))