diff --git a/Cargo.lock b/Cargo.lock index 39e6222c6c..8008e9917c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5953,61 +5953,6 @@ dependencies = [ "util", ] -[[package]] -name = "project2" -version = "0.1.0" -dependencies = [ - "aho-corasick", - "anyhow", - "async-trait", - "backtrace", - "client2", - "clock", - "collections", - "copilot2", - "ctor", - "db2", - "env_logger 0.9.3", - "fs", - "fsevent", - "futures 0.3.28", - "fuzzy2", - "git", - "git2", - "globset", - "gpui2", - "ignore", - "itertools 0.10.5", - "language2", - "lazy_static", - "log", - "lsp2", - "node_runtime", - "parking_lot 0.11.2", - "postage", - "prettier", - "pretty_assertions", - "rand 0.8.5", - "regex", - "rpc", - "schemars", - "serde", - "serde_derive", - "serde_json", - "settings2", - "sha2 0.10.7", - "similar", - "smol", - "sum_tree", - "tempdir", - "terminal", - "text", - "thiserror", - "toml 0.5.11", - "unindent", - "util", -] - [[package]] name = "project_panel" version = "0.1.0" @@ -8374,35 +8319,6 @@ dependencies = [ "util", ] -[[package]] -name = "terminal2" -version = "0.1.0" -dependencies = [ - "alacritty_terminal", - "anyhow", - "db2", - "dirs 4.0.0", - "futures 0.3.28", - "gpui2", - "itertools 0.10.5", - "lazy_static", - "libc", - "mio-extras", - "ordered-float 2.10.0", - "procinfo", - "rand 0.8.5", - "schemars", - "serde", - "serde_derive", - "settings2", - "shellexpand", - "smallvec", - "smol", - "theme2", - "thiserror", - "util", -] - [[package]] name = "terminal_view" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 400d471f54..535e6ff8a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ members = [ "crates/plugin_runtime", "crates/prettier", "crates/project", - "crates/project2", + # "crates/project2", "crates/project_panel", "crates/project_symbols", "crates/recent_projects", @@ -78,7 +78,7 @@ members = [ "crates/storybook2", "crates/sum_tree", "crates/terminal", - "crates/terminal2", + #"crates/terminal2", "crates/text", "crates/theme", "crates/theme2", diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 9649f4745f..5bade4e717 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -178,7 +178,7 @@ pub struct AppContext { pub(crate) svg_renderer: SvgRenderer, pub(crate) image_cache: ImageCache, pub(crate) text_style_stack: Vec, - pub(crate) globals_by_type: HashMap>, + pub(crate) globals_by_type: HashMap, pub(crate) unit_entity: Handle<()>, pub(crate) entities: EntityMap, pub(crate) windows: SlotMap>, @@ -574,7 +574,7 @@ impl AppContext { ) } - pub(crate) fn lease_global(&mut self) -> Box { + pub(crate) fn lease_global(&mut self) -> Box { self.globals_by_type .remove(&TypeId::of::()) .ok_or_else(|| anyhow!("no global registered of type {}", type_name::())) @@ -583,7 +583,7 @@ impl AppContext { .unwrap() } - pub(crate) fn restore_global(&mut self, global: Box) { + pub(crate) fn restore_global(&mut self, global: Box) { let global_type = TypeId::of::(); self.push_effect(Effect::NotifyGlobalObservers { global_type }); self.globals_by_type.insert(global_type, global); @@ -639,7 +639,7 @@ impl AppContext { } impl Context for AppContext { - type EntityContext<'a, 'w, T: Send + Sync + 'static> = ModelContext<'a, T>; + type EntityContext<'a, 'w, T> = ModelContext<'a, T>; type Result = T; fn entity( @@ -653,7 +653,7 @@ impl Context for AppContext { }) } - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R, @@ -723,11 +723,11 @@ impl MainThread { self.platform().open_url(url); } - pub fn open_window( + pub fn open_window( &mut self, options: crate::WindowOptions, - build_root_view: impl FnOnce(&mut WindowContext) -> View + Send + 'static, - ) -> WindowHandle { + build_root_view: impl FnOnce(&mut WindowContext) -> View + Send + 'static, + ) -> WindowHandle { self.update(|cx| { let id = cx.windows.insert(None); let handle = WindowHandle::new(id); @@ -739,7 +739,7 @@ impl MainThread { }) } - pub fn update_global( + pub fn update_global( &mut self, update: impl FnOnce(&mut G, &mut MainThread) -> R, ) -> R { @@ -756,7 +756,7 @@ pub(crate) enum Effect { }, Emit { emitter: EntityId, - event: Box, + event: AnyBox, }, FocusChanged { window_id: WindowId, diff --git a/crates/gpui2/src/app/async_context.rs b/crates/gpui2/src/app/async_context.rs index 0fea00ed1f..779e88e786 100644 --- a/crates/gpui2/src/app/async_context.rs +++ b/crates/gpui2/src/app/async_context.rs @@ -14,7 +14,7 @@ pub struct AsyncAppContext { } impl Context for AsyncAppContext { - type EntityContext<'a, 'w, T: 'static + Send + Sync> = ModelContext<'a, T>; + type EntityContext<'a, 'w, T> = ModelContext<'a, T>; type Result = Result; fn entity( @@ -29,7 +29,7 @@ impl Context for AsyncAppContext { Ok(lock.entity(build_entity)) } - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R, @@ -213,18 +213,18 @@ impl AsyncWindowContext { } impl Context for AsyncWindowContext { - type EntityContext<'a, 'w, T: 'static + Send + Sync> = ViewContext<'a, 'w, T>; + type EntityContext<'a, 'w, T> = ViewContext<'a, 'w, T>; type Result = Result; - fn entity( + fn entity( &mut self, - build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, R>) -> R, - ) -> Result> { + build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, + ) -> Result> { self.app .update_window(self.window, |cx| cx.entity(build_entity)) } - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R, diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index a8ef9bb87b..ebc6644c16 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -30,7 +30,7 @@ impl Display for EntityId { } pub(crate) struct EntityMap { - entities: SecondaryMap>, + entities: SecondaryMap>, ref_counts: Arc>, } @@ -51,24 +51,20 @@ impl EntityMap { } /// Reserve a slot for an entity, which you can subsequently use with `insert`. - pub fn reserve(&self) -> Slot { + pub fn reserve(&self) -> Slot { let id = self.ref_counts.write().counts.insert(1.into()); Slot(Handle::new(id, Arc::downgrade(&self.ref_counts))) } /// Insert an entity into a slot obtained by calling `reserve`. - pub fn insert( - &mut self, - slot: Slot, - entity: T, - ) -> Handle { + pub fn insert(&mut self, slot: Slot, entity: T) -> Handle { let handle = slot.0; self.entities.insert(handle.entity_id, Box::new(entity)); handle } /// Move an entity to the stack. - pub fn lease<'a, T: 'static + Send + Sync>(&mut self, handle: &'a Handle) -> Lease<'a, T> { + pub fn lease<'a, T>(&mut self, handle: &'a Handle) -> Lease<'a, T> { let entity = Some( self.entities .remove(handle.entity_id) @@ -80,16 +76,16 @@ impl EntityMap { } /// Return an entity after moving it to the stack. - pub fn end_lease(&mut self, mut lease: Lease) { + pub fn end_lease(&mut self, mut lease: Lease) { self.entities .insert(lease.handle.entity_id, lease.entity.take().unwrap()); } - pub fn read(&self, handle: &Handle) -> &T { + pub fn read(&self, handle: &Handle) -> &T { self.entities[handle.entity_id].downcast_ref().unwrap() } - pub fn weak_handle(&self, id: EntityId) -> WeakHandle { + pub fn weak_handle(&self, id: EntityId) -> WeakHandle { WeakHandle { any_handle: AnyWeakHandle { entity_id: id, @@ -100,7 +96,7 @@ impl EntityMap { } } - pub fn take_dropped(&mut self) -> Vec<(EntityId, Box)> { + pub fn take_dropped(&mut self) -> Vec<(EntityId, Box)> { let dropped_entity_ids = mem::take(&mut self.ref_counts.write().dropped_entity_ids); dropped_entity_ids .into_iter() @@ -109,15 +105,12 @@ impl EntityMap { } } -pub struct Lease<'a, T: Send + Sync> { +pub struct Lease<'a, T> { entity: Option>, pub handle: &'a Handle, } -impl<'a, T> core::ops::Deref for Lease<'a, T> -where - T: Send + Sync, -{ +impl<'a, T> core::ops::Deref for Lease<'a, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -125,19 +118,13 @@ where } } -impl<'a, T> core::ops::DerefMut for Lease<'a, T> -where - T: Send + Sync, -{ +impl<'a, T> core::ops::DerefMut for Lease<'a, T> { fn deref_mut(&mut self) -> &mut Self::Target { self.entity.as_mut().unwrap() } } -impl<'a, T> Drop for Lease<'a, T> -where - T: Send + Sync, -{ +impl<'a, T> Drop for Lease<'a, T> { fn drop(&mut self) { if self.entity.is_some() { // We don't panic here, because other panics can cause us to drop the lease without ending it cleanly. @@ -147,7 +134,7 @@ where } #[derive(Deref, DerefMut)] -pub struct Slot(Handle); +pub struct Slot(Handle); pub struct AnyHandle { pub(crate) entity_id: EntityId, @@ -178,7 +165,7 @@ impl AnyHandle { pub fn downcast(&self) -> Option> where - T: 'static + Send + Sync, + T: Any, { if TypeId::of::() == self.entity_type { Some(Handle { @@ -231,10 +218,7 @@ impl Drop for AnyHandle { } } -impl From> for AnyHandle -where - T: 'static + Send + Sync, -{ +impl From> for AnyHandle { fn from(handle: Handle) -> Self { handle.any_handle } @@ -255,14 +239,14 @@ impl PartialEq for AnyHandle { impl Eq for AnyHandle {} #[derive(Deref, DerefMut)] -pub struct Handle { +pub struct Handle { #[deref] #[deref_mut] any_handle: AnyHandle, entity_type: PhantomData, } -impl Handle { +impl Handle { fn new(id: EntityId, entity_map: Weak>) -> Self { Self { any_handle: AnyHandle::new(id, TypeId::of::(), entity_map), @@ -295,7 +279,7 @@ impl Handle { } } -impl Clone for Handle { +impl Clone for Handle { fn clone(&self) -> Self { Self { any_handle: self.any_handle.clone(), @@ -304,7 +288,7 @@ impl Clone for Handle { } } -impl std::fmt::Debug for Handle { +impl std::fmt::Debug for Handle { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -315,19 +299,19 @@ impl std::fmt::Debug for Handle { } } -impl Hash for Handle { +impl Hash for Handle { fn hash(&self, state: &mut H) { self.any_handle.hash(state); } } -impl PartialEq for Handle { +impl PartialEq for Handle { fn eq(&self, other: &Self) -> bool { self.any_handle == other.any_handle } } -impl Eq for Handle {} +impl Eq for Handle {} #[derive(Clone)] pub struct AnyWeakHandle { @@ -436,16 +420,16 @@ impl WeakHandle { } } -impl Hash for WeakHandle { +impl Hash for WeakHandle { fn hash(&self, state: &mut H) { self.any_handle.hash(state); } } -impl PartialEq for WeakHandle { +impl PartialEq for WeakHandle { fn eq(&self, other: &Self) -> bool { self.any_handle == other.any_handle } } -impl Eq for WeakHandle {} +impl Eq for WeakHandle {} diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs index 0b84cbe93e..5a1a6b71ac 100644 --- a/crates/gpui2/src/app/model_context.rs +++ b/crates/gpui2/src/app/model_context.rs @@ -15,7 +15,7 @@ pub struct ModelContext<'a, T> { entity_id: EntityId, } -impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> { +impl<'a, T> ModelContext<'a, T> { pub(crate) fn mutable(app: &'a mut AppContext, entity_id: EntityId) -> Self { Self { app: Reference::Mutable(app), @@ -38,7 +38,7 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> { self.app.entities.weak_handle(self.entity_id) } - pub fn observe( + pub fn observe( &mut self, handle: &Handle, on_notify: impl Fn(&mut T, Handle, &mut ModelContext<'_, T>) + Send + Sync + 'static, @@ -58,7 +58,7 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> { ) } - pub fn subscribe( + pub fn subscribe( &mut self, handle: &Handle, on_event: impl Fn(&mut T, Handle, &E::Event, &mut ModelContext<'_, T>) @@ -95,7 +95,7 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> { ) } - pub fn observe_release( + pub fn observe_release( &mut self, handle: &Handle, on_release: impl Fn(&mut T, &mut E, &mut ModelContext<'_, T>) + Send + Sync + 'static, @@ -176,7 +176,7 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> { } } -impl<'a, T: EventEmitter + Send + Sync + 'static> ModelContext<'a, T> { +impl<'a, T: EventEmitter> ModelContext<'a, T> { pub fn emit(&mut self, event: T::Event) { self.app.pending_effects.push_back(Effect::Emit { emitter: self.entity_id, @@ -186,7 +186,7 @@ impl<'a, T: EventEmitter + Send + Sync + 'static> ModelContext<'a, T> { } impl<'a, T: 'static> Context for ModelContext<'a, T> { - type EntityContext<'b, 'c, U: Send + Sync + 'static> = ModelContext<'b, U>; + type EntityContext<'b, 'c, U> = ModelContext<'b, U>; type Result = U; fn entity( @@ -196,7 +196,7 @@ impl<'a, T: 'static> Context for ModelContext<'a, T> { self.app.entity(build_entity) } - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut U, &mut Self::EntityContext<'_, '_, U>) -> R, diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index c76ef9d953..04e6afcc87 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -4,8 +4,8 @@ pub(crate) use smallvec::SmallVec; use std::mem; pub trait Element: IntoAnyElement { - type ViewState: 'static + Send + Sync; - type ElementState: 'static + Send + Sync; + type ViewState; + type ElementState; fn id(&self) -> Option; @@ -59,7 +59,7 @@ pub trait ParentElement: Element { } } -trait ElementObject: 'static + Send + Sync { +trait ElementObject { fn initialize(&mut self, view_state: &mut V, cx: &mut ViewContext); fn layout(&mut self, view_state: &mut V, cx: &mut ViewContext) -> LayoutId; fn paint(&mut self, view_state: &mut V, cx: &mut ViewContext); @@ -98,7 +98,7 @@ impl RenderedElement { impl ElementObject for RenderedElement where - E: 'static + Element + Send + Sync, + E: Element, { fn initialize(&mut self, view_state: &mut E::ViewState, cx: &mut ViewContext) { let frame_state = if let Some(id) = self.element.id() { @@ -173,8 +173,8 @@ where pub struct AnyElement(Box>); -impl AnyElement { - pub fn new>(element: E) -> Self { +impl AnyElement { + pub fn new>(element: E) -> Self { AnyElement(Box::new(RenderedElement::new(element))) } diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index 72015a0443..8d5717aa7c 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -20,7 +20,10 @@ pub struct Div< base_style: StyleRefinement, } -pub fn div() -> Div, FocusDisabled> { +pub fn div() -> Div, FocusDisabled> +// where + // V: 'static + Send + Sync, +{ Div { interaction: StatelessInteraction::default(), focus: FocusDisabled, @@ -33,7 +36,6 @@ pub fn div() -> Div, FocusDisabled> { impl Div, F> where F: ElementFocus, - V: 'static + Send + Sync, { pub fn id(self, id: impl Into) -> Div, F> { Div { @@ -50,7 +52,6 @@ impl Div where I: ElementInteraction, F: ElementFocus, - V: 'static + Send + Sync, { pub fn group(mut self, group: impl Into) -> Self { self.group = Some(group.into()); @@ -105,10 +106,7 @@ where } } -impl Div, FocusDisabled> -where - V: 'static + Send + Sync, -{ +impl Div, FocusDisabled> { pub fn focusable(self) -> Div, FocusEnabled> { Div { interaction: self.interaction, @@ -149,10 +147,7 @@ where } } -impl Div, FocusDisabled> -where - V: 'static + Send + Sync, -{ +impl Div, FocusDisabled> { pub fn track_focus( self, handle: &FocusHandle, @@ -170,7 +165,6 @@ where impl Focusable for Div> where I: ElementInteraction, - V: 'static + Send + Sync, { fn focus_listeners(&mut self) -> &mut FocusListeners { &mut self.focus.focus_listeners @@ -200,7 +194,6 @@ impl Element for Div where I: ElementInteraction, F: ElementFocus, - V: 'static + Send + Sync, { type ViewState = V; type ElementState = DivState; @@ -316,7 +309,6 @@ impl IntoAnyElement for Div where I: ElementInteraction, F: ElementFocus, - V: 'static + Send + Sync, { fn into_any(self) -> AnyElement { AnyElement::new(self) @@ -327,7 +319,6 @@ impl ParentElement for Div where I: ElementInteraction, F: ElementFocus, - V: 'static + Send + Sync, { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children @@ -338,7 +329,6 @@ impl Styled for Div where I: ElementInteraction, F: ElementFocus, - V: 'static + Send + Sync, { fn style(&mut self) -> &mut StyleRefinement { &mut self.base_style @@ -349,7 +339,6 @@ impl StatelessInteractive for Div where I: ElementInteraction, F: ElementFocus, - V: 'static + Send + Sync, { fn stateless_interaction(&mut self) -> &mut StatelessInteraction { self.interaction.as_stateless_mut() @@ -359,7 +348,6 @@ where impl StatefulInteractive for Div, F> where F: ElementFocus, - V: 'static + Send + Sync, { fn stateful_interaction(&mut self) -> &mut StatefulInteraction { &mut self.interaction diff --git a/crates/gpui2/src/elements/img.rs b/crates/gpui2/src/elements/img.rs index 713bc8b98d..2efbe6c8c0 100644 --- a/crates/gpui2/src/elements/img.rs +++ b/crates/gpui2/src/elements/img.rs @@ -8,7 +8,7 @@ use futures::FutureExt; use util::ResultExt; pub struct Img< - V: 'static + Send + Sync, + V, I: ElementInteraction = StatelessInteraction, F: ElementFocus = FocusDisabled, > { @@ -17,10 +17,7 @@ pub struct Img< grayscale: bool, } -pub fn img() -> Img, FocusDisabled> -where - V: 'static + Send + Sync, -{ +pub fn img() -> Img, FocusDisabled> { Img { base: div(), uri: None, @@ -30,7 +27,6 @@ where impl Img where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -47,7 +43,6 @@ where impl Img, F> where - V: 'static + Send + Sync, F: ElementFocus, { pub fn id(self, id: impl Into) -> Img, F> { @@ -61,7 +56,6 @@ where impl IntoAnyElement for Img where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -72,7 +66,6 @@ where impl Element for Img where - V: Send + Sync + 'static, I: ElementInteraction, F: ElementFocus, { @@ -141,7 +134,6 @@ where impl Styled for Img where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -152,7 +144,6 @@ where impl StatelessInteractive for Img where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -163,7 +154,6 @@ where impl StatefulInteractive for Img, F> where - V: 'static + Send + Sync, F: ElementFocus, { fn stateful_interaction(&mut self) -> &mut StatefulInteraction { @@ -173,7 +163,6 @@ where impl Focusable for Img> where - V: 'static + Send + Sync, I: ElementInteraction, { fn focus_listeners(&mut self) -> &mut FocusListeners { diff --git a/crates/gpui2/src/elements/svg.rs b/crates/gpui2/src/elements/svg.rs index fcaaa24956..b1d5403d88 100644 --- a/crates/gpui2/src/elements/svg.rs +++ b/crates/gpui2/src/elements/svg.rs @@ -7,6 +7,7 @@ use crate::{ use util::ResultExt; pub struct Svg< + V, I: ElementInteraction = StatelessInteraction, F: ElementFocus = FocusDisabled, > { @@ -14,10 +15,7 @@ pub struct Svg< path: Option, } -pub fn svg() -> Svg, FocusDisabled> -where - V: 'static + Send + Sync, -{ +pub fn svg() -> Svg, FocusDisabled> { Svg { base: div(), path: None, @@ -26,7 +24,6 @@ where impl Svg where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -38,7 +35,6 @@ where impl Svg, F> where - V: 'static + Send + Sync, F: ElementFocus, { pub fn id(self, id: impl Into) -> Svg, F> { @@ -61,7 +57,6 @@ where impl Element for Svg where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -113,7 +108,6 @@ where impl Styled for Svg where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -124,7 +118,6 @@ where impl StatelessInteractive for Svg where - V: 'static + Send + Sync, I: ElementInteraction, F: ElementFocus, { @@ -135,7 +128,6 @@ where impl StatefulInteractive for Svg, F> where - V: 'static + Send + Sync, F: ElementFocus, { fn stateful_interaction(&mut self) -> &mut StatefulInteraction { @@ -145,7 +137,6 @@ where impl Focusable for Svg> where - V: 'static + Send + Sync, I: ElementInteraction, { fn focus_listeners(&mut self) -> &mut FocusListeners { diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rs index ff1a9e2335..a8d76971a2 100644 --- a/crates/gpui2/src/elements/text.rs +++ b/crates/gpui2/src/elements/text.rs @@ -7,8 +7,8 @@ use smallvec::SmallVec; use std::{marker::PhantomData, sync::Arc}; use util::ResultExt; -impl IntoAnyElement for SharedString { - fn into_any(self) -> AnyElement { +impl IntoAnyElement for SharedString { + fn into_any(self) -> AnyElement { Text { text: self, state_type: PhantomData, @@ -17,7 +17,7 @@ impl IntoAnyElement for SharedString { } } -impl IntoAnyElement for &'static str { +impl IntoAnyElement for &'static str { fn into_any(self) -> AnyElement { Text { text: self.into(), @@ -29,7 +29,7 @@ impl IntoAnyElement for &'static str { // TODO: Figure out how to pass `String` to `child` without this. // This impl doesn't exist in the `gpui2` crate. -impl IntoAnyElement for String { +impl IntoAnyElement for String { fn into_any(self) -> AnyElement { Text { text: self.into(), @@ -44,13 +44,13 @@ pub struct Text { state_type: PhantomData, } -impl IntoAnyElement for Text { +impl IntoAnyElement for Text { fn into_any(self) -> AnyElement { AnyElement::new(self) } } -impl Element for Text { +impl Element for Text { type ViewState = V; type ElementState = Arc>>; diff --git a/crates/gpui2/src/gpui2.rs b/crates/gpui2/src/gpui2.rs index c3bbd1b2e9..e985a6d047 100644 --- a/crates/gpui2/src/gpui2.rs +++ b/crates/gpui2/src/gpui2.rs @@ -66,7 +66,7 @@ use taffy::TaffyLayoutEngine; type AnyBox = Box; pub trait Context { - type EntityContext<'a, 'w, T: 'static + Send + Sync>; + type EntityContext<'a, 'w, T>; type Result; fn entity( @@ -74,7 +74,7 @@ pub trait Context { build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Self::Result>; - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R, @@ -105,10 +105,10 @@ impl DerefMut for MainThread { } impl Context for MainThread { - type EntityContext<'a, 'w, T: 'static + Send + Sync> = MainThread>; + type EntityContext<'a, 'w, T> = MainThread>; type Result = C::Result; - fn entity( + fn entity( &mut self, build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T, ) -> Self::Result> { @@ -123,7 +123,7 @@ impl Context for MainThread { }) } - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R, diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 115f9fbe6c..a4afe397af 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -397,7 +397,10 @@ pub trait ElementInteraction { &mut self, cx: &mut ViewContext, f: impl FnOnce(&mut ViewContext) -> R, - ) -> R { + ) -> R + where + V: 'static + Send + Sync, + { if let Some(stateful) = self.as_stateful_mut() { cx.with_element_id(stateful.id.clone(), |global_id, cx| { stateful.key_listeners.push(( @@ -433,7 +436,9 @@ pub trait ElementInteraction { bounds: Bounds, element_state: &InteractiveElementState, cx: &mut ViewContext, - ) { + ) where + V: 'static + Send + Sync, + { let mouse_position = cx.mouse_position(); let stateless = self.as_stateless(); if let Some(group_hover) = stateless.group_hover_style.as_ref() { @@ -487,7 +492,9 @@ pub trait ElementInteraction { overflow: Point, element_state: &mut InteractiveElementState, cx: &mut ViewContext, - ) { + ) where + V: 'static + Send + Sync, + { let stateless = self.as_stateless(); for listener in stateless.mouse_down_listeners.iter().cloned() { cx.on_mouse_event(move |state, event: &MouseDownEvent, phase, cx| { @@ -906,9 +913,7 @@ pub struct ClickEvent { pub struct Drag where - S: 'static + Send + Sync, R: Fn(&mut V, &mut ViewContext) -> E, - V: 'static + Send + Sync, E: Element, { pub state: S, @@ -918,9 +923,7 @@ where impl Drag where - S: 'static + Send + Sync, R: Fn(&mut V, &mut ViewContext) -> E + Send + Sync, - V: 'static + Send + Sync, E: Element, { pub fn new(state: S, render_drag_handle: R) -> Self { diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index a8a4d650d6..c1aa64d084 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -6,12 +6,12 @@ use crate::{ }; use std::{marker::PhantomData, sync::Arc}; -pub struct View { +pub struct View { state: Handle, render: Arc) -> AnyElement + Send + Sync + 'static>, } -impl View { +impl View { pub fn into_any(self) -> AnyView { AnyView { view: Arc::new(Mutex::new(self)), @@ -19,7 +19,7 @@ impl View { } } -impl Clone for View { +impl Clone for View { fn clone(&self) -> Self { Self { state: self.state.clone(), @@ -42,9 +42,7 @@ where } } -impl - IntoAnyElement for View -{ +impl IntoAnyElement for View { fn into_any(self) -> AnyElement { AnyElement::new(EraseViewState { view: self, @@ -53,7 +51,7 @@ impl } } -impl Element for View { +impl Element for View { type ViewState = (); type ElementState = AnyElement; @@ -94,26 +92,18 @@ impl Element for View { } } -struct EraseViewState { +struct EraseViewState { view: View, parent_view_state_type: PhantomData, } -impl IntoAnyElement for EraseViewState -where - V: 'static + Send + Sync, - ParentV: 'static + Send + Sync, -{ +impl IntoAnyElement for EraseViewState { fn into_any(self) -> AnyElement { AnyElement::new(self) } } -impl Element for EraseViewState -where - V: 'static + Send + Sync, - ParentV: 'static + Send + Sync, -{ +impl Element for EraseViewState { type ViewState = ParentV; type ElementState = AnyBox; @@ -150,14 +140,14 @@ where } } -trait ViewObject: 'static + Send + Sync { +trait ViewObject { fn entity_id(&self) -> EntityId; fn initialize(&mut self, cx: &mut WindowContext) -> AnyBox; fn layout(&mut self, element: &mut AnyBox, cx: &mut WindowContext) -> LayoutId; fn paint(&mut self, bounds: Bounds, element: &mut AnyBox, cx: &mut WindowContext); } -impl ViewObject for View { +impl ViewObject for View { fn entity_id(&self) -> EntityId { self.state.entity_id } diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index f803bb7bb6..3c9409d9ea 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -1129,7 +1129,7 @@ impl<'a, 'w> MainThread> { } impl Context for WindowContext<'_, '_> { - type EntityContext<'a, 'w, T: 'static + Send + Sync> = ViewContext<'a, 'w, T>; + type EntityContext<'a, 'w, T> = ViewContext<'a, 'w, T>; type Result = T; fn entity( @@ -1145,7 +1145,7 @@ impl Context for WindowContext<'_, '_> { self.entities.insert(slot, entity) } - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R, @@ -1340,7 +1340,7 @@ impl BorrowWindow for ViewContext<'_, '_, S> { } } -impl<'a, 'w, V: Send + Sync + 'static> ViewContext<'a, 'w, V> { +impl<'a, 'w, V> ViewContext<'a, 'w, V> { fn mutable(app: &'a mut AppContext, window: &'w mut Window, entity_id: EntityId) -> Self { Self { window_cx: WindowContext::mutable(app, window), @@ -1580,8 +1580,9 @@ impl<'a, 'w, V: Send + Sync + 'static> ViewContext<'a, 'w, V> { f: impl FnOnce(WeakHandle, AsyncWindowContext) -> Fut + Send + 'static, ) -> Task where - R: Send + 'static, - Fut: Future + Send + 'static, + V: 'static + Send + Sync, + R: 'static + Send, + Fut: 'static + Future + Send, { let handle = self.handle(); self.window_cx.spawn(move |_, cx| { @@ -1640,11 +1641,8 @@ impl<'a, 'w, V: EventEmitter + Send + Sync + 'static> ViewContext<'a, 'w, V> { } } -impl<'a, 'w, V> Context for ViewContext<'a, 'w, V> -where - V: 'static + Send + Sync, -{ - type EntityContext<'b, 'c, U: 'static + Send + Sync> = ViewContext<'b, 'c, U>; +impl<'a, 'w, V> Context for ViewContext<'a, 'w, V> { + type EntityContext<'b, 'c, U> = ViewContext<'b, 'c, U>; type Result = U; fn entity( @@ -1654,7 +1652,7 @@ where self.window_cx.entity(build_entity) } - fn update_entity( + fn update_entity( &mut self, handle: &Handle, update: impl FnOnce(&mut U, &mut Self::EntityContext<'_, '_, U>) -> R, diff --git a/crates/gpui2_macros/src/derive_into_any_element.rs b/crates/gpui2_macros/src/derive_into_any_element.rs index 7d403a6eca..4c6d9e3d7f 100644 --- a/crates/gpui2_macros/src/derive_into_any_element.rs +++ b/crates/gpui2_macros/src/derive_into_any_element.rs @@ -44,7 +44,7 @@ pub fn derive_into_any_element(input: TokenStream) -> TokenStream { #where_clause { fn into_any(self) -> gpui2::AnyElement<#view_type> { - self.render().into_any() + Self::render(self).into_any() } } } diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index c25539ea3c..0f7aa8d75a 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -1,6 +1,6 @@ use crate::prelude::*; use crate::{Icon, IconButton, Label, Panel, PanelSide}; -use gpui2::{rems, AbsoluteLength, IntoAnyElement}; +use gpui2::{div, rems, AbsoluteLength, IntoAnyElement}; #[derive(IntoAnyElement)] pub struct AssistantPanel { @@ -21,7 +21,9 @@ impl AssistantPanel { self } - fn render(mut self) -> impl IntoAnyElement { + fn render(mut self) -> impl IntoAnyElement { + div() + // let color = ThemeColor::new(cx); // Panel::new(self.id, cx) @@ -91,9 +93,9 @@ mod stories { Self } - fn render(self) -> impl IntoAnyElement { - Story::container(self.cx) - .child(Story::title_for::<_, AssistantPanel>(self.cx)) + fn render(self) -> impl IntoAnyElement { + Story::container(self.0) + .child(Story::title_for::<_, AssistantPanel>(self.0)) .child(Story::label(self.cx, "Default")) .child(AssistantPanel::new("assistant-panel")) } diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index d815ef412f..852498fc07 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -16,7 +16,7 @@ pub struct Breadcrumb<'a> { cx: &'a AppContext, } -impl Breadcrumb { +impl<'a> Breadcrumb<'a> { pub fn new(path: PathBuf, symbols: Vec, cx: &'a AppContext) -> Self { Self { path, symbols, cx } } @@ -27,7 +27,7 @@ impl Breadcrumb { } fn render(mut self) -> impl IntoAnyElement { - let color = ThemeColor::new(cx); + let color = ThemeColor::new(self.cx); let symbols_len = self.symbols.len(); diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index af8c75fc26..df804fab04 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -19,7 +19,7 @@ impl ChatPanel { } } - pub fn messages(mut self, messages: Vec>) -> Self { + pub fn messages(mut self, messages: Vec) -> Self { self.messages = messages; self } diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rs index 3821f11c3b..b657f9fe8e 100644 --- a/crates/ui2/src/story.rs +++ b/crates/ui2/src/story.rs @@ -18,10 +18,7 @@ impl Story { .bg(color.background) } - pub fn title( - cx: &mut ViewContext, - title: &str, - ) -> impl Element { + pub fn title(cx: &mut ViewContext, title: &str) -> impl Element { let color = ThemeColor::new(cx); div() @@ -30,16 +27,11 @@ impl Story { .child(title.to_owned()) } - pub fn title_for( - cx: &mut ViewContext, - ) -> impl Element { + pub fn title_for(cx: &mut ViewContext) -> impl Element { Self::title(cx, std::any::type_name::()) } - pub fn label( - cx: &mut ViewContext, - label: &str, - ) -> impl Element { + pub fn label(cx: &mut ViewContext, label: &str) -> impl Element { let color = ThemeColor::new(cx); div() diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rs index bf354e7c15..dc5ec93565 100644 --- a/crates/ui2/src/theme.rs +++ b/crates/ui2/src/theme.rs @@ -150,7 +150,7 @@ pub struct Themed { impl IntoAnyElement for Themed where - E: Element, + E: 'static + Element + Send + Sync, { fn into_any(self) -> AnyElement { AnyElement::new(self) @@ -160,7 +160,10 @@ where #[derive(Default)] struct ThemeStack(Vec); -impl Element for Themed { +impl Element for Themed +where + E: 'static + Element + Send + Sync, +{ type ViewState = E::ViewState; type ElementState = E::ElementState;