mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 18:41:56 +03:00
Add command palette action events
This commit is contained in:
parent
deac172e39
commit
268d156fad
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1607,6 +1607,7 @@ name = "command_palette"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"client",
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
|
@ -129,6 +129,11 @@ pub enum Event {
|
|||||||
environment: &'static str,
|
environment: &'static str,
|
||||||
milliseconds_since_first_event: i64,
|
milliseconds_since_first_event: i64,
|
||||||
},
|
},
|
||||||
|
Action {
|
||||||
|
source: &'static str,
|
||||||
|
action: String,
|
||||||
|
milliseconds_since_first_event: i64,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[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 {
|
fn milliseconds_since_first_event(&self) -> i64 {
|
||||||
let mut state = self.state.lock();
|
let mut state = self.state.lock();
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ path = "src/command_palette.rs"
|
|||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
client = { path = "../client" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
editor = { path = "../editor" }
|
editor = { path = "../editor" }
|
||||||
fuzzy = { path = "../fuzzy" }
|
fuzzy = { path = "../fuzzy" }
|
||||||
@ -16,9 +17,9 @@ gpui = { path = "../gpui" }
|
|||||||
picker = { path = "../picker" }
|
picker = { path = "../picker" }
|
||||||
project = { path = "../project" }
|
project = { path = "../project" }
|
||||||
settings = { path = "../settings" }
|
settings = { path = "../settings" }
|
||||||
|
theme = { path = "../theme" }
|
||||||
ui = { path = "../ui" }
|
ui = { path = "../ui" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
theme = { path = "../theme" }
|
|
||||||
workspace = { path = "../workspace" }
|
workspace = { path = "../workspace" }
|
||||||
zed_actions = { path = "../zed_actions" }
|
zed_actions = { path = "../zed_actions" }
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
@ -3,6 +3,7 @@ use std::{
|
|||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use client::telemetry::Telemetry;
|
||||||
use collections::{CommandPaletteFilter, HashMap};
|
use collections::{CommandPaletteFilter, HashMap};
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@ -39,11 +40,18 @@ impl CommandPalette {
|
|||||||
let Some(previous_focus_handle) = cx.focused() else {
|
let Some(previous_focus_handle) = cx.focused() else {
|
||||||
return;
|
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 filter = cx.try_global::<CommandPaletteFilter>();
|
||||||
|
|
||||||
let commands = cx
|
let commands = cx
|
||||||
@ -66,8 +74,12 @@ impl CommandPalette {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let delegate =
|
let delegate = CommandPaletteDelegate::new(
|
||||||
CommandPaletteDelegate::new(cx.view().downgrade(), commands, previous_focus_handle);
|
cx.view().downgrade(),
|
||||||
|
commands,
|
||||||
|
telemetry,
|
||||||
|
previous_focus_handle,
|
||||||
|
);
|
||||||
|
|
||||||
let picker = cx.new_view(|cx| Picker::new(delegate, cx));
|
let picker = cx.new_view(|cx| Picker::new(delegate, cx));
|
||||||
Self { picker }
|
Self { picker }
|
||||||
@ -103,6 +115,7 @@ pub struct CommandPaletteDelegate {
|
|||||||
commands: Vec<Command>,
|
commands: Vec<Command>,
|
||||||
matches: Vec<StringMatch>,
|
matches: Vec<StringMatch>,
|
||||||
selected_ix: usize,
|
selected_ix: usize,
|
||||||
|
telemetry: Arc<Telemetry>,
|
||||||
previous_focus_handle: FocusHandle,
|
previous_focus_handle: FocusHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +143,7 @@ impl CommandPaletteDelegate {
|
|||||||
fn new(
|
fn new(
|
||||||
command_palette: WeakView<CommandPalette>,
|
command_palette: WeakView<CommandPalette>,
|
||||||
commands: Vec<Command>,
|
commands: Vec<Command>,
|
||||||
|
telemetry: Arc<Telemetry>,
|
||||||
previous_focus_handle: FocusHandle,
|
previous_focus_handle: FocusHandle,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -138,6 +152,7 @@ impl CommandPaletteDelegate {
|
|||||||
matches: vec![],
|
matches: vec![],
|
||||||
commands,
|
commands,
|
||||||
selected_ix: 0,
|
selected_ix: 0,
|
||||||
|
telemetry,
|
||||||
previous_focus_handle,
|
previous_focus_handle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,6 +299,10 @@ impl PickerDelegate for CommandPaletteDelegate {
|
|||||||
}
|
}
|
||||||
let action_ix = self.matches[self.selected_ix].candidate_id;
|
let action_ix = self.matches[self.selected_ix].candidate_id;
|
||||||
let command = self.commands.swap_remove(action_ix);
|
let command = self.commands.swap_remove(action_ix);
|
||||||
|
|
||||||
|
self.telemetry
|
||||||
|
.report_action_event("command palette", command.name.clone());
|
||||||
|
|
||||||
self.matches.clear();
|
self.matches.clear();
|
||||||
self.commands.clear();
|
self.commands.clear();
|
||||||
cx.update_global(|hit_counts: &mut HitCounts, _| {
|
cx.update_global(|hit_counts: &mut HitCounts, _| {
|
||||||
|
Loading…
Reference in New Issue
Block a user