Skip to main content

component_shape_gpui_macros/
lib.rs

1mod derives;
2
3use proc_macro::TokenStream;
4
5/// Derive macro for GPUI component shape metadata.
6///
7/// When `#[gpui_component_shape(...)]` is present, `state = ...` may be omitted
8/// if the backing state follows the `ComponentState` naming convention. By
9/// default the derive calls `<State>::new(window, cx)`. Override the constructor
10/// with `new = ...`, a closure, or a direct constructor expression.
11///
12/// `value = ...` or `values(...)` publish exact supported value types. For
13/// `value_binding` shapes, value compatibility may also be inferred from
14/// `State: GpuiComponentStateValueBinding<T>`.
15///
16/// Common MCP input metadata is inferred from declared value metadata when the
17/// shape has unambiguous string, boolean, numeric, date, date-time, array, set,
18/// range, object-map, or unconstrained JSON value shapes. Each generated
19/// `ComponentShapeFor<Value>` impl carries the value-specific metadata; the
20/// shape-level metadata is emitted only when all declared values agree. Use
21/// `mcp_input = string`, `mcp_input = object`, or another `McpInput` expression
22/// when a generic or custom shape knows its model-facing MCP input better than
23/// the value type can be inferred.
24#[proc_macro_derive(GpuiComponentShape, attributes(gpui_component_shape))]
25pub fn derive_gpui_component_shape(input: TokenStream) -> TokenStream {
26    derives::component_shape_state::from(input)
27}
28
29/// Function-like macro for declaring a local GPUI component shape around
30/// external component/state types.
31///
32/// The backing state may be declared as `type State = ...;` or `state = ...;`.
33/// When no explicit `value = ...` or `values(...)` metadata is present, a
34/// nested `GpuiComponentValueBinding<T>` impl publishes `T` as a supported value
35/// and enables value-binding metadata.
36///
37/// Common MCP input metadata is inferred from declared value metadata when the
38/// shape has unambiguous string, boolean, numeric, date, date-time, array, set,
39/// range, object-map, or unconstrained JSON value shapes. Each generated
40/// `ComponentShapeFor<Value>` impl carries the value-specific metadata; the
41/// shape-level metadata is emitted only when all declared values agree. Use
42/// `mcp_input = string`, `mcp_input = object`, or another `McpInput` expression
43/// when a generic or custom shape knows its model-facing MCP input better than
44/// the value type can be inferred.
45#[proc_macro]
46pub fn component_shape(input: TokenStream) -> TokenStream {
47    derives::component_shape::function(input)
48}