diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 7151dcd7bb0606efc59a5dec68669a4d7273d651..5e3c78420d978283b7009bf77d3d576bdc5a4773 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -86,6 +86,11 @@ pub enum ClickhouseEvent { copilot_enabled: bool, copilot_enabled_for_language: bool, }, + Copilot { + suggestion_id: Option, + suggestion_accepted: bool, + file_extension: Option, + }, } #[derive(Serialize, Debug)] diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index 9ccd9c445df45388ad64f8942292ae5e03c37564..65d0a19bedb0d90454d492065d0886e596255de5 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -258,7 +258,7 @@ impl RegisteredBuffer { #[derive(Debug)] pub struct Completion { - uuid: String, + pub uuid: String, pub range: Range, pub text: String, } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b6d44397a9c4933a0a7e6a7f990c9fdc2515b0a2..ff4c0846cb79396a91bed4124ac0b95ed5abd3e1 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3097,6 +3097,8 @@ impl Editor { copilot .update(cx, |copilot, cx| copilot.accept_completion(completion, cx)) .detach_and_log_err(cx); + + self.report_copilot_event(Some(completion.uuid.clone()), true, cx) } self.insert_with_autoindent_mode(&suggestion.text.to_string(), None, cx); cx.notify(); @@ -3114,6 +3116,8 @@ impl Editor { copilot.discard_completions(&self.copilot_state.completions, cx) }) .detach_and_log_err(cx); + + self.report_copilot_event(None, false, cx) } self.display_map @@ -6876,6 +6880,36 @@ impl Editor { .collect() } + fn report_copilot_event( + &self, + suggestion_id: Option, + suggestion_accepted: bool, + cx: &AppContext, + ) { + let Some(project) = &self.project else { + return + }; + + // If None, we are either getting suggestions in a new, unsaved file, or in a file without an extension + let file_extension = self + .buffer + .read(cx) + .as_singleton() + .and_then(|b| b.read(cx).file()) + .and_then(|file| Path::new(file.file_name(cx)).extension()) + .and_then(|e| e.to_str()); + + let telemetry = project.read(cx).client().telemetry().clone(); + let telemetry_settings = cx.global::().telemetry(); + + let event = ClickhouseEvent::Copilot { + suggestion_id, + suggestion_accepted, + file_extension: file_extension.map(ToString::to_string), + }; + telemetry.report_clickhouse_event(event, telemetry_settings); + } + fn report_editor_event(&self, name: &'static str, cx: &AppContext) { if let Some((project, file)) = self.project.as_ref().zip( self.buffer