Add repl events (#15259)
Release Notes: - N/A --------- Co-authored-by: Kyle Kelley <rgbkrk@gmail.com>
This commit is contained in:
co-authored by
Kyle Kelley
parent
745d2e4d3b
commit
856d9632e4
@@ -24,13 +24,14 @@ pub use crate::repl_sessions_ui::{
|
||||
};
|
||||
use crate::repl_store::ReplStore;
|
||||
pub use crate::session::Session;
|
||||
use client::telemetry::Telemetry;
|
||||
|
||||
pub fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) {
|
||||
pub fn init(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, cx: &mut AppContext) {
|
||||
set_dispatcher(zed_dispatcher(cx));
|
||||
JupyterSettings::register(cx);
|
||||
::editor::init_settings(cx);
|
||||
repl_sessions_ui::init(cx);
|
||||
ReplStore::init(fs, cx);
|
||||
ReplStore::init(fs, telemetry, cx);
|
||||
}
|
||||
|
||||
fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher {
|
||||
|
||||
@@ -42,12 +42,15 @@ pub fn run(editor: WeakView<Editor>, cx: &mut WindowContext) -> Result<()> {
|
||||
})?;
|
||||
|
||||
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, kernel_specification, cx));
|
||||
let session = cx
|
||||
.new_view(|cx| Session::new(weak_editor, fs, telemetry, kernel_specification, cx));
|
||||
|
||||
editor.update(cx, |_editor, cx| {
|
||||
cx.notify();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use client::telemetry::Telemetry;
|
||||
use collections::HashMap;
|
||||
use command_palette_hooks::CommandPaletteFilter;
|
||||
use gpui::{
|
||||
@@ -22,14 +23,15 @@ pub struct ReplStore {
|
||||
enabled: bool,
|
||||
sessions: HashMap<EntityId, View<Session>>,
|
||||
kernel_specifications: Vec<KernelSpecification>,
|
||||
telemetry: Arc<Telemetry>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl ReplStore {
|
||||
const NAMESPACE: &'static str = "repl";
|
||||
|
||||
pub(crate) fn init(fs: Arc<dyn Fs>, cx: &mut AppContext) {
|
||||
let store = cx.new_model(move |cx| Self::new(fs, cx));
|
||||
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));
|
||||
|
||||
store
|
||||
.update(cx, |store, cx| store.refresh_kernelspecs(cx))
|
||||
@@ -42,13 +44,14 @@ impl ReplStore {
|
||||
cx.global::<GlobalReplStore>().0.clone()
|
||||
}
|
||||
|
||||
pub fn new(fs: Arc<dyn Fs>, cx: &mut ModelContext<Self>) -> Self {
|
||||
pub fn new(fs: Arc<dyn Fs>, telemetry: Arc<Telemetry>, 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(),
|
||||
@@ -62,6 +65,10 @@ impl ReplStore {
|
||||
&self.fs
|
||||
}
|
||||
|
||||
pub fn telemetry(&self) -> &Arc<Telemetry> {
|
||||
&self.telemetry
|
||||
}
|
||||
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
+51
-13
@@ -1,8 +1,10 @@
|
||||
use crate::components::KernelListItem;
|
||||
use crate::KernelStatus;
|
||||
use crate::{
|
||||
kernels::{Kernel, KernelSpecification, RunningKernel},
|
||||
outputs::{ExecutionStatus, ExecutionView, LineHeight as _},
|
||||
};
|
||||
use client::telemetry::Telemetry;
|
||||
use collections::{HashMap, HashSet};
|
||||
use editor::{
|
||||
display_map::{
|
||||
@@ -34,6 +36,7 @@ pub struct Session {
|
||||
blocks: HashMap<String, EditorBlock>,
|
||||
messaging_task: Task<()>,
|
||||
pub kernel_specification: KernelSpecification,
|
||||
telemetry: Arc<Telemetry>,
|
||||
_buffer_subscription: Subscription,
|
||||
}
|
||||
|
||||
@@ -205,9 +208,18 @@ impl Session {
|
||||
pub fn new(
|
||||
editor: WeakView<Editor>,
|
||||
fs: Arc<dyn Fs>,
|
||||
telemetry: Arc<Telemetry>,
|
||||
kernel_specification: KernelSpecification,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let kernel_language = kernel_specification.kernelspec.language.clone();
|
||||
|
||||
telemetry.report_repl_event(
|
||||
kernel_language.clone(),
|
||||
KernelStatus::Starting.to_string(),
|
||||
cx.entity_id().to_string(),
|
||||
);
|
||||
|
||||
let entity_id = editor.entity_id();
|
||||
let working_directory = editor
|
||||
.upgrade()
|
||||
@@ -227,11 +239,11 @@ impl Session {
|
||||
|
||||
match kernel {
|
||||
Ok((mut kernel, mut messages_rx)) => {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update(&mut cx, |session, cx| {
|
||||
// At this point we can create a new kind of kernel that has the process and our long running background tasks
|
||||
|
||||
let status = kernel.process.status();
|
||||
this.kernel = Kernel::RunningKernel(kernel);
|
||||
session.kernel(Kernel::RunningKernel(kernel), cx);
|
||||
|
||||
cx.spawn(|session, mut cx| async move {
|
||||
let error_message = match status.await {
|
||||
@@ -252,8 +264,10 @@ impl Session {
|
||||
|
||||
session
|
||||
.update(&mut cx, |session, cx| {
|
||||
session.kernel =
|
||||
Kernel::ErroredLaunch(error_message.clone());
|
||||
session.kernel(
|
||||
Kernel::ErroredLaunch(error_message.clone()),
|
||||
cx,
|
||||
);
|
||||
|
||||
session.blocks.values().for_each(|block| {
|
||||
block.execution_view.update(
|
||||
@@ -282,7 +296,7 @@ impl Session {
|
||||
})
|
||||
.detach();
|
||||
|
||||
this.messaging_task = cx.spawn(|session, mut cx| async move {
|
||||
session.messaging_task = cx.spawn(|session, mut cx| async move {
|
||||
while let Some(message) = messages_rx.next().await {
|
||||
session
|
||||
.update(&mut cx, |session, cx| {
|
||||
@@ -295,8 +309,8 @@ impl Session {
|
||||
.ok();
|
||||
}
|
||||
Err(err) => {
|
||||
this.update(&mut cx, |this, _cx| {
|
||||
this.kernel = Kernel::ErroredLaunch(err.to_string());
|
||||
this.update(&mut cx, |session, cx| {
|
||||
session.kernel(Kernel::ErroredLaunch(err.to_string()), cx);
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
@@ -319,6 +333,7 @@ impl Session {
|
||||
blocks: HashMap::default(),
|
||||
kernel_specification,
|
||||
_buffer_subscription: subscription,
|
||||
telemetry,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -474,8 +489,8 @@ impl Session {
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
task.await;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.send(message, cx).ok();
|
||||
this.update(&mut cx, |session, cx| {
|
||||
session.send(message, cx).ok();
|
||||
})
|
||||
.ok();
|
||||
})
|
||||
@@ -501,6 +516,13 @@ impl Session {
|
||||
match &message.content {
|
||||
JupyterMessageContent::Status(status) => {
|
||||
self.kernel.set_execution_state(&status.execution_state);
|
||||
|
||||
self.telemetry.report_repl_event(
|
||||
self.kernel_specification.kernelspec.language.clone(),
|
||||
KernelStatus::from(&self.kernel).to_string(),
|
||||
cx.entity_id().to_string(),
|
||||
);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
JupyterMessageContent::KernelInfoReply(reply) => {
|
||||
@@ -528,6 +550,23 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kernel(&mut self, kernel: Kernel, cx: &mut ViewContext<Self>) {
|
||||
if let Kernel::Shutdown = kernel {
|
||||
cx.emit(SessionEvent::Shutdown(self.editor.clone()));
|
||||
}
|
||||
|
||||
let kernel_status = KernelStatus::from(&kernel).to_string();
|
||||
let kernel_language = self.kernel_specification.kernelspec.language.clone();
|
||||
|
||||
self.telemetry.report_repl_event(
|
||||
kernel_language,
|
||||
kernel_status,
|
||||
cx.entity_id().to_string(),
|
||||
);
|
||||
|
||||
self.kernel = kernel;
|
||||
}
|
||||
|
||||
pub fn shutdown(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let kernel = std::mem::replace(&mut self.kernel, Kernel::ShuttingDown);
|
||||
|
||||
@@ -544,10 +583,9 @@ impl Session {
|
||||
|
||||
kernel.process.kill().ok();
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
cx.emit(SessionEvent::Shutdown(this.editor.clone()));
|
||||
this.clear_outputs(cx);
|
||||
this.kernel = Kernel::Shutdown;
|
||||
this.update(&mut cx, |session, cx| {
|
||||
session.clear_outputs(cx);
|
||||
session.kernel(Kernel::Shutdown, cx);
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
|
||||
Reference in New Issue
Block a user