Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Checkpoint: Compiling
Marshall Bowers8cac89d17cde
diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rsindex 5d33f57247d..1bbcc8c6087 100644--- a/crates/gpui3/src/app.rs+++ b/crates/gpui3/src/app.rs@@ -137,40 +137,38 @@ impl<Thread> AppContext<Thread> {AsyncContext(self.this.clone())}- // pub fn run_on_main<R>(- // &self,- // f: impl FnOnce(&mut AppContext<MainThread>) -> R + Send + 'static,- // ) -> impl Future<Output = R>- // where- // R: Send + 'static,- // {- // let this = self.this.upgrade().unwrap();- // run_on_main(self.dispatcher.clone(), move || {- // let cx = &mut *this.lock();- // let main_thread_cx: &mut AppContext<MainThread> = unsafe { std::mem::transmute(cx) };- // main_thread_cx.update(|cx| f(cx))- // })- // }-- // pub fn spawn_on_main<F, R>(- // &self,- // f: impl FnOnce(&mut AppContext<MainThread>) -> F + Send + 'static,- // ) -> impl Future<Output = R>- // where- // F: Future<Output = R> + 'static,- // R: Send + 'static,- // {- // let this = self.this.upgrade().unwrap();- // spawn_on_main(self.dispatcher.clone(), move || {- // let cx = &mut *this.lock();- // let platform = cx.platform.borrow_on_main_thread().clone();- // // todo!()- // // cx.update(|cx| f(&mut MainThreadContext::mutable(cx, platform.as_ref())))-- // future::ready(())- // })- // // self.platform.read(move |platform| {- // }+ pub fn run_on_main<R>(+ &self,+ f: impl FnOnce(&mut AppContext<MainThread>) -> R + Send + 'static,+ ) -> impl Future<Output = R>+ where+ R: Send + 'static,+ {+ let this = self.this.upgrade().unwrap();+ run_on_main(self.dispatcher.clone(), move || {+ let cx = &mut *this.lock();+ let main_thread_cx =+ unsafe { std::mem::transmute::<&mut AppContext, &mut AppContext<MainThread>>(cx) };+ main_thread_cx.update(|cx| f(cx))+ })+ }++ pub fn spawn_on_main<F, R>(+ &self,+ f: impl FnOnce(&mut AppContext<MainThread>) -> F + Send + 'static,+ ) -> impl Future<Output = R>+ where+ F: Future<Output = R> + 'static,+ R: Send + 'static,+ {+ let this = self.this.upgrade().unwrap();+ spawn_on_main(self.dispatcher.clone(), move || {+ let cx = &mut *this.lock();+ let main_thread_cx =+ unsafe { std::mem::transmute::<&mut AppContext, &mut AppContext<MainThread>>(cx) };+ main_thread_cx.update(|cx| f(cx))+ })+ }pub fn text_style(&self) -> TextStyle {let mut style = TextStyle::default();@@ -319,7 +317,7 @@ impl Context for AppContext {}impl AppContext<MainThread> {- fn platform(&self) -> &dyn Platform {+ pub(crate) fn platform(&self) -> &dyn Platform {self.platform.borrow_on_main_thread()}@@ -334,7 +332,7 @@ impl AppContext<MainThread> {) -> WindowHandle<S> {let id = self.windows.insert(None);let handle = WindowHandle::new(id);- let mut window = Window::new(handle.into(), options, self.platform(), self);+ let mut window = Window::new(handle.into(), options, self);let root_view = build_root_view(&mut WindowContext::mutable(self, &mut window));window.root_view.replace(root_view.into_any());self.windows.get_mut(id).unwrap().replace(window);diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rsindex 346b5cb25be..fda69ba6505 100644--- a/crates/gpui3/src/window.rs+++ b/crates/gpui3/src/window.rs@@ -26,10 +26,9 @@ impl Window {pub fn new(handle: AnyWindowHandle,options: WindowOptions,- platform: &dyn Platform,cx: &mut AppContext<MainThread>,) -> Self {- let platform_window = platform.open_window(handle, options);+ let platform_window = cx.platform().open_window(handle, options);let mouse_position = platform_window.mouse_position();let content_size = platform_window.content_size();let scale_factor = platform_window.scale_factor();@@ -46,7 +45,8 @@ impl Window {}}));- let platform_window = MainThreadOnly::new(Arc::new(platform_window), platform.dispatcher());+ let platform_window =+ MainThreadOnly::new(Arc::new(platform_window), cx.platform().dispatcher());Window {handle,diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rsindex bc927b78fa0..a9fbc050b7f 100644--- a/crates/storybook2/src/storybook2.rs+++ b/crates/storybook2/src/storybook2.rs@@ -17,7 +17,9 @@ fn main() {SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");gpui3::App::production().run(|cx| {- let window = cx.open_window(Default::default(), |cx| workspace(cx));+ cx.run_on_main(|cx| {+ let window = cx.open_window(Default::default(), |cx| workspace(cx));+ });});}