Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP: Macro not working fully yet
Nathan Sobof4cff6972971
diff --git a/crates/gpui2_macros/src/derive_component.rs b/crates/gpui2_macros/src/derive_component.rsindex 45f4b44c858..6c0384c95a8 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.rsindex c07723cedbc..c5eeb22a4cf 100644--- a/crates/ui2/src/components/assistant_panel.rs+++ b/crates/ui2/src/components/assistant_panel.rs@@ -69,7 +69,7 @@ impl<S: 'static + Send + Sync> AssistantPanel<S> {.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<S: 'static + Send + Sync> {- state_type: PhantomData<S>,- }+ pub struct AssistantPanelStory {}- impl<S: 'static + Send + Sync> AssistantPanelStory<S> {+ impl AssistantPanelStory {pub fn new() -> Self {- Self {- state_type: PhantomData,- }+ Self {}}- fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {+ fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {Story::container(cx)- .child(Story::title_for::<_, AssistantPanel<S>>(cx))+ .child(Story::title_for::<_, AssistantPanel<V>>(cx)).child(Story::label(cx, "Default")).child(AssistantPanel::new("assistant-panel"))}