repl.rs

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