Add initial element inspector for Zed development (#31315)
Open inspector with `dev: toggle inspector` from command palette or `cmd-alt-i` on mac or `ctrl-alt-i` on linux. https://github.com/user-attachments/assets/54c43034-d40b-414e-ba9b-190bed2e6d2f * Picking of elements via the mouse, with scroll wheel to inspect occluded elements. * Temporary manipulation of the selected element. * Layout info and JSON-based style manipulation for `Div`. * Navigation to code that constructed the element. Big thanks to @as-cii and @maxdeviant for sorting out how to implement the core of an inspector. Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Marshall Bowers <git@maxdeviant.com> Co-authored-by: Federico Dionisi <code@fdionisi.me>
This commit is contained in:
co-authored by
Antonio Scandurra
Marshall Bowers
Federico Dionisi
parent
685933b5c8
commit
ab59982bf7
@@ -138,7 +138,6 @@ pub use git::blame::BlameRenderer;
|
||||
pub use proposed_changes_editor::{
|
||||
ProposedChangeLocation, ProposedChangesEditor, ProposedChangesEditorToolbar,
|
||||
};
|
||||
use smallvec::smallvec;
|
||||
use std::{cell::OnceCell, iter::Peekable, ops::Not};
|
||||
use task::{ResolvedTask, RunnableTag, TaskTemplate, TaskVariables};
|
||||
|
||||
@@ -176,7 +175,7 @@ use selections_collection::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsLocation, SettingsStore, update_settings_file};
|
||||
use smallvec::SmallVec;
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use snippet::Snippet;
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
@@ -7993,7 +7992,7 @@ impl Editor {
|
||||
.gap_1()
|
||||
// Workaround: For some reason, there's a gap if we don't do this
|
||||
.ml(-BORDER_WIDTH)
|
||||
.shadow(smallvec![gpui::BoxShadow {
|
||||
.shadow(vec![gpui::BoxShadow {
|
||||
color: gpui::black().opacity(0.05),
|
||||
offset: point(px(1.), px(1.)),
|
||||
blur_radius: px(2.),
|
||||
@@ -16708,7 +16707,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub fn wrap_guides(&self, cx: &App) -> SmallVec<[(usize, bool); 2]> {
|
||||
let mut wrap_guides = smallvec::smallvec![];
|
||||
let mut wrap_guides = smallvec![];
|
||||
|
||||
if self.show_wrap_guides == Some(false) {
|
||||
return wrap_guides;
|
||||
|
||||
@@ -7181,9 +7181,14 @@ impl Element for EditorElement {
|
||||
None
|
||||
}
|
||||
|
||||
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn request_layout(
|
||||
&mut self,
|
||||
_: Option<&GlobalElementId>,
|
||||
__inspector_id: Option<&gpui::InspectorElementId>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> (gpui::LayoutId, ()) {
|
||||
@@ -7290,6 +7295,7 @@ impl Element for EditorElement {
|
||||
fn prepaint(
|
||||
&mut self,
|
||||
_: Option<&GlobalElementId>,
|
||||
_inspector_id: Option<&gpui::InspectorElementId>,
|
||||
bounds: Bounds<Pixels>,
|
||||
_: &mut Self::RequestLayoutState,
|
||||
window: &mut Window,
|
||||
@@ -7761,7 +7767,7 @@ impl Element for EditorElement {
|
||||
// If the fold widths have changed, we need to prepaint
|
||||
// the element again to account for any changes in
|
||||
// wrapping.
|
||||
return self.prepaint(None, bounds, &mut (), window, cx);
|
||||
return self.prepaint(None, _inspector_id, bounds, &mut (), window, cx);
|
||||
}
|
||||
|
||||
let longest_line_blame_width = self
|
||||
@@ -7846,7 +7852,7 @@ impl Element for EditorElement {
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
editor.resize_blocks(resized_blocks, autoscroll_request, cx)
|
||||
});
|
||||
return self.prepaint(None, bounds, &mut (), window, cx);
|
||||
return self.prepaint(None, _inspector_id, bounds, &mut (), window, cx);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8345,6 +8351,7 @@ impl Element for EditorElement {
|
||||
fn paint(
|
||||
&mut self,
|
||||
_: Option<&GlobalElementId>,
|
||||
__inspector_id: Option<&gpui::InspectorElementId>,
|
||||
bounds: Bounds<gpui::Pixels>,
|
||||
_: &mut Self::RequestLayoutState,
|
||||
layout: &mut Self::PrepaintState,
|
||||
|
||||
@@ -1135,7 +1135,7 @@ impl SerializableItem for Editor {
|
||||
mtime,
|
||||
..
|
||||
} => {
|
||||
let project_item = project.update(cx, |project, cx| {
|
||||
let opened_buffer = project.update(cx, |project, cx| {
|
||||
let (worktree, path) = project.find_worktree(&abs_path, cx)?;
|
||||
let project_path = ProjectPath {
|
||||
worktree_id: worktree.read(cx).id(),
|
||||
@@ -1144,13 +1144,10 @@ impl SerializableItem for Editor {
|
||||
Some(project.open_path(project_path, cx))
|
||||
});
|
||||
|
||||
match project_item {
|
||||
Some(project_item) => {
|
||||
match opened_buffer {
|
||||
Some(opened_buffer) => {
|
||||
window.spawn(cx, async move |cx| {
|
||||
let (_, project_item) = project_item.await?;
|
||||
let buffer = project_item.downcast::<Buffer>().map_err(|_| {
|
||||
anyhow!("Project item at stored path was not a buffer")
|
||||
})?;
|
||||
let (_, buffer) = opened_buffer.await?;
|
||||
|
||||
// This is a bit wasteful: we're loading the whole buffer from
|
||||
// disk and then overwrite the content.
|
||||
|
||||
Reference in New Issue
Block a user