Skip to content
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

C#: Add [ScriptMethodExclude]. An attribute that excluding method generation from source generators #90687

Open
wants to merge 2 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ public static bool IsGodotGlobalClassAttribute(this INamedTypeSymbol symbol)
public static bool IsSystemFlagsAttribute(this INamedTypeSymbol symbol)
=> symbol.FullQualifiedNameOmitGlobal() == GodotClasses.SystemFlagsAttr;

public static bool IsGodotScriptMethodExcludeAttribute(this INamedTypeSymbol symbol)
=> symbol.FullQualifiedNameOmitGlobal() == GodotClasses.ScriptMethodExcludeAttr;

public static GodotMethodData? HasGodotCompatibleSignature(
this IMethodSymbol method,
MarshalUtils.TypeCache typeCache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public static class GodotClasses
public const string GodotClassNameAttr = "Godot.GodotClassNameAttribute";
public const string GlobalClassAttr = "Godot.GlobalClassAttribute";
public const string SystemFlagsAttr = "System.FlagsAttribute";
public const string ScriptMethodExcludeAttr = "Godot.ScriptMethodExcludeAttribute";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
var methodSymbols = members
.Where(s => s.Kind == SymbolKind.Method && !s.IsImplicitlyDeclared)
.Cast<IMethodSymbol>()
.Where(m => !m.GetAttributes()
.Any(a => a.AttributeClass?.IsGodotScriptMethodExcludeAttribute() ?? false)
)
.Where(m => m.MethodKind == MethodKind.Ordinary);

var godotClassMethods = methodSymbols.WhereHasGodotCompatibleSignature(typeCache)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Godot
{
/// <summary>
/// An attribute that excluding method generation from source generators
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class ScriptMethodExcludeAttribute : Attribute { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="Core\Attributes\ScriptPathAttribute.cs" />
<Compile Include="Core\Attributes\SignalAttribute.cs" />
<Compile Include="Core\Attributes\ToolAttribute.cs" />
<Compile Include="Core\Attributes\ScriptMethodExcludeAttribute.cs" />
<Compile Include="Core\Basis.cs" />
<Compile Include="Core\Bridge\CSharpInstanceBridge.cs" />
<Compile Include="Core\Bridge\GCHandleBridge.cs" />
Expand Down