diff --git a/crates/gpui2_macros/src/derive_component.rs b/crates/gpui2_macros/src/derive_component.rs index 45f4b44c85..6c0384c95a 100644 --- a/crates/gpui2_macros/src/derive_component.rs +++ b/crates/gpui2_macros/src/derive_component.rs @@ -1,9 +1,21 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, DeriveInput}; +use syn::{parse_macro_input, parse_quote, DeriveInput}; pub fn derive_component(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); + let mut ast = parse_macro_input!(input as DeriveInput); + + if !ast + .generics + .params + .iter() + .any(|param| matches!(param, syn::GenericParam::Type(_))) + { + ast.generics.params.push(parse_quote! { + V: 'static + }); + } + let name = &ast.ident; let generics = &ast.generics; let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); @@ -37,7 +49,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream { if let Some(syn::GenericParam::Type(type_param)) = generics.params.first() { type_param.ident.clone() } else { - panic!("Expected first type parameter"); + panic!("Expected first type parameter to be a view type"); } }); @@ -50,5 +62,9 @@ pub fn derive_component(input: TokenStream) -> TokenStream { } }; + if name == "AssistantPanelStory" { + println!("Expanded tokens: {}", expanded.to_string()); + } + TokenStream::from(expanded) } diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index c07723cedb..c5eeb22a4c 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -69,7 +69,7 @@ impl AssistantPanel { .overflow_y_scroll() .child(Label::new("Is this thing on?")), ) - .render()]) + .renderinto_any()]) .side(self.current_side) .width(AbsoluteLength::Rems(rems(32.))) } @@ -85,20 +85,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct AssistantPanelStory { - state_type: PhantomData, - } + pub struct AssistantPanelStory {} - impl AssistantPanelStory { + impl AssistantPanelStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self {} } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, AssistantPanel>(cx)) + .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) .child(AssistantPanel::new("assistant-panel")) }