Skip to content

Commit e3c6335

Browse files
committed
Deprecate #[class(editor_plugin)]; implied by #[class(base=EditorPlugin)]
1 parent 0c91b8a commit e3c6335

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

godot-core/src/deprecated.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub use crate::emit_deprecated_warning;
4141
More information on https://github.com/godot-rust/gdext/pull/844."]
4242
pub const fn init_default() {}
4343

44+
#[deprecated = "\nThe attribute key #[class(editor_plugin)] is now implied by #[class(base = EditorPlugin)]. It is ignored.\n\
45+
More information on https://github.com/godot-rust/gdext/pull/884."]
46+
pub const fn editor_plugin() {}
47+
4448
// ----------------------------------------------------------------------------------------------------------------------------------------------
4549
// Godot-side deprecations
4650

godot-macros/src/class/derive_godot_class.rs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ pub fn derive_godot_class(item: venial::Item) -> ParseResult<TokenStream> {
2121
.ok_or_else(|| venial::Error::new("Not a valid struct"))?;
2222

2323
let named_fields = named_fields(class)?;
24-
let struct_cfg = parse_struct_attributes(class)?;
25-
let fields = parse_fields(named_fields, struct_cfg.init_strategy)?;
24+
let mut struct_cfg = parse_struct_attributes(class)?;
25+
let mut fields = parse_fields(named_fields, struct_cfg.init_strategy)?;
26+
let is_editor_plugin = struct_cfg.is_editor_plugin();
27+
28+
let mut deprecations = std::mem::take(&mut struct_cfg.deprecations);
29+
deprecations.extend(fields.deprecations.drain(..));
2630

2731
let class_name = &class.name;
2832
let class_name_str: String = struct_cfg
@@ -33,7 +37,6 @@ pub fn derive_godot_class(item: venial::Item) -> ParseResult<TokenStream> {
3337
let class_name_cstr = util::c_str(&class_name_str);
3438
let class_name_obj = util::class_name_obj(class_name);
3539

36-
let is_editor_plugin = struct_cfg.is_editor_plugin;
3740
let is_hidden = struct_cfg.is_hidden;
3841
let base_ty = &struct_cfg.base_ty;
3942
#[cfg(all(feature = "docs", since_api = "4.3"))]
@@ -75,7 +78,6 @@ pub fn derive_godot_class(item: venial::Item) -> ParseResult<TokenStream> {
7578
let mut create_fn = quote! { None };
7679
let mut recreate_fn = quote! { None };
7780
let mut is_instantiable = true;
78-
let deprecations = &fields.deprecations;
7981

8082
match struct_cfg.init_strategy {
8183
InitStrategy::Generated => {
@@ -201,9 +203,15 @@ struct ClassAttributes {
201203
base_ty: Ident,
202204
init_strategy: InitStrategy,
203205
is_tool: bool,
204-
is_editor_plugin: bool,
205206
is_hidden: bool,
206207
rename: Option<Ident>,
208+
deprecations: Vec<TokenStream>,
209+
}
210+
211+
impl ClassAttributes {
212+
fn is_editor_plugin(&self) -> bool {
213+
self.base_ty == ident("EditorPlugin")
214+
}
207215
}
208216

209217
fn make_godot_init_impl(class_name: &Ident, fields: &Fields) -> TokenStream {
@@ -310,9 +318,9 @@ fn parse_struct_attributes(class: &venial::Struct) -> ParseResult<ClassAttribute
310318
let mut base_ty = ident("RefCounted");
311319
let mut init_strategy = InitStrategy::UserDefined;
312320
let mut is_tool = false;
313-
let mut is_editor_plugin = false;
314321
let mut is_hidden = false;
315322
let mut rename: Option<Ident> = None;
323+
let mut deprecations = vec![];
316324

317325
// #[class] attribute on struct
318326
if let Some(mut parser) = KvParser::parse(&class.attributes, "class")? {
@@ -334,24 +342,10 @@ fn parse_struct_attributes(class: &venial::Struct) -> ParseResult<ClassAttribute
334342
}
335343

336344
// #[class(editor_plugin)]
337-
if let Some(attr_key) = parser.handle_alone_with_span("editor_plugin")? {
338-
is_editor_plugin = true;
339-
340-
// Requires #[class(tool, base=EditorPlugin)].
341-
// The base=EditorPlugin check should come first to create the best compile errors since it's more complex to resolve.
342-
// See https://github.com/godot-rust/gdext/pull/773
343-
if base_ty != ident("EditorPlugin") {
344-
return bail!(
345-
attr_key,
346-
"#[class(editor_plugin)] requires additional key-value `base=EditorPlugin`"
347-
);
348-
}
349-
if !is_tool {
350-
return bail!(
351-
attr_key,
352-
"#[class(editor_plugin)] requires additional key `tool`"
353-
);
354-
}
345+
if let Some(_attr_key) = parser.handle_alone_with_span("editor_plugin")? {
346+
deprecations.push(quote! {
347+
::godot::__deprecated::emit_deprecated_warning!(editor_plugin);
348+
});
355349
}
356350

357351
// #[class(rename = NewName)]
@@ -368,15 +362,15 @@ fn parse_struct_attributes(class: &venial::Struct) -> ParseResult<ClassAttribute
368362
parser.finish()?;
369363
}
370364

371-
post_validate(&base_ty, is_tool, is_editor_plugin)?;
365+
post_validate(&base_ty, is_tool)?;
372366

373367
Ok(ClassAttributes {
374368
base_ty,
375369
init_strategy,
376370
is_tool,
377-
is_editor_plugin,
378371
is_hidden,
379372
rename,
373+
deprecations,
380374
})
381375
}
382376

@@ -561,7 +555,7 @@ fn handle_opposite_keys(
561555
}
562556

563557
/// Checks more logical combinations of attributes.
564-
fn post_validate(base_ty: &Ident, is_tool: bool, is_editor_plugin: bool) -> ParseResult<()> {
558+
fn post_validate(base_ty: &Ident, is_tool: bool) -> ParseResult<()> {
565559
// TODO: this should be delegated to either:
566560
// a) the type system: have a trait IsTool which is implemented when #[class(tool)] is set.
567561
// Then, for certain base classes, require a tool bound (e.g. generate method `fn type_check<T: IsTool>()`).
@@ -579,12 +573,6 @@ fn post_validate(base_ty: &Ident, is_tool: bool, is_editor_plugin: bool) -> Pars
579573
"Base class `{}` is a virtual extension class, which runs in the editor and thus requires #[class(tool)].",
580574
base_ty
581575
);
582-
} else if class_name == "EditorPlugin" && !is_editor_plugin {
583-
return bail!(
584-
base_ty,
585-
"Classes extending `{}` require #[class(editor_plugin)] to get registered as a plugin in the editor. See: https://godot-rust.github.io/book/recipes/editor-plugin/index.html",
586-
base_ty
587-
);
588576
} else if is_class_editor && !is_tool {
589577
return bail!(
590578
base_ty,

itest/rust/src/object_tests/virtual_methods_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ impl GetSetTest {
779779
// There isn't a good way to test editor plugins, but we can at least declare one to ensure that the macro
780780
// compiles.
781781
#[derive(GodotClass)]
782-
#[class(no_init, base = EditorPlugin, editor_plugin, tool)]
782+
#[class(no_init, base = EditorPlugin, tool)]
783783
struct CustomEditorPlugin;
784784

785785
// Just override EditorPlugin::edit() to verify method is declared with Option<T>.

0 commit comments

Comments
 (0)