Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443)

Editing JSON styles is not very helpful for bringing style changes back
to the actual code. This PR adds a buffer that pretends to be Rust,
applying any style attribute identifiers it finds. Also supports
completions with display of documentation. The effect of the currently
selected completion is previewed. Warning diagnostics appear on any
unrecognized identifier.


https://github.com/user-attachments/assets/af39ff0a-26a5-4835-a052-d8f642b2080c

Adds a `#[derive_inspector_reflection]` macro which allows these methods
to be enumerated and called by their name. The macro code changes were
95% generated by Zed Agent + Opus 4.

Release Notes:

* Added an element inspector for development. On debug builds,
`dev::ToggleInspector` will open a pane allowing inspecting of element
info and modifying styles.
This commit is contained in:
Michael Sloan 2025-05-26 11:43:57 -06:00 committed by GitHub
parent 6253b95f82
commit 649072d140
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 1778 additions and 316 deletions

View file

@ -221,3 +221,34 @@ mod conditional {
}
}
}
/// Provides definitions used by `#[derive_inspector_reflection]`.
#[cfg(any(feature = "inspector", debug_assertions))]
pub mod inspector_reflection {
use std::any::Any;
/// Reification of a function that has the signature `fn some_fn(T) -> T`. Provides the name,
/// documentation, and ability to invoke the function.
#[derive(Clone, Copy)]
pub struct FunctionReflection<T> {
/// The name of the function
pub name: &'static str,
/// The method
pub function: fn(Box<dyn Any>) -> Box<dyn Any>,
/// Documentation for the function
pub documentation: Option<&'static str>,
/// `PhantomData` for the type of the argument and result
pub _type: std::marker::PhantomData<T>,
}
impl<T: 'static> FunctionReflection<T> {
/// Invoke this method on a value and return the result.
pub fn invoke(&self, value: T) -> T {
let boxed = Box::new(value) as Box<dyn Any>;
let result = (self.function)(boxed);
*result
.downcast::<T>()
.expect("Type mismatch in reflection invoke")
}
}
}