Allow dumping the project diagnostic view's state as JSON
Also, improve DebugElements action so that it shows the JSON in an editor. Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
54d49c13d9
commit
949fbe7cd3
@@ -62,6 +62,9 @@ pub trait View: Entity + Sized {
|
||||
cx.set.insert(Self::ui_name().into());
|
||||
cx
|
||||
}
|
||||
fn debug_json(&self, _: &AppContext) -> serde_json::Value {
|
||||
serde_json::Value::Null
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ReadModel {
|
||||
@@ -2277,6 +2280,12 @@ pub struct AppContext {
|
||||
}
|
||||
|
||||
impl AppContext {
|
||||
pub(crate) fn root_view(&self, window_id: usize) -> Option<AnyViewHandle> {
|
||||
self.windows
|
||||
.get(&window_id)
|
||||
.map(|window| window.root_view.clone())
|
||||
}
|
||||
|
||||
pub fn root_view_id(&self, window_id: usize) -> Option<usize> {
|
||||
self.windows
|
||||
.get(&window_id)
|
||||
@@ -2590,6 +2599,7 @@ pub trait AnyView {
|
||||
fn on_focus(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize);
|
||||
fn on_blur(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize);
|
||||
fn keymap_context(&self, cx: &AppContext) -> keymap::Context;
|
||||
fn debug_json(&self, cx: &AppContext) -> serde_json::Value;
|
||||
}
|
||||
|
||||
impl<T> AnyView for T
|
||||
@@ -2653,6 +2663,10 @@ where
|
||||
fn keymap_context(&self, cx: &AppContext) -> keymap::Context {
|
||||
View::keymap_context(self, cx)
|
||||
}
|
||||
|
||||
fn debug_json(&self, cx: &AppContext) -> serde_json::Value {
|
||||
View::debug_json(self, cx)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ModelContext<'a, T: ?Sized> {
|
||||
@@ -3927,6 +3941,12 @@ impl AnyViewHandle {
|
||||
pub fn view_type(&self) -> TypeId {
|
||||
self.view_type
|
||||
}
|
||||
|
||||
pub fn debug_json(&self, cx: &AppContext) -> serde_json::Value {
|
||||
cx.views
|
||||
.get(&(self.window_id, self.view_id))
|
||||
.map_or_else(|| serde_json::Value::Null, |view| view.debug_json(cx))
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for AnyViewHandle {
|
||||
|
||||
@@ -209,15 +209,18 @@ impl Presenter {
|
||||
}
|
||||
|
||||
pub fn debug_elements(&self, cx: &AppContext) -> Option<json::Value> {
|
||||
cx.root_view_id(self.window_id)
|
||||
.and_then(|root_view_id| self.rendered_views.get(&root_view_id))
|
||||
.map(|root_element| {
|
||||
root_element.debug(&DebugContext {
|
||||
rendered_views: &self.rendered_views,
|
||||
font_cache: &self.font_cache,
|
||||
app: cx,
|
||||
let view = cx.root_view(self.window_id)?;
|
||||
Some(json!({
|
||||
"root_view": view.debug_json(cx),
|
||||
"root_element": self.rendered_views.get(&view.id())
|
||||
.map(|root_element| {
|
||||
root_element.debug(&DebugContext {
|
||||
rendered_views: &self.rendered_views,
|
||||
font_cache: &self.font_cache,
|
||||
app: cx,
|
||||
})
|
||||
})
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,6 +557,7 @@ impl Element for ChildView {
|
||||
"type": "ChildView",
|
||||
"view_id": self.view.id(),
|
||||
"bounds": bounds.to_json(),
|
||||
"view": self.view.debug_json(cx.app),
|
||||
"child": if let Some(view) = cx.rendered_views.get(&self.view.id()) {
|
||||
view.debug(cx)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user