Report editor open and save events to Amplitude

Co-authored-by: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Nathan Sobo
2022-09-26 18:18:34 -06:00
co-authored by Max Brunsfeld
parent f0c50c1e0a
commit 824fdb54e6
8 changed files with 137 additions and 35 deletions
+21
View File
@@ -29,6 +29,7 @@ use gpui::{
geometry::vector::{vec2f, Vector2F},
impl_actions, impl_internal_actions,
platform::CursorStyle,
serde_json::json,
text_layout, AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Element, ElementBox,
Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, Task, View,
ViewContext, ViewHandle, WeakViewHandle,
@@ -1053,6 +1054,7 @@ impl Editor {
let editor_created_event = EditorCreated(cx.handle());
cx.emit_global(editor_created_event);
this.report_event("open editor", cx);
this
}
@@ -5928,6 +5930,25 @@ impl Editor {
})
.collect()
}
fn report_event(&self, name: &str, 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()),
) {
project.read(cx).client().report_event(
name,
json!({
"file_extension": file
.path()
.extension()
.and_then(|e| e.to_str())
}),
);
}
}
}
impl EditorSnapshot {
+1
View File
@@ -410,6 +410,7 @@ impl Item for Editor {
let buffers = buffer.read(cx).all_buffers();
let mut timeout = cx.background().timer(FORMAT_TIMEOUT).fuse();
let format = project.update(cx, |project, cx| project.format(buffers, true, cx));
self.report_event("save editor", cx);
cx.spawn(|_, mut cx| async move {
let transaction = futures::select_biased! {
_ = timeout => {