From 297fd858e8f97a61dd69cd8c4801a04c2a2c8266 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Thu, 14 Aug 2025 19:10:19 -0600 Subject: [PATCH] Code for debugging issue with no width available This commit enables extremely verbose taffy logging and adds output of the layout ids for the Open Router settings container ID and the ID for the text input that has the issue. https://gist.github.com/mgsloan/28a2d8d9c9c803fc60898eae9db1ec8e is the subsets of the logs starting with the first line with the container ID and ending with the last line that has the container ID (see the end of the logs for these IDs) Repro for the issue: * Set ui_font_size to 20 in user settings.json * Open zed agent settings * Expand Open Router settings * Resize panel until the API key input field becomes small --- crates/gpui/Cargo.toml | 2 +- crates/gpui/src/elements/div.rs | 19 ++++++++++++++++++- crates/gpui/src/taffy.rs | 18 +++++++++++++++++- .../src/provider/open_router.rs | 2 ++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index d720dfb2a1..0bf0cd8c0f 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -121,7 +121,7 @@ smallvec.workspace = true smol.workspace = true strum.workspace = true sum_tree.workspace = true -taffy = "=0.9.0" +taffy = { version = "=0.9.0", features = ["debug"] } thiserror.workspace = true util.workspace = true uuid.workspace = true diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 09afbff929..0669d36b2c 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -23,6 +23,7 @@ use crate::{ MouseClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Overflow, ParentElement, Pixels, Point, Render, ScrollWheelEvent, SharedString, Size, Style, StyleRefinement, Styled, Task, TooltipId, Visibility, Window, WindowControlArea, point, px, size, + taffy::{CONTAINER_LAYOUT_ID_TO_DEBUG, LAYOUT_ID_TO_DEBUG}, }; use collections::HashMap; use refineable::Refineable; @@ -1298,7 +1299,23 @@ impl Element for Div { .iter_mut() .map(|child| child.request_layout(window, cx)) .collect::>(); - window.request_layout(style, child_layout_ids.iter().copied(), cx) + let layout_id = + window.request_layout(style, child_layout_ids.iter().copied(), cx); + if let Some(global_id) = global_id.as_ref() + && global_id.0.ends_with(&["api-key-editor".into()]) + { + LAYOUT_ID_TO_DEBUG.with_borrow_mut(|layout_id_to_debug| { + *layout_id_to_debug = Some(layout_id) + }); + } + if let Some(global_id) = global_id.as_ref() + && global_id.0.ends_with(&["open-router-container".into()]) + { + CONTAINER_LAYOUT_ID_TO_DEBUG.with_borrow_mut(|layout_id_to_debug| { + *layout_id_to_debug = Some(layout_id) + }); + } + layout_id }) }, ) diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rs index ee21ecd8c4..61736e456c 100644 --- a/crates/gpui/src/taffy.rs +++ b/crates/gpui/src/taffy.rs @@ -3,7 +3,7 @@ use crate::{ }; use collections::{FxHashMap, FxHashSet}; use smallvec::SmallVec; -use std::{fmt::Debug, ops::Range}; +use std::{cell::RefCell, fmt::Debug, ops::Range}; use taffy::{ TaffyTree, TraversePartialTree as _, geometry::{Point as TaffyPoint, Rect as TaffyRect, Size as TaffySize}, @@ -11,6 +11,14 @@ use taffy::{ tree::NodeId, }; +thread_local! { + pub static LAYOUT_ID_TO_DEBUG: RefCell> = const { RefCell::new(None) }; +} + +thread_local! { + pub static CONTAINER_LAYOUT_ID_TO_DEBUG: RefCell> = const { RefCell::new(None) }; +} + type NodeMeasureFn = Box< dyn FnMut(Size>, Size, &mut Window, &mut App) -> Size, >; @@ -198,6 +206,14 @@ impl TaffyLayoutEngine { ) .expect(EXPECT_MESSAGE); + LAYOUT_ID_TO_DEBUG.with_borrow(|layout_id_to_debug| { + println!("Layout ID Debug: {:?}", layout_id_to_debug); + }); + + CONTAINER_LAYOUT_ID_TO_DEBUG.with_borrow(|layout_id| { + println!("Container Layout ID Debug: {:?}\n", layout_id); + }); + // println!("compute_layout took {:?}", started_at.elapsed()); } diff --git a/crates/language_models/src/provider/open_router.rs b/crates/language_models/src/provider/open_router.rs index 3a492086f1..6e56bb5344 100644 --- a/crates/language_models/src/provider/open_router.rs +++ b/crates/language_models/src/provider/open_router.rs @@ -853,6 +853,7 @@ impl Render for ConfigurationView { div().child(Label::new("Loading credentials...")).into_any() } else if self.should_render_editor(cx) { v_flex() + .id("open-router-container") .size_full() .on_action(cx.listener(Self::save_api_key)) .child(Label::new("To use Zed's agent with OpenRouter, you need to add an API key. Follow these steps:")) @@ -872,6 +873,7 @@ impl Render for ConfigurationView { ) .child( h_flex() + .id("api-key-editor") .w_full() .my_2() .px_2()