repl.rs

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