From afe75e8cbd750a7b18dbf6d5dfacefdaa9be7adf Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Tue, 16 May 2023 14:02:36 -0400 Subject: [PATCH] Send copilot events even if file_extension is not known at the time --- crates/editor/src/editor.rs | 39 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b4af9abb85..c51ed1a14a 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6888,25 +6888,28 @@ impl Editor { suggestion_accepted: bool, cx: &AppContext, ) { - if let Some((project, file)) = self.project.as_ref().zip( - self.buffer - .read(cx) - .as_singleton() - .and_then(|b| b.read(cx).file()), - ) { - let telemetry_settings = cx.global::().telemetry(); - let extension = Path::new(file.file_name(cx)) - .extension() - .and_then(|e| e.to_str()); - let telemetry = project.read(cx).client().telemetry().clone(); + let Some(project) = &self.project else { + return + }; - let event = ClickhouseEvent::Copilot { - suggestion_id, - suggestion_accepted, - file_extension: extension.map(ToString::to_string), - }; - telemetry.report_clickhouse_event(event, telemetry_settings); - } + // 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) {