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
|
@ -6,6 +6,9 @@ mod register_action;
|
|||
mod styles;
|
||||
mod test;
|
||||
|
||||
#[cfg(any(feature = "inspector", debug_assertions))]
|
||||
mod derive_inspector_reflection;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use syn::{DeriveInput, Ident};
|
||||
|
||||
|
@ -178,6 +181,28 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
|||
test::test(args, function)
|
||||
}
|
||||
|
||||
/// When added to a trait, `#[derive_inspector_reflection]` generates a module which provides
|
||||
/// enumeration and lookup by name of all methods that have the shape `fn method(self) -> Self`.
|
||||
/// This is used by the inspector so that it can use the builder methods in `Styled` and
|
||||
/// `StyledExt`.
|
||||
///
|
||||
/// The generated module will have the name `<snake_case_trait_name>_reflection` and contain the
|
||||
/// following functions:
|
||||
///
|
||||
/// ```ignore
|
||||
/// pub fn methods::<T: TheTrait + 'static>() -> Vec<gpui::inspector_reflection::FunctionReflection<T>>;
|
||||
///
|
||||
/// pub fn find_method::<T: TheTrait + 'static>() -> Option<gpui::inspector_reflection::FunctionReflection<T>>;
|
||||
/// ```
|
||||
///
|
||||
/// The `invoke` method on `FunctionReflection` will run the method. `FunctionReflection` also
|
||||
/// provides the method's documentation.
|
||||
#[cfg(any(feature = "inspector", debug_assertions))]
|
||||
#[proc_macro_attribute]
|
||||
pub fn derive_inspector_reflection(_args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
derive_inspector_reflection::derive_inspector_reflection(_args, input)
|
||||
}
|
||||
|
||||
pub(crate) fn get_simple_attribute_field(ast: &DeriveInput, name: &'static str) -> Option<Ident> {
|
||||
match &ast.data {
|
||||
syn::Data::Struct(data_struct) => data_struct
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue