WIP

Joseph T. Lyons created

Change summary

crates/client/src/telemetry.rs               |  7 +------
crates/terminal_view/src/terminal_element.rs | 17 +++++++++++++++--
crates/terminal_view/src/terminal_view.rs    |  4 ++++
3 files changed, 20 insertions(+), 8 deletions(-)

Detailed changes

crates/client/src/telemetry.rs 🔗

@@ -1,7 +1,3 @@
-// TODO - Test if locking slows Zed typing down
-// TODO - Make sure to send last event on flush
-// TODO - Move code to be used as arcs in editor and terminal
-
 mod event_coalescer;
 
 use crate::{TelemetrySettings, ZED_SECRET_CLIENT_TOKEN, ZED_SERVER_URL};
@@ -408,8 +404,8 @@ impl Telemetry {
 
     pub fn log_edit_event(self: &Arc<Self>, environment: &'static str) {
         let mut state = self.state.lock();
-
         let coalesced_duration = state.edit_activity.log_event(environment);
+        drop(state);
 
         if let Some((start, end)) = coalesced_duration {
             let event = Event::Edit {
@@ -418,7 +414,6 @@ impl Telemetry {
                 milliseconds_since_first_event: self.milliseconds_since_first_event(),
             };
 
-            drop(state);
             self.report_event(event);
         }
     }

crates/terminal_view/src/terminal_element.rs 🔗

@@ -6,7 +6,7 @@ use gpui::{
     InteractiveElementState, Interactivity, IntoElement, LayoutId, Model, ModelContext,
     ModifiersChangedEvent, MouseButton, MouseMoveEvent, Pixels, PlatformInputHandler, Point,
     ShapedLine, StatefulInteractiveElement, Styled, TextRun, TextStyle, TextSystem, UnderlineStyle,
-    WhiteSpace, WindowContext,
+    WeakView, WhiteSpace, WindowContext,
 };
 use itertools::Itertools;
 use language::CursorShape;
@@ -24,6 +24,7 @@ use terminal::{
 };
 use theme::{ActiveTheme, Theme, ThemeSettings};
 use ui::Tooltip;
+use workspace::Workspace;
 
 use std::mem;
 use std::{fmt::Debug, ops::RangeInclusive};
@@ -142,6 +143,7 @@ impl LayoutRect {
 ///We need to keep a reference to the view for mouse events, do we need it for any other terminal stuff, or can we move that to connection?
 pub struct TerminalElement {
     terminal: Model<Terminal>,
+    workspace: WeakView<Workspace>,
     focus: FocusHandle,
     focused: bool,
     cursor_visible: bool,
@@ -160,6 +162,7 @@ impl StatefulInteractiveElement for TerminalElement {}
 impl TerminalElement {
     pub fn new(
         terminal: Model<Terminal>,
+        workspace: WeakView<Workspace>,
         focus: FocusHandle,
         focused: bool,
         cursor_visible: bool,
@@ -167,6 +170,7 @@ impl TerminalElement {
     ) -> TerminalElement {
         TerminalElement {
             terminal,
+            workspace,
             focused,
             focus: focus.clone(),
             cursor_visible,
@@ -762,6 +766,7 @@ impl Element for TerminalElement {
                 .cursor
                 .as_ref()
                 .map(|cursor| cursor.bounding_rect(origin)),
+            workspace: self.workspace.clone(),
         };
 
         self.register_mouse_listeners(origin, layout.mode, bounds, cx);
@@ -831,6 +836,7 @@ impl IntoElement for TerminalElement {
 struct TerminalInputHandler {
     cx: AsyncWindowContext,
     terminal: Model<Terminal>,
+    workspace: WeakView<Workspace>,
     cursor_bounds: Option<Bounds<Pixels>>,
 }
 
@@ -871,7 +877,14 @@ impl PlatformInputHandler for TerminalInputHandler {
             .update(|_, cx| {
                 self.terminal.update(cx, |terminal, _| {
                     terminal.input(text.into());
-                })
+                });
+
+                self.workspace
+                    .update(cx, |this, cx| {
+                        let telemetry = this.project().read(cx).client().telemetry().clone();
+                        telemetry.log_edit_event("terminal");
+                    })
+                    .ok();
             })
             .ok();
     }

crates/terminal_view/src/terminal_view.rs 🔗

@@ -73,6 +73,7 @@ pub fn init(cx: &mut AppContext) {
 ///A terminal view, maintains the PTY's file handles and communicates with the terminal
 pub struct TerminalView {
     terminal: Model<Terminal>,
+    workspace: WeakView<Workspace>,
     focus_handle: FocusHandle,
     has_new_content: bool,
     //Currently using iTerm bell, show bell emoji in tab until input is received
@@ -135,6 +136,7 @@ impl TerminalView {
         workspace_id: WorkspaceId,
         cx: &mut ViewContext<Self>,
     ) -> Self {
+        let workspace_handle = workspace.clone();
         cx.observe(&terminal, |_, _, cx| cx.notify()).detach();
         cx.subscribe(&terminal, move |this, _, event, cx| match event {
             Event::Wakeup => {
@@ -279,6 +281,7 @@ impl TerminalView {
 
         Self {
             terminal,
+            workspace: workspace_handle,
             has_new_content: true,
             has_bell: false,
             focus_handle: cx.focus_handle(),
@@ -661,6 +664,7 @@ impl Render for TerminalView {
                 // TODO: Oddly this wrapper div is needed for TerminalElement to not steal events from the context menu
                 div().size_full().child(TerminalElement::new(
                     terminal_handle,
+                    self.workspace.clone(),
                     self.focus_handle.clone(),
                     focused,
                     self.should_show_cursor(focused, cx),