Skip to content

node macro: copy visibility from node function #2782

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

Merged
merged 1 commit into from
Jul 1, 2025
Merged
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
4 changes: 2 additions & 2 deletions node-graph/gstd/src/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn mask(
}

#[node_macro::node(category(""))]
fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<CPU>, bounds: DAffine2) -> RasterDataTable<CPU> {
pub fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<CPU>, bounds: DAffine2) -> RasterDataTable<CPU> {
let mut result_table = RasterDataTable::default();

for mut image_instance in image.instance_iter() {
Expand Down Expand Up @@ -284,7 +284,7 @@ fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<CPU>, bounds: DAff
}

#[node_macro::node(category("Debug: Raster"))]
fn empty_image(_: impl Ctx, transform: DAffine2, color: Color) -> RasterDataTable<CPU> {
pub fn empty_image(_: impl Ctx, transform: DAffine2, color: Color) -> RasterDataTable<CPU> {
let width = transform.transform_vector2(DVec2::new(1., 0.)).length() as u32;
let height = transform.transform_vector2(DVec2::new(0., 1.)).length() as u32;

Expand Down
3 changes: 2 additions & 1 deletion node-graph/node-macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static NODE_ID: AtomicU64 = AtomicU64::new(0);

pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStream2> {
let ParsedNodeFn {
vis,
attributes,
fn_name,
struct_name,
Expand Down Expand Up @@ -345,7 +346,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
/// Underlying implementation for [#struct_name]
#[inline]
#[allow(clippy::too_many_arguments)]
pub(crate) #async_keyword fn #fn_name <'n, #(#fn_generics,)*> (#input_ident: #input_type #(, #field_idents: #field_types)*) -> #output_type #where_clause #body
#vis #async_keyword fn #fn_name <'n, #(#fn_generics,)*> (#input_ident: #input_type #(, #field_idents: #field_types)*) -> #output_type #where_clause #body

#[automatically_derived]
impl<'n, #(#fn_generics,)* #(#struct_generics,)* #(#future_idents,)*> #graphene_core::Node<'n, #input_type> for #mod_name::#struct_name<#(#struct_generics,)*>
Expand Down
14 changes: 12 additions & 2 deletions node-graph/node-macro/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::token::{Comma, RArrow};
use syn::{
AttrStyle, Attribute, Error, Expr, ExprTuple, FnArg, GenericParam, Ident, ItemFn, Lit, LitFloat, LitInt, LitStr, Meta, Pat, PatIdent, PatType, Path, ReturnType, Type, TypeParam, WhereClause,
parse_quote,
AttrStyle, Attribute, Error, Expr, ExprTuple, FnArg, GenericParam, Ident, ItemFn, Lit, LitFloat, LitInt, LitStr, Meta, Pat, PatIdent, PatType, Path, ReturnType, Type, TypeParam, Visibility,
WhereClause, parse_quote,
};

use crate::codegen::generate_node_code;
Expand All @@ -22,6 +22,7 @@ pub(crate) struct Implementation {

#[derive(Debug)]
pub(crate) struct ParsedNodeFn {
pub(crate) vis: Visibility,
pub(crate) attributes: NodeFnAttributes,
pub(crate) fn_name: Ident,
pub(crate) struct_name: Ident,
Expand Down Expand Up @@ -263,6 +264,7 @@ fn parse_node_fn(attr: TokenStream2, item: TokenStream2) -> syn::Result<ParsedNo
let attributes = syn::parse2::<NodeFnAttributes>(attr.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse node_fn attributes: {}", e)))?;
let input_fn = syn::parse2::<ItemFn>(item.clone()).map_err(|e| Error::new(e.span(), format!("Failed to parse function: {}. Make sure it's a valid Rust function.", e)))?;

let vis = input_fn.vis;
let fn_name = input_fn.sig.ident.clone();
let struct_name = format_ident!("{}", fn_name.to_string().to_case(Case::Pascal));
let mod_name = fn_name.clone();
Expand Down Expand Up @@ -297,6 +299,7 @@ fn parse_node_fn(attr: TokenStream2, item: TokenStream2) -> syn::Result<ParsedNo
.fold(String::new(), |acc, b| acc + &b + "\n");

Ok(ParsedNodeFn {
vis,
attributes,
fn_name,
struct_name,
Expand Down Expand Up @@ -748,6 +751,7 @@ mod tests {

let parsed = parse_node_fn(attr, input).unwrap();
let expected = ParsedNodeFn {
vis: Visibility::Inherited,
attributes: NodeFnAttributes {
category: Some(parse_quote!("Math: Arithmetic")),
display_name: None,
Expand Down Expand Up @@ -808,6 +812,7 @@ mod tests {

let parsed = parse_node_fn(attr, input).unwrap();
let expected = ParsedNodeFn {
vis: Visibility::Inherited,
attributes: NodeFnAttributes {
category: Some(parse_quote!("General")),
display_name: None,
Expand Down Expand Up @@ -879,6 +884,7 @@ mod tests {

let parsed = parse_node_fn(attr, input).unwrap();
let expected = ParsedNodeFn {
vis: Visibility::Inherited,
attributes: NodeFnAttributes {
category: Some(parse_quote!("Vector: Shape")),
display_name: None,
Expand Down Expand Up @@ -935,6 +941,7 @@ mod tests {

let parsed = parse_node_fn(attr, input).unwrap();
let expected = ParsedNodeFn {
vis: Visibility::Inherited,
attributes: NodeFnAttributes {
category: Some(parse_quote!("Raster: Adjustment")),
display_name: None,
Expand Down Expand Up @@ -1003,6 +1010,7 @@ mod tests {

let parsed = parse_node_fn(attr, input).unwrap();
let expected = ParsedNodeFn {
vis: Visibility::Inherited,
attributes: NodeFnAttributes {
category: Some(parse_quote!("Math: Arithmetic")),
display_name: None,
Expand Down Expand Up @@ -1059,6 +1067,7 @@ mod tests {

let parsed = parse_node_fn(attr, input).unwrap();
let expected = ParsedNodeFn {
vis: Visibility::Inherited,
attributes: NodeFnAttributes {
category: Some(parse_quote!("IO")),
display_name: None,
Expand Down Expand Up @@ -1115,6 +1124,7 @@ mod tests {

let parsed = parse_node_fn(attr, input).unwrap();
let expected = ParsedNodeFn {
vis: Visibility::Inherited,
attributes: NodeFnAttributes {
category: Some(parse_quote!("Custom")),
display_name: Some(parse_quote!("CustomNode2")),
Expand Down
Loading