Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

WIP

Antonio Scandurraebc80597d59b
diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs
index 592a6076def..3b1a66326c5 100644
--- a/crates/gpui3/src/app.rs
+++ b/crates/gpui3/src/app.rs
@@ -225,6 +225,18 @@ impl AppContext {
})
}
+ pub fn spawn<Fut, R>(&self, f: impl FnOnce(&mut AppContext) -> Fut + Send + 'static) -> Task<R>
+ where
+ Fut: Future<Output = R> + Send + 'static,
+ R: Send + 'static,
+ {
+ let this = self.this.upgrade().unwrap();
+ self.executor.spawn(async move {
+ let future = f(&mut this.lock());
+ future.await
+ })
+ }
+
pub fn text_system(&self) -> &Arc<TextSystem> {
&self.text_system
}
diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs
index 3782dfe97a5..3257f520cda 100644
--- a/crates/gpui3/src/window.rs
+++ b/crates/gpui3/src/window.rs
@@ -1,14 +1,14 @@
use crate::{
- image_cache::RenderImageParams, px, AnyView, AppContext, AvailableSpace, BorrowAppContext,
- Bounds, Context, Corners, DevicePixels, Effect, Element, EntityId, FontId, GlyphId, Handle,
- Hsla, ImageData, IsZero, LayerId, LayoutId, MainThread, MainThreadOnly, MonochromeSprite,
- Pixels, PlatformAtlas, PlatformWindow, Point, PolychromeSprite, Reference, RenderGlyphParams,
- RenderSvgParams, ScaledPixels, Scene, SharedString, Size, Style, TaffyLayoutEngine, Task,
- WeakHandle, WindowOptions, SUBPIXEL_VARIANTS,
+ image_cache::RenderImageParams, px, AnyView, AppContext, AsyncContext, AvailableSpace,
+ BorrowAppContext, Bounds, Context, Corners, DevicePixels, Effect, Element, EntityId, FontId,
+ GlyphId, Handle, Hsla, ImageData, IsZero, LayerId, LayoutId, MainThread, MainThreadOnly,
+ MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, PolychromeSprite, Reference,
+ RenderGlyphParams, RenderSvgParams, ScaledPixels, Scene, SharedString, Size, Style,
+ TaffyLayoutEngine, Task, WeakHandle, WindowOptions, SUBPIXEL_VARIANTS,
};
use anyhow::Result;
use smallvec::SmallVec;
-use std::{any::TypeId, borrow::Cow, marker::PhantomData, mem, sync::Arc};
+use std::{any::TypeId, borrow::Cow, future::Future, marker::PhantomData, mem, sync::Arc};
use util::ResultExt;
pub struct AnyWindow {}
@@ -601,6 +601,20 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
}
}
+ pub fn spawn<Fut, R>(
+ &mut self,
+ f: impl FnOnce(&mut S, &mut ViewContext<'_, '_, S>) -> Fut + Send + 'static,
+ ) -> Task<Result<R>>
+ where
+ Fut: Future<Output = R> + Send + 'static,
+ {
+ let handle = self.handle();
+ todo!()
+ // self.window_cx.spawn(|cx| {
+ // f
+ // })
+ }
+
pub(crate) fn erase_state<R>(&mut self, f: impl FnOnce(&mut ViewContext<()>) -> R) -> R {
let entity_id = self.unit_entity.id;
let mut cx = ViewContext::mutable(