Home Explore Blog CI



zed

1st chunk of `crates/inspector_ui/README.md`
fb0da312b3a26c10828a2866271002dd8754871f7923e4f40000000100000a39
# Inspector

This is a tool for inspecting and manipulating rendered elements in Zed. It is only available in debug builds. Use the `dev::ToggleInspector` action to toggle inspector mode and click on UI elements to inspect them.

# Current features

* Picking of elements via the mouse, with scroll wheel to inspect occluded elements.

* Temporary manipulation of the selected element.

* Layout info for `Div`.

* Both Rust and JSON-based style manipulation of `Div` style. The rust style editor only supports argumentless `Styled` and `StyledExt` method calls.

* Navigation to code that constructed the element.

# Known bugs

## JSON style editor undo history doesn't get reset

The JSON style editor appends to its undo stack on every change of the active inspected element.

I attempted to fix it by creating a new buffer and setting the buffer associated with the `json_style_buffer` entity. Unfortunately this doesn't work because the language server uses the `version: clock::Global` to figure out the changes, so would need some way to start the new buffer's text at that version.

```
        json_style_buffer.update(cx, |json_style_buffer, cx| {
            let language = json_style_buffer.language().cloned();
            let file = json_style_buffer.file().cloned();

            *json_style_buffer = Buffer::local("", cx);

            json_style_buffer.set_language(language, cx);
            if let Some(file) = file {
                json_style_buffer.file_updated(file, cx);
            }
        });
```

# Future features

* Action and keybinding for entering pick mode.

* Ability to highlight current element after it's been picked.

* Info and manipulation of element types other than `Div`.

* Indicate when the picked element has disappeared.

* To inspect elements that disappear, it would be helpful to be able to pause the UI.

* Hierarchy view?

## Methods that take arguments in Rust style editor

Could use TreeSitter to parse out the fluent style method chain and arguments. Tricky part of this is completions - ideally the Rust Analyzer already being used by the developer's Zed would be used.

## Edit original code in Rust style editor

Two approaches:

1. Open an excerpt of the original file.

2. Communicate with the Zed process that has the repo open - it would send the code for the element. This seems like a lot of work, but would be very nice for rapid development, and it would allow use of rust analyzer.

With both approaches, would need to record the buffer version and use that when referring to source locations, since editing elements can cause code layout shift.

Title: Zed Inspector Tool: Features, Bugs, and Future Development
Summary
This document describes the Zed Inspector tool, which is used for inspecting and manipulating rendered elements in Zed. It details current features like element picking, temporary manipulation, layout info, Rust and JSON-based style manipulation, and code navigation. It also outlines known bugs, such as issues with the JSON style editor's undo history, and proposes future features like an action for pick mode, highlighting the current element, inspecting other element types, indicating when elements disappear, UI pausing, and a hierarchy view. It also explores methods to improve the Rust style editor, including handling methods with arguments and editing the original code.