repl.rs

 1use async_dispatcher::{set_dispatcher, Dispatcher, Runnable};
 2use gpui::{AppContext, PlatformDispatcher};
 3use settings::Settings as _;
 4use std::{sync::Arc, time::Duration};
 5
 6mod jupyter_settings;
 7mod kernels;
 8mod outputs;
 9mod runtime_panel;
10mod session;
11mod stdio;
12
13pub use jupyter_settings::JupyterSettings;
14pub use runtime_panel::RuntimePanel;
15
16fn zed_dispatcher(cx: &mut AppContext) -> impl Dispatcher {
17    struct ZedDispatcher {
18        dispatcher: Arc<dyn PlatformDispatcher>,
19    }
20
21    // PlatformDispatcher is _super_ close to the same interface we put in
22    // async-dispatcher, except for the task label in dispatch. Later we should
23    // just make that consistent so we have this dispatcher ready to go for
24    // other crates in Zed.
25    impl Dispatcher for ZedDispatcher {
26        fn dispatch(&self, runnable: Runnable) {
27            self.dispatcher.dispatch(runnable, None)
28        }
29
30        fn dispatch_after(&self, duration: Duration, runnable: Runnable) {
31            self.dispatcher.dispatch_after(duration, runnable);
32        }
33    }
34
35    ZedDispatcher {
36        dispatcher: cx.background_executor().dispatcher.clone(),
37    }
38}
39
40pub fn init(cx: &mut AppContext) {
41    set_dispatcher(zed_dispatcher(cx));
42    JupyterSettings::register(cx);
43    runtime_panel::init(cx)
44}