Skip to content

Require that classes starting with "Editor" be marked internal #1272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions godot-macros/src/class/derive_godot_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,15 @@ fn parse_struct_attributes(class: &venial::Struct) -> ParseResult<ClassAttribute
if let Some(span) = parser.handle_alone_with_span("internal")? {
require_api_version!("4.2", span, "#[class(internal)]")?;
is_internal = true;
} else {
// Godot has an edge case where classes starting with "Editor" are implicitly hidden:
// https://github.com/godotengine/godot/blob/ca452113d430cb96de409a297ff5b52389f1c9d9/editor/gui/create_dialog.cpp#L171-L173
if class.name.to_string().starts_with("Editor") {
return bail!(
class.name.span(),
"Classes starting with `Editor` are implicitly hidden by Godot; use #[class(internal)] to make this explicit",
);
}
}

// Deprecated #[class(hidden)]
Expand Down
7 changes: 5 additions & 2 deletions godot-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ use crate::util::{bail, ident, KvParser};
///
/// ## Class hiding
///
/// If you want to register a class with Godot, but not have it show up in the editor then you can use `#[class(internal)]`.
/// If you want to register a class with Godot, but not display in the editor (e.g. when creating a new node), you can use `#[class(internal)]`.
///
/// Classes starting with "Editor" are auto-hidden by Godot. They *must* be marked as internal in godot-rust.
///
/// ```
/// # use godot::prelude::*;
Expand Down Expand Up @@ -540,7 +542,8 @@ use crate::util::{bail, ident, KvParser};
alias = "var",
alias = "export",
alias = "tool",
alias = "rename"
alias = "rename",
alias = "internal"
)]
#[proc_macro_derive(
GodotClass,
Expand Down
Loading