Skip to content

Commit

Permalink
repl event too
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Dec 17, 2024
1 parent a1a4481 commit 2ec2a93
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 60 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions crates/client/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::{env, mem, path::PathBuf, sync::Arc, time::Duration};
use telemetry_events::{
ActionEvent, AppEvent, AssistantEvent, CallEvent, EditEvent, Event, EventRequestBody,
EventWrapper, InlineCompletionEvent, InlineCompletionRating, InlineCompletionRatingEvent,
ReplEvent, SettingEvent,
SettingEvent,
};
use util::{ResultExt, TryFutureExt};
use worktree::{UpdatedEntriesSet, WorktreeId};
Expand Down Expand Up @@ -478,21 +478,6 @@ impl Telemetry {
}
}

pub fn report_repl_event(
self: &Arc<Self>,
kernel_language: String,
kernel_status: String,
repl_session_id: String,
) {
let event = Event::Repl(ReplEvent {
kernel_language,
kernel_status,
repl_session_id,
});

self.report_event(event)
}

fn report_event(self: &Arc<Self>, event: Event) {
let mut state = self.state.lock();

Expand Down
1 change: 1 addition & 0 deletions crates/repl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ serde.workspace = true
serde_json.workspace = true
settings.workspace = true
smol.workspace = true
telemetry.workspace = true
terminal.workspace = true
terminal_view.workspace = true
theme.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions crates/repl/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ pub use crate::repl_sessions_ui::{
};
use crate::repl_store::ReplStore;
pub use crate::session::Session;
use client::telemetry::Telemetry;

pub const KERNEL_DOCS_URL: &str = "https://zed.dev/docs/repl#changing-kernels";

pub fn init(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, cx: &mut AppContext) {
pub fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) {
set_dispatcher(zed_dispatcher(cx));
JupyterSettings::register(cx);
::editor::init_settings(cx);
repl_sessions_ui::init(cx);
ReplStore::init(fs, telemetry, cx);
ReplStore::init(fs, cx);
}

fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher {
Expand Down
8 changes: 2 additions & 6 deletions crates/repl/src/repl_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub fn assign_kernelspec(
});

let fs = store.read(cx).fs().clone();
let telemetry = store.read(cx).telemetry().clone();

if let Some(session) = store.read(cx).get_session(weak_editor.entity_id()).cloned() {
// Drop previous session, start new one
Expand All @@ -44,8 +43,7 @@ pub fn assign_kernelspec(
});
}

let session = cx
.new_view(|cx| Session::new(weak_editor.clone(), fs, telemetry, kernel_specification, cx));
let session = cx.new_view(|cx| Session::new(weak_editor.clone(), fs, kernel_specification, cx));

weak_editor
.update(cx, |_editor, cx| {
Expand Down Expand Up @@ -105,15 +103,13 @@ pub fn run(editor: WeakView<Editor>, move_down: bool, cx: &mut WindowContext) ->
.ok_or_else(|| anyhow::anyhow!("No kernel found for language: {}", language.name()))?;

let fs = store.read(cx).fs().clone();
let telemetry = store.read(cx).telemetry().clone();

let session = if let Some(session) = store.read(cx).get_session(editor.entity_id()).cloned()
{
session
} else {
let weak_editor = editor.downgrade();
let session = cx
.new_view(|cx| Session::new(weak_editor, fs, telemetry, kernel_specification, cx));
let session = cx.new_view(|cx| Session::new(weak_editor, fs, kernel_specification, cx));

editor.update(cx, |_editor, cx| {
cx.notify();
Expand Down
13 changes: 3 additions & 10 deletions crates/repl/src/repl_store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use anyhow::Result;
use client::telemetry::Telemetry;
use collections::HashMap;
use command_palette_hooks::CommandPaletteFilter;
use gpui::{
Expand All @@ -28,15 +27,14 @@ pub struct ReplStore {
kernel_specifications: Vec<KernelSpecification>,
selected_kernel_for_worktree: HashMap<WorktreeId, KernelSpecification>,
kernel_specifications_for_worktree: HashMap<WorktreeId, Vec<KernelSpecification>>,
telemetry: Arc<Telemetry>,
_subscriptions: Vec<Subscription>,
}

impl ReplStore {
const NAMESPACE: &'static str = "repl";

pub(crate) fn init(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, cx: &mut AppContext) {
let store = cx.new_model(move |cx| Self::new(fs, telemetry, cx));
pub(crate) fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) {
let store = cx.new_model(move |cx| Self::new(fs, cx));

store
.update(cx, |store, cx| store.refresh_kernelspecs(cx))
Expand All @@ -49,14 +47,13 @@ impl ReplStore {
cx.global::<GlobalReplStore>().0.clone()
}

pub fn new(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, cx: &mut ModelContext<Self>) -> Self {
pub fn new(fs: Arc<dyn Fs>, cx: &mut ModelContext<Self>) -> Self {
let subscriptions = vec![cx.observe_global::<SettingsStore>(move |this, cx| {
this.set_enabled(JupyterSettings::enabled(cx), cx);
})];

let this = Self {
fs,
telemetry,
enabled: JupyterSettings::enabled(cx),
sessions: HashMap::default(),
kernel_specifications: Vec::new(),
Expand All @@ -72,10 +69,6 @@ impl ReplStore {
&self.fs
}

pub fn telemetry(&self) -> &Arc<Telemetry> {
&self.telemetry
}

pub fn is_enabled(&self) -> bool {
self.enabled
}
Expand Down
29 changes: 14 additions & 15 deletions crates/repl/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
outputs::{ExecutionStatus, ExecutionView},
KernelStatus,
};
use client::telemetry::Telemetry;
use collections::{HashMap, HashSet};
use editor::{
display_map::{
Expand Down Expand Up @@ -37,7 +36,6 @@ pub struct Session {
pub kernel: Kernel,
blocks: HashMap<String, EditorBlock>,
pub kernel_specification: KernelSpecification,
telemetry: Arc<Telemetry>,
_buffer_subscription: Subscription,
}

Expand Down Expand Up @@ -194,7 +192,6 @@ impl Session {
pub fn new(
editor: WeakView<Editor>,
fs: Arc<dyn Fs>,
telemetry: Arc<Telemetry>,
kernel_specification: KernelSpecification,
cx: &mut ViewContext<Self>,
) -> Self {
Expand All @@ -221,7 +218,6 @@ impl Session {
blocks: HashMap::default(),
kernel_specification,
_buffer_subscription: subscription,
telemetry,
};

session.start_kernel(cx);
Expand All @@ -237,10 +233,11 @@ impl Session {
.and_then(|editor| editor.read(cx).working_directory(cx))
.unwrap_or_else(temp_dir);

self.telemetry.report_repl_event(
kernel_language.into(),
KernelStatus::Starting.to_string(),
cx.entity_id().to_string(),
telemetry::event!(
"Kernel Status Changed",
kernel_language,
kernel_status = KernelStatus::Starting.to_string(),
repl_session_id = cx.entity_id().to_string(),
);

let session_view = cx.view().clone();
Expand Down Expand Up @@ -488,10 +485,11 @@ impl Session {
JupyterMessageContent::Status(status) => {
self.kernel.set_execution_state(&status.execution_state);

self.telemetry.report_repl_event(
self.kernel_specification.language().into(),
KernelStatus::from(&self.kernel).to_string(),
cx.entity_id().to_string(),
telemetry::event!(
"Kernel Status Changed",
kernel_language = self.kernel_specification.language(),
kernel_status = KernelStatus::from(&self.kernel).to_string(),
repl_session_id = cx.entity_id().to_string(),
);

cx.notify();
Expand Down Expand Up @@ -540,12 +538,13 @@ impl Session {
}

let kernel_status = KernelStatus::from(&kernel).to_string();
let kernel_language = self.kernel_specification.language().into();
let kernel_language = self.kernel_specification.language();

self.telemetry.report_repl_event(
telemetry::event!(
"Kernel Status Changed",
kernel_language,
kernel_status,
cx.entity_id().to_string(),
repl_session_id = cx.entity_id().to_string(),
);

self.kernel = kernel;
Expand Down
6 changes: 1 addition & 5 deletions crates/zed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,7 @@ fn main() {
cx,
);
assistant_tools::init(cx);
repl::init(
app_state.fs.clone(),
app_state.client.telemetry().clone(),
cx,
);
repl::init(app_state.fs.clone(), cx);
extension_host::init(
extension_host_proxy,
app_state.fs.clone(),
Expand Down
6 changes: 1 addition & 5 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3496,11 +3496,7 @@ mod tests {
);
let prompt_builder =
assistant::init(app_state.fs.clone(), app_state.client.clone(), false, cx);
repl::init(
app_state.fs.clone(),
app_state.client.telemetry().clone(),
cx,
);
repl::init(app_state.fs.clone(), cx);
repl::notebook::init(cx);
tasks_ui::init(cx);
initialize_workspace(app_state.clone(), prompt_builder, cx);
Expand Down

0 comments on commit 2ec2a93

Please sign in to comment.