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:
parent
6253b95f82
commit
649072d140
35 changed files with 1778 additions and 316 deletions
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue