From e557eb4afe05195f7196f118270816d7a1ad73d6 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Tue, 21 Nov 2023 12:45:25 -0800 Subject: [PATCH 1/3] Fix no window showing up on startup co-authored-by: Marshall --- crates/zed2/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 9c42badb85..c1db4eace4 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -355,7 +355,7 @@ async fn restore_or_create_workspace(app_state: &Arc, mut cx: AsyncApp cx.update(|cx| workspace::open_paths(location.paths().as_ref(), app_state, None, cx))? .await .log_err(); - } else if matches!(KEY_VALUE_STORE.read_kvp("******* THIS IS A BAD KEY PLEASE UNCOMMENT BELOW TO FIX THIS VERY LONG LINE *******"), Ok(None)) { + // todo!(welcome) //} else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) { //todo!() From 469b05684f261149c20a8e8438c4da9d813ce4ab Mon Sep 17 00:00:00 2001 From: Mikayla Date: Tue, 21 Nov 2023 17:11:38 -0800 Subject: [PATCH 2/3] Fix a few identity mixups in GPUI co-authored-by: nathan --- crates/diagnostics2/src/items.rs | 2 +- crates/gpui2/src/element.rs | 6 +-- crates/gpui2/src/view.rs | 22 ++++------ crates/gpui2/src/window.rs | 68 ++++++++++++++++++++++++----- crates/workspace2/src/dock.rs | 2 +- crates/workspace2/src/pane.rs | 4 +- crates/workspace2/src/pane_group.rs | 24 +++++----- 7 files changed, 84 insertions(+), 44 deletions(-) diff --git a/crates/diagnostics2/src/items.rs b/crates/diagnostics2/src/items.rs index bbcfa748d4..ac24b7ad50 100644 --- a/crates/diagnostics2/src/items.rs +++ b/crates/diagnostics2/src/items.rs @@ -44,7 +44,7 @@ impl Render for DiagnosticIndicator { }; h_stack() - .id(cx.entity_id()) + .id("diagnostic-indicator") .on_action(cx.listener(Self::go_to_next_diagnostic)) .rounded_md() .flex_none() diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 5cd015503d..1045e6218c 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -432,10 +432,6 @@ impl AnyElement { AnyElement(Box::new(Some(DrawableElement::new(element))) as Box) } - pub fn element_id(&self) -> Option { - self.0.element_id() - } - pub fn layout(&mut self, cx: &mut WindowContext) -> LayoutId { self.0.layout(cx) } @@ -490,7 +486,7 @@ impl RenderOnce for AnyElement { type Element = Self; fn element_id(&self) -> Option { - AnyElement::element_id(self) + None } fn render_once(self) -> Self::Element { diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index efa40627ac..c46707c7e2 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -248,7 +248,7 @@ impl RenderOnce for View { type Element = View; fn element_id(&self) -> Option { - Some(self.model.entity_id.into()) + Some(ElementId::from_entity_id(self.model.entity_id)) } fn render_once(self) -> Self::Element { @@ -260,7 +260,7 @@ impl RenderOnce for AnyView { type Element = Self; fn element_id(&self) -> Option { - Some(self.model.entity_id.into()) + Some(ElementId::from_entity_id(self.model.entity_id)) } fn render_once(self) -> Self::Element { @@ -308,27 +308,23 @@ where } mod any_view { - use crate::{AnyElement, AnyView, BorrowWindow, Element, LayoutId, Render, WindowContext}; + use crate::{AnyElement, AnyView, Element, LayoutId, Render, WindowContext}; pub(crate) fn layout( view: &AnyView, cx: &mut WindowContext, ) -> (LayoutId, AnyElement) { - cx.with_element_id(Some(view.model.entity_id), |cx| { - let view = view.clone().downcast::().unwrap(); - let mut element = view.update(cx, |view, cx| view.render(cx).into_any()); - let layout_id = element.layout(cx); - (layout_id, element) - }) + let view = view.clone().downcast::().unwrap(); + let mut element = view.update(cx, |view, cx| view.render(cx).into_any()); + let layout_id = element.layout(cx); + (layout_id, element) } pub(crate) fn paint( - view: &AnyView, + _view: &AnyView, element: AnyElement, cx: &mut WindowContext, ) { - cx.with_element_id(Some(view.model.entity_id), |cx| { - element.paint(cx); - }) + element.paint(cx); } } diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 483a8fdbee..1973aa14a9 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -230,9 +230,15 @@ pub struct Window { pub(crate) focus: Option, } +pub(crate) struct ElementStateBox { + inner: Box, + #[cfg(debug_assertions)] + type_name: &'static str, +} + // #[derive(Default)] pub(crate) struct Frame { - pub(crate) element_states: HashMap>, + pub(crate) element_states: HashMap, mouse_listeners: HashMap>, pub(crate) dispatch_tree: DispatchTree, pub(crate) focus_listeners: Vec, @@ -1815,10 +1821,37 @@ pub trait BorrowWindow: BorrowMut + BorrowMut { .remove(&global_id) }) { + let ElementStateBox { + inner, + + #[cfg(debug_assertions)] + type_name + } = any; // Using the extra inner option to avoid needing to reallocate a new box. - let mut state_box = any + let mut state_box = inner .downcast::>() - .expect("invalid element state type for id"); + .map_err(|_| { + #[cfg(debug_assertions)] + { + anyhow!( + "invalid element state type for id, requested_type {:?}, actual type: {:?}", + std::any::type_name::(), + type_name + ) + } + + #[cfg(not(debug_assertions))] + { + anyhow!( + "invalid element state type for id, requested_type {:?}", + std::any::type_name::(), + ) + } + }) + .unwrap(); + + // Actual: Option <- View + // Requested: () <- AnyElemet let state = state_box .take() .expect("element state is already on the stack"); @@ -1827,14 +1860,27 @@ pub trait BorrowWindow: BorrowMut + BorrowMut { cx.window_mut() .current_frame .element_states - .insert(global_id, state_box); + .insert(global_id, ElementStateBox { + inner: state_box, + + #[cfg(debug_assertions)] + type_name + }); result } else { let (result, state) = f(None, cx); cx.window_mut() .current_frame .element_states - .insert(global_id, Box::new(Some(state))); + .insert(global_id, + ElementStateBox { + inner: Box::new(Some(state)), + + #[cfg(debug_assertions)] + type_name: std::any::type_name::() + } + + ); result } }) @@ -2599,6 +2645,12 @@ pub enum ElementId { FocusHandle(FocusId), } +impl ElementId { + pub(crate) fn from_entity_id(entity_id: EntityId) -> Self { + ElementId::View(entity_id) + } +} + impl TryInto for ElementId { type Error = anyhow::Error; @@ -2611,12 +2663,6 @@ impl TryInto for ElementId { } } -impl From for ElementId { - fn from(id: EntityId) -> Self { - ElementId::View(id) - } -} - impl From for ElementId { fn from(id: usize) -> Self { ElementId::Integer(id) diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rs index b44178ceb7..8bc07b6e90 100644 --- a/crates/workspace2/src/dock.rs +++ b/crates/workspace2/src/dock.rs @@ -721,7 +721,7 @@ impl Render for PanelButtons { let panel = panel.clone(); menu = menu.entry( ListItem::new( - panel.entity_id(), + position.to_label(), Label::new(format!("Dock {}", position.to_label())), ), move |_, cx| { diff --git a/crates/workspace2/src/pane.rs b/crates/workspace2/src/pane.rs index cdc341d7dc..f742be10f4 100644 --- a/crates/workspace2/src/pane.rs +++ b/crates/workspace2/src/pane.rs @@ -1350,7 +1350,7 @@ impl Pane { let id = item.item_id(); div() - .id(item.item_id()) + .id(ix) .invisible() .group_hover("", |style| style.visible()) .child( @@ -1382,7 +1382,7 @@ impl Pane { div() .group("") - .id(item.item_id()) + .id(ix) .cursor_pointer() .when_some(item.tab_tooltip_text(cx), |div, text| { div.tooltip(move |cx| cx.build_view(|cx| Tooltip::new(text.clone())).into()) diff --git a/crates/workspace2/src/pane_group.rs b/crates/workspace2/src/pane_group.rs index bd827a6dd7..3f11421778 100644 --- a/crates/workspace2/src/pane_group.rs +++ b/crates/workspace2/src/pane_group.rs @@ -214,7 +214,7 @@ impl Member { // Some(pane) // }; - div().size_full().child(pane.clone()) + div().size_full().child(pane.clone()).into_any() // Stack::new() // .with_child(pane_element.contained().with_border(leader_border)) @@ -230,16 +230,18 @@ impl Member { // .bg(cx.theme().colors().editor) // .children(); } - Member::Axis(axis) => axis.render( - project, - basis + 1, - follower_states, - active_call, - active_pane, - zoomed, - app_state, - cx, - ), + Member::Axis(axis) => axis + .render( + project, + basis + 1, + follower_states, + active_call, + active_pane, + zoomed, + app_state, + cx, + ) + .into_any(), } // enum FollowIntoExternalProject {} From eb74ad7caaab389a5eefbaac221587a0b157c43e Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 22 Nov 2023 13:41:48 -0800 Subject: [PATCH 3/3] Fix failing test --- crates/diagnostics2/src/diagnostics.rs | 2 +- crates/gpui2/src/element.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/diagnostics2/src/diagnostics.rs b/crates/diagnostics2/src/diagnostics.rs index 7ff8cd84db..01e8762127 100644 --- a/crates/diagnostics2/src/diagnostics.rs +++ b/crates/diagnostics2/src/diagnostics.rs @@ -1550,7 +1550,7 @@ mod tests { block_id: ix, editor_style: &editor::EditorStyle::default(), }) - .element_id()? + .inner_id()? .try_into() .ok()?, diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 1045e6218c..912329c3cb 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -463,6 +463,10 @@ impl AnyElement { pub fn into_any(self) -> AnyElement { AnyElement::new(self) } + + pub fn inner_id(&self) -> Option { + self.0.element_id() + } } impl Element for AnyElement {