Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add command palette action events
Joseph T. Lyons268d156fad72
diff --git a/Cargo.lock b/Cargo.lockindex 056fab49cd5..090980ac3eb 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1607,6 +1607,7 @@ name = "command_palette"version = "0.1.0"dependencies = ["anyhow",+ "client","collections","ctor","editor",diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rsindex 6276548e4cf..32cf9efba23 100644--- a/crates/client/src/telemetry.rs+++ b/crates/client/src/telemetry.rs@@ -129,6 +129,11 @@ pub enum Event {environment: &'static str,milliseconds_since_first_event: i64,},+ Action {+ source: &'static str,+ action: String,+ milliseconds_since_first_event: i64,+ },}#[cfg(debug_assertions)]@@ -420,6 +425,16 @@ impl Telemetry {}}+ pub fn report_action_event(self: &Arc<Self>, source: &'static str, action: String) {+ let event = Event::Action {+ source,+ action,+ milliseconds_since_first_event: self.milliseconds_since_first_event(),+ };++ self.report_event(event)+ }+fn milliseconds_since_first_event(&self) -> i64 {let mut state = self.state.lock();diff --git a/crates/command_palette/Cargo.toml b/crates/command_palette/Cargo.tomlindex 39ed4fd95e1..c762af7c487 100644--- a/crates/command_palette/Cargo.toml+++ b/crates/command_palette/Cargo.toml@@ -9,6 +9,7 @@ path = "src/command_palette.rs"doctest = false[dependencies]+client = { path = "../client" }collections = { path = "../collections" }editor = { path = "../editor" }fuzzy = { path = "../fuzzy" }@@ -16,9 +17,9 @@ gpui = { path = "../gpui" }picker = { path = "../picker" }project = { path = "../project" }settings = { path = "../settings" }+theme = { path = "../theme" }ui = { path = "../ui" }util = { path = "../util" }-theme = { path = "../theme" }workspace = { path = "../workspace" }zed_actions = { path = "../zed_actions" }anyhow.workspace = truediff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex e077426bb84..c90e4488656 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -3,6 +3,7 @@ use std::{sync::Arc,};+use client::telemetry::Telemetry;use collections::{CommandPaletteFilter, HashMap};use fuzzy::{StringMatch, StringMatchCandidate};use gpui::{@@ -39,11 +40,18 @@ impl CommandPalette {let Some(previous_focus_handle) = cx.focused() else {return;};- workspace.toggle_modal(cx, move |cx| CommandPalette::new(previous_focus_handle, cx));+ let telemetry = workspace.client().telemetry().clone();+ workspace.toggle_modal(cx, move |cx| {+ CommandPalette::new(previous_focus_handle, telemetry, cx)+ });});}- fn new(previous_focus_handle: FocusHandle, cx: &mut ViewContext<Self>) -> Self {+ fn new(+ previous_focus_handle: FocusHandle,+ telemetry: Arc<Telemetry>,+ cx: &mut ViewContext<Self>,+ ) -> Self {let filter = cx.try_global::<CommandPaletteFilter>();let commands = cx@@ -66,8 +74,12 @@ impl CommandPalette {}).collect();- let delegate =- CommandPaletteDelegate::new(cx.view().downgrade(), commands, previous_focus_handle);+ let delegate = CommandPaletteDelegate::new(+ cx.view().downgrade(),+ commands,+ telemetry,+ previous_focus_handle,+ );let picker = cx.new_view(|cx| Picker::new(delegate, cx));Self { picker }@@ -103,6 +115,7 @@ pub struct CommandPaletteDelegate {commands: Vec<Command>,matches: Vec<StringMatch>,selected_ix: usize,+ telemetry: Arc<Telemetry>,previous_focus_handle: FocusHandle,}@@ -130,6 +143,7 @@ impl CommandPaletteDelegate {fn new(command_palette: WeakView<CommandPalette>,commands: Vec<Command>,+ telemetry: Arc<Telemetry>,previous_focus_handle: FocusHandle,) -> Self {Self {@@ -138,6 +152,7 @@ impl CommandPaletteDelegate {matches: vec![],commands,selected_ix: 0,+ telemetry,previous_focus_handle,}}@@ -284,6 +299,10 @@ impl PickerDelegate for CommandPaletteDelegate {}let action_ix = self.matches[self.selected_ix].candidate_id;let command = self.commands.swap_remove(action_ix);++ self.telemetry+ .report_action_event("command palette", command.name.clone());+self.matches.clear();self.commands.clear();cx.update_global(|hit_counts: &mut HitCounts, _| {