1pub mod components;
2mod jupyter_settings;
3pub mod kernels;
4pub mod notebook;
5mod outputs;
6mod repl_editor;
7mod repl_sessions_ui;
8mod repl_store;
9mod session;
10
11use std::{sync::Arc, time::Duration};
12
13use async_dispatcher::{Dispatcher, Runnable, set_dispatcher};
14use gpui::{App, Scheduler};
15use project::Fs;
16pub use runtimelib::ExecutionState;
17use settings::Settings as _;
18
19pub use crate::jupyter_settings::JupyterSettings;
20pub use crate::kernels::{Kernel, KernelSpecification, KernelStatus};
21pub use crate::repl_editor::*;
22pub use crate::repl_sessions_ui::{
23 ClearOutputs, Interrupt, ReplSessionsPage, Restart, Run, Sessions, Shutdown,
24};
25use crate::repl_store::ReplStore;
26pub use crate::session::Session;
27
28pub const KERNEL_DOCS_URL: &str = "https://zed.dev/docs/repl#changing-kernels";
29
30pub fn init(fs: Arc<dyn Fs>, cx: &mut App) {
31 set_dispatcher(zed_dispatcher(cx));
32 JupyterSettings::register(cx);
33 ::editor::init_settings(cx);
34 repl_sessions_ui::init(cx);
35 ReplStore::init(fs, cx);
36}
37
38fn zed_dispatcher(cx: &mut App) -> impl Dispatcher {
39 struct ZedDispatcher {
40 scheduler: Arc<dyn Scheduler>,
41 }
42
43 // PlatformDispatcher is _super_ close to the same interface we put in
44 // async-dispatcher, except for the task label in dispatch. Later we should
45 // just make that consistent so we have this dispatcher ready to go for
46 // other crates in Zed.
47 impl Dispatcher for ZedDispatcher {
48 fn dispatch(&self, runnable: Runnable) {
49 self.scheduler.schedule_background(runnable)
50 }
51
52 fn dispatch_after(&self, duration: Duration, runnable: Runnable) {
53 let timer = self.scheduler.timer(duration);
54 let future = async move {
55 timer.await;
56 runnable.run();
57 };
58 let (runnable, task) = async_task::spawn(future, {
59 let scheduler = self.scheduler.clone();
60 move |runnable| scheduler.schedule_background(runnable)
61 });
62 runnable.schedule();
63 task.detach();
64 }
65 }
66
67 ZedDispatcher {
68 scheduler: cx.background_executor().scheduler().clone(),
69 }
70}