Skip to content

Commit b294779

Browse files
bors[bot]Stephan Dilly
andauthored
Merge #674
674: support no editor properties r=toasteater a=extrawurst fixes #673 Co-authored-by: Stephan Dilly <[email protected]>
2 parents bec872c + 5133030 commit b294779

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

gdnative-derive/src/native_script.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ pub(crate) fn derive_native_class(derive_input: &DeriveInput) -> Result<TokenStr
6060
None
6161
};
6262

63+
let with_usage = if config.no_editor {
64+
Some(quote!(.with_usage(::gdnative::nativescript::init::property::Usage::NOEDITOR)))
65+
} else {
66+
None
67+
};
68+
6369
let before_get: Option<Stmt> = config
6470
.before_get
6571
.map(|path_expr| parse_quote!(#path_expr(this, _owner);));
@@ -81,6 +87,7 @@ pub(crate) fn derive_native_class(derive_input: &DeriveInput) -> Result<TokenStr
8187
builder.add_property(#label)
8288
#with_default
8389
#with_hint
90+
#with_usage
8491
.with_ref_getter(|this: &#name, _owner: ::gdnative::TRef<Self::Base>| {
8592
#before_get
8693
let res = &this.#ident;
@@ -202,6 +209,8 @@ fn parse_derive_input(input: &DeriveInput) -> Result<DeriveData, syn::Error> {
202209
for arg in &nested {
203210
if let NestedMeta::Meta(Meta::NameValue(ref pair)) = arg {
204211
attr_args_builder.add_pair(pair)?;
212+
} else if let NestedMeta::Meta(Meta::Path(ref path)) = arg {
213+
attr_args_builder.add_path(path)?;
205214
} else {
206215
let msg = format!("Unexpected argument: {:?}", arg);
207216
return Err(syn::Error::new(arg.span(), msg));
@@ -292,4 +301,21 @@ mod tests {
292301

293302
parse_derive_input(&input).unwrap();
294303
}
304+
305+
#[test]
306+
fn derive_property_no_editor() {
307+
let input: TokenStream2 = syn::parse_str(
308+
r#"
309+
#[inherit(Node)]
310+
struct Foo {
311+
#[property(no_editor)]
312+
bar: String,
313+
}"#,
314+
)
315+
.unwrap();
316+
317+
let input: DeriveInput = syn::parse2(input).unwrap();
318+
319+
parse_derive_input(&input).unwrap();
320+
}
295321
}

gdnative-derive/src/native_script/property_args.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct PropertyAttrArgs {
88
pub after_get: Option<syn::Path>,
99
pub before_set: Option<syn::Path>,
1010
pub after_set: Option<syn::Path>,
11+
pub no_editor: bool,
1112
}
1213

1314
#[derive(Default)]
@@ -19,6 +20,7 @@ pub struct PropertyAttrArgsBuilder {
1920
after_get: Option<syn::Path>,
2021
before_set: Option<syn::Path>,
2122
after_set: Option<syn::Path>,
23+
no_editor: bool,
2224
}
2325

2426
impl PropertyAttrArgsBuilder {
@@ -167,6 +169,19 @@ impl PropertyAttrArgsBuilder {
167169

168170
Ok(())
169171
}
172+
173+
pub fn add_path(&mut self, path: &syn::Path) -> Result<(), syn::Error> {
174+
if path.is_ident("no_editor") {
175+
self.no_editor = true;
176+
} else {
177+
return Err(syn::Error::new(
178+
path.span(),
179+
format!("unexpected argument: {:?}", path.get_ident()),
180+
));
181+
}
182+
183+
Ok(())
184+
}
170185
}
171186

172187
impl PropertyAttrArgsBuilder {
@@ -179,6 +194,7 @@ impl PropertyAttrArgsBuilder {
179194
after_get: self.after_get,
180195
before_set: self.before_set,
181196
after_set: self.after_set,
197+
no_editor: self.no_editor,
182198
}
183199
}
184200
}

0 commit comments

Comments
 (0)