Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Record debug selectors only in debug builds (#65056)
Conrad Irwin506beb34de3f
diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rsindex a4c9fb6528c..e7a8c06fd5f 100644--- a/crates/gpui/src/app/test_context.rs+++ b/crates/gpui/src/app/test_context.rs@@ -983,7 +983,10 @@ impl VisualTestContext {self.simulate_window_scale_factor_change(self.window, scale_factor)}- /// debug_bounds returns the bounds of the element with the given selector.+ /// Returns the bounds of the element with the given debug selector.+ ///+ /// Returns `None` in builds without `debug_assertions`, which don't record+ /// selectors; see [`crate::InteractiveElement::debug_selector`].pub fn debug_bounds(&mut self, selector: &'static str) -> Option<Bounds<Pixels>> {self.update(|window, _| window.rendered_frame.debug_bounds.get(selector).copied())}diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rsindex c32ac995ec5..fc292f2a81e 100644--- a/crates/gpui/src/elements/div.rs+++ b/crates/gpui/src/elements/div.rs@@ -875,19 +875,25 @@ pub trait InteractiveElement: Sized {self}- #[cfg(any(test, feature = "test-support"))]/// Set a key that can be used to look up this element's bounds- /// in the [`crate::VisualTestContext::debug_bounds`] map- /// This is a noop in release builds+ /// in the [`crate::VisualTestContext::debug_bounds`] map.+ ///+ /// Selectors are only recorded in debug builds with the `test-support`+ /// feature. Elsewhere this is a no-op, so `test-support` can stay enabled+ /// in release builds without the per-frame cost.+ #[cfg(any(test, all(debug_assertions, feature = "test-support")))]fn debug_selector(mut self, f: impl FnOnce() -> String) -> Self {self.interactivity().debug_selector = Some(f());self}- #[cfg(not(any(test, feature = "test-support")))]/// Set a key that can be used to look up this element's bounds- /// in the [`crate::VisualTestContext::debug_bounds`] map- /// This is a noop in release builds+ /// in the [`crate::VisualTestContext::debug_bounds`] map.+ ///+ /// Selectors are only recorded in debug builds with the `test-support`+ /// feature. Elsewhere this is a no-op, so `test-support` can stay enabled+ /// in release builds without the per-frame cost.+ #[cfg(not(any(test, all(debug_assertions, feature = "test-support"))))]#[inline]fn debug_selector(self, _: impl FnOnce() -> String) -> Self {self@@ -2194,7 +2200,7 @@ pub struct Interactivity {#[cfg(any(feature = "inspector", debug_assertions))]pub(crate) source_location: Option<&'static core::panic::Location<'static>>,- #[cfg(any(test, feature = "test-support"))]+ #[cfg(any(test, all(debug_assertions, feature = "test-support")))]pub(crate) debug_selector: Option<String>,}@@ -2517,7 +2523,7 @@ impl Interactivity {let style = self.compute_style_internal(hitbox, element_state.as_mut(), window, cx);- #[cfg(any(feature = "test-support", test))]+ #[cfg(any(test, all(debug_assertions, feature = "test-support")))]if let Some(debug_selector) = &self.debug_selector {window.next_frame