repl.rs

 1pub mod components;
 2mod jupyter_settings;
 3pub mod kernels;
 4pub mod notebook;
 5mod outputs;
 6mod repl_editor;
 7mod repl_sessions_ui;
 8mod repl_settings;
 9mod repl_store;
10mod session;
11
12use std::{sync::Arc, time::Duration};
13
14use async_dispatcher::{Dispatcher, Runnable, set_dispatcher};
15use gpui::{App, PlatformDispatcher};
16use project::Fs;
17pub use runtimelib::ExecutionState;
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};
25pub use crate::repl_settings::ReplSettings;
26use crate::repl_store::ReplStore;
27pub use crate::session::Session;
28
29pub const KERNEL_DOCS_URL: &str = "https://zed.dev/docs/repl#changing-kernels";
30
31pub fn init(fs: Arc<dyn Fs>, cx: &mut App) {
32    set_dispatcher(zed_dispatcher(cx));
33    repl_sessions_ui::init(cx);
34    ReplStore::init(fs, cx);
35}
36
37fn zed_dispatcher(cx: &mut App) -> impl Dispatcher {
38    struct ZedDispatcher {
39        dispatcher: Arc<dyn PlatformDispatcher>,
40    }
41
42    // PlatformDispatcher is _super_ close to the same interface we put in
43    // async-dispatcher, except for the task label in dispatch. Later we should
44    // just make that consistent so we have this dispatcher ready to go for
45    // other crates in Zed.
46    impl Dispatcher for ZedDispatcher {
47        fn dispatch(&self, runnable: Runnable) {
48            self.dispatcher.dispatch(runnable, None)
49        }
50
51        fn dispatch_after(&self, duration: Duration, runnable: Runnable) {
52            self.dispatcher.dispatch_after(duration, runnable);
53        }
54    }
55
56    ZedDispatcher {
57        dispatcher: cx.background_executor().dispatcher.clone(),
58    }
59}