Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix runtime errors
Nathan Soboda8919002fce
diff --git a/crates/feature_flags2/src/feature_flags2.rs b/crates/feature_flags2/src/feature_flags2.rsindex d5f10ea5876..48534051e76 100644--- a/crates/feature_flags2/src/feature_flags2.rs+++ b/crates/feature_flags2/src/feature_flags2.rs@@ -51,13 +51,13 @@ pub trait FeatureFlagAppExt {impl FeatureFlagAppExt for AppContext {fn update_flags(&mut self, staff: bool, flags: Vec<String>) {- let feature_flags = self.default_global::<FeatureFlags>();+ let feature_flags = self.default_global_mut::<FeatureFlags>();feature_flags.staff = staff;feature_flags.flags = flags;}fn set_staff(&mut self, staff: bool) {- let feature_flags = self.default_global::<FeatureFlags>();+ let feature_flags = self.default_global_mut::<FeatureFlags>();feature_flags.staff = staff;}diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rsindex 516cdbc46ad..1e4852ff4d4 100644--- a/crates/gpui2/src/app.rs+++ b/crates/gpui2/src/app.rs@@ -510,14 +510,12 @@ impl AppContext {.unwrap()}- pub fn default_global<G: 'static + Default + Sync + Send>(&mut self) -> &mut G {+ pub fn default_global_mut<G: 'static + Default + Sync + Send>(&mut self) -> &mut G {let global_type = TypeId::of::<G>();self.push_effect(Effect::NotifyGlobalObservers { global_type });self.globals_by_type- .insert(global_type, Box::new(G::default()));- self.globals_by_type- .get_mut(&global_type)- .unwrap()+ .entry(global_type)+ .or_insert_with(|| Box::new(G::default())).downcast_mut::<G>().unwrap()}diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rsindex 56dcba9571b..475cbb75a47 100644--- a/crates/gpui2/src/interactive.rs+++ b/crates/gpui2/src/interactive.rs@@ -603,7 +603,7 @@ pub struct GroupBounds(HashMap<SharedString, SmallVec<[Bounds<Pixels>; 1]>>);impl GroupBounds {pub fn get(name: &SharedString, cx: &mut AppContext) -> Option<Bounds<Pixels>> {- cx.default_global::<Self>()+ cx.default_global_mut::<Self>().0.get(name).and_then(|bounds_stack| bounds_stack.last())@@ -611,7 +611,7 @@ impl GroupBounds {}pub fn push(name: SharedString, bounds: Bounds<Pixels>, cx: &mut AppContext) {- cx.default_global::<Self>()+ cx.default_global_mut::<Self>().0.entry(name).or_default()@@ -619,7 +619,7 @@ impl GroupBounds {}pub fn pop(name: &SharedString, cx: &mut AppContext) {- cx.default_global::<GroupBounds>()+ cx.default_global_mut::<Self>().0.get_mut(name).unwrap()diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rsindex 552e124c06e..6aba3f5c26b 100644--- a/crates/storybook2/src/storybook2.rs+++ b/crates/storybook2/src/storybook2.rs@@ -56,6 +56,9 @@ fn main() {let selector =story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));+ cx.set_global(theme.clone());+ ui::settings::init(cx);+let window = cx.open_window(WindowOptions {bounds: WindowBounds::Fixed(Bounds {diff --git a/crates/ui2/src/lib.rs b/crates/ui2/src/lib.rsindex c2d02369a1a..8bc7bfa8109 100644--- a/crates/ui2/src/lib.rs+++ b/crates/ui2/src/lib.rs@@ -4,7 +4,7 @@ mod components;mod element_ext;mod elements;pub mod prelude;-mod settings;+pub mod settings;mod static_data;mod theme;diff --git a/crates/ui2/src/settings.rs b/crates/ui2/src/settings.rsindex 5c88608c88f..48a2e8e7b43 100644--- a/crates/ui2/src/settings.rs+++ b/crates/ui2/src/settings.rs@@ -1,9 +1,13 @@use std::ops::Deref;-use gpui2::{rems, AbsoluteLength, WindowContext};+use gpui2::{rems, AbsoluteLength, AppContext, WindowContext};use crate::prelude::*;+pub fn init(cx: &mut AppContext) {+ cx.set_global(FakeSettings::default());+}+/// Returns the user settings.pub fn user_settings(cx: &WindowContext) -> FakeSettings {cx.global::<FakeSettings>().clone()diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rsindex dec773b08fb..bf354e7c15e 100644--- a/crates/ui2/src/theme.rs+++ b/crates/ui2/src/theme.rs@@ -137,9 +137,9 @@ whereE: Element,F: FnOnce(&mut ViewContext<E::ViewState>) -> E,{- cx.default_global::<ThemeStack>().0.push(theme.clone());+ cx.default_global_mut::<ThemeStack>().0.push(theme.clone());let child = build_child(cx);- cx.default_global::<ThemeStack>().0.pop();+ cx.default_global_mut::<ThemeStack>().0.pop();Themed { theme, child }}@@ -174,9 +174,11 @@ impl<E: Element> Element for Themed<E> {element_state: Option<Self::ElementState>,cx: &mut ViewContext<Self::ViewState>,) -> Self::ElementState {- cx.default_global::<ThemeStack>().0.push(self.theme.clone());+ cx.default_global_mut::<ThemeStack>()+ .0+ .push(self.theme.clone());let element_state = self.child.initialize(view_state, element_state, cx);- cx.default_global::<ThemeStack>().0.pop();+ cx.default_global_mut::<ThemeStack>().0.pop();element_state}@@ -189,9 +191,11 @@ impl<E: Element> Element for Themed<E> {whereSelf: Sized,{- cx.default_global::<ThemeStack>().0.push(self.theme.clone());+ cx.default_global_mut::<ThemeStack>()+ .0+ .push(self.theme.clone());let layout_id = self.child.layout(view_state, element_state, cx);- cx.default_global::<ThemeStack>().0.pop();+ cx.default_global_mut::<ThemeStack>().0.pop();layout_id}@@ -204,9 +208,11 @@ impl<E: Element> Element for Themed<E> {) whereSelf: Sized,{- cx.default_global::<ThemeStack>().0.push(self.theme.clone());+ cx.default_global_mut::<ThemeStack>()+ .0+ .push(self.theme.clone());self.child.paint(bounds, view_state, frame_state, cx);- cx.default_global::<ThemeStack>().0.pop();+ cx.default_global_mut::<ThemeStack>().0.pop();}}