Send editor event when saving a new file

This commit is contained in:
Joseph Lyons 2023-05-16 18:16:09 -04:00
parent 2e27f26339
commit c27859871f
2 changed files with 49 additions and 34 deletions

View file

@ -1330,7 +1330,7 @@ impl Editor {
cx.set_global(ScrollbarAutoHide(should_auto_hide_scrollbars)); cx.set_global(ScrollbarAutoHide(should_auto_hide_scrollbars));
} }
this.report_editor_event("open", cx); this.report_editor_event("open", None, cx);
this this
} }
@ -6897,7 +6897,8 @@ impl Editor {
.as_singleton() .as_singleton()
.and_then(|b| b.read(cx).file()) .and_then(|b| b.read(cx).file())
.and_then(|file| Path::new(file.file_name(cx)).extension()) .and_then(|file| Path::new(file.file_name(cx)).extension())
.and_then(|e| e.to_str()); .and_then(|e| e.to_str())
.map(|a| a.to_string());
let telemetry = project.read(cx).client().telemetry().clone(); let telemetry = project.read(cx).client().telemetry().clone();
let telemetry_settings = cx.global::<Settings>().telemetry(); let telemetry_settings = cx.global::<Settings>().telemetry();
@ -6905,49 +6906,58 @@ impl Editor {
let event = ClickhouseEvent::Copilot { let event = ClickhouseEvent::Copilot {
suggestion_id, suggestion_id,
suggestion_accepted, suggestion_accepted,
file_extension: file_extension.map(ToString::to_string), file_extension,
}; };
telemetry.report_clickhouse_event(event, telemetry_settings); telemetry.report_clickhouse_event(event, telemetry_settings);
} }
fn report_editor_event(&self, name: &'static str, cx: &AppContext) { fn report_editor_event(
if let Some((project, file)) = self.project.as_ref().zip( &self,
self.buffer name: &'static str,
.read(cx) file_extension: Option<String>,
.as_singleton() cx: &AppContext,
.and_then(|b| b.read(cx).file()), ) {
) { let Some(project) = &self.project else {
let settings = cx.global::<Settings>(); return
};
let extension = Path::new(file.file_name(cx)) // If None, we are in a file without an extension
.extension() let file_extension = file_extension.or(self
.and_then(|e| e.to_str()); .buffer
let telemetry = project.read(cx).client().telemetry().clone(); .read(cx)
telemetry.report_mixpanel_event( .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())
.map(|a| a.to_string()));
let settings = cx.global::<Settings>();
let telemetry = project.read(cx).client().telemetry().clone();
telemetry.report_mixpanel_event(
match name { match name {
"open" => "open editor", "open" => "open editor",
"save" => "save editor", "save" => "save editor",
_ => name, _ => name,
}, },
json!({ "File Extension": extension, "Vim Mode": settings.vim_mode, "In Clickhouse": true }), json!({ "File Extension": file_extension, "Vim Mode": settings.vim_mode, "In Clickhouse": true }),
settings.telemetry(), settings.telemetry(),
); );
let event = ClickhouseEvent::Editor { let event = ClickhouseEvent::Editor {
file_extension: extension.map(ToString::to_string), file_extension,
vim_mode: settings.vim_mode, vim_mode: settings.vim_mode,
operation: name, operation: name,
copilot_enabled: settings.features.copilot, copilot_enabled: settings.features.copilot,
copilot_enabled_for_language: settings.show_copilot_suggestions( copilot_enabled_for_language: settings.show_copilot_suggestions(
self.language_at(0, cx) self.language_at(0, cx)
.map(|language| language.name()) .map(|language| language.name())
.as_deref(), .as_deref(),
self.file_at(0, cx) self.file_at(0, cx)
.map(|file| file.path().clone()) .map(|file| file.path().clone())
.as_deref(), .as_deref(),
), ),
}; };
telemetry.report_clickhouse_event(event, settings.telemetry()) telemetry.report_clickhouse_event(event, settings.telemetry())
}
} }
/// Copy the highlighted chunks to the clipboard as JSON. The format is an array of lines, /// Copy the highlighted chunks to the clipboard as JSON. The format is an array of lines,

View file

@ -637,7 +637,7 @@ impl Item for Editor {
project: ModelHandle<Project>, project: ModelHandle<Project>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
self.report_editor_event("save", cx); self.report_editor_event("save", None, cx);
let format = self.perform_format(project.clone(), FormatTrigger::Save, cx); let format = self.perform_format(project.clone(), FormatTrigger::Save, cx);
let buffers = self.buffer().clone().read(cx).all_buffers(); let buffers = self.buffer().clone().read(cx).all_buffers();
cx.spawn(|_, mut cx| async move { cx.spawn(|_, mut cx| async move {
@ -686,6 +686,11 @@ impl Item for Editor {
.as_singleton() .as_singleton()
.expect("cannot call save_as on an excerpt list"); .expect("cannot call save_as on an excerpt list");
let file_extension = abs_path
.extension()
.map(|a| a.to_string_lossy().to_string());
self.report_editor_event("save", file_extension, cx);
project.update(cx, |project, cx| { project.update(cx, |project, cx| {
project.save_buffer_as(buffer, abs_path, cx) project.save_buffer_as(buffer, abs_path, cx)
}) })