Add repl events (#15259)
Release Notes: - N/A --------- Co-authored-by: Kyle Kelley <rgbkrk@gmail.com>
This commit is contained in:
parent
745d2e4d3b
commit
856d9632e4
11 changed files with 190 additions and 37 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue