-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Add C# source generator for ScriptPathAttribute #46713
Add C# source generator for ScriptPathAttribute #46713
Conversation
a999c21
to
8541f75
Compare
NOTE: We use I found no problems with VSCode's C# (OmniSharp) extension. |
b2eb9fd
to
d0d86d6
Compare
To fix the clang-format issues, you likely need to update your local version to clang-format 11 (they changed the logic for alignment of ternary operators in that version, going from "bad" to "still bad but different"...). |
d0d86d6
to
b647eff
Compare
I don't get it, I have the black format precommit hook (version is the same as in the CI)... |
Try to run it manually with |
This source generator adds a newly introduced attribute, `ScriptPath` to all classes that: - Are top-level classes (not inner/nested). - Have the `partial` modifier. - Inherit `Godot.Object`. - The class name matches the file name. A build error is thrown if the generator finds a class that meets these conditions but is not declared `partial`, unless the class is annotated with the `DisableGodotGenerators` attribute. We also generate an `AssemblyHasScripts` assembly attribute which Godot uses to get all the script classes in the assembly, eliminating the need for Godot to search them. We can also avoid searching in assemblies that don't have this attribute. This will be good for performance in the future once we support multiple assemblies with Godot script classes. This is an example of what the generated code looks like: ``` using Godot; namespace Foo { [ScriptPathAttribute("res://Player.cs")] // Multiple partial declarations are allowed [ScriptPathAttribute("res://Foo/Player.cs")] partial class Player {} } [assembly:AssemblyHasScripts(new System.Type[] { typeof(Foo.Player) })] ``` The new attributes replace script metadata which we were generating by determining the namespace of script classes with a very simple parser. This fixes several issues with the old approach related to parser errors and conditional compilation. It also makes the task part of the MSBuild project build, rather than a separate step executed by the Godot editor.
b647eff
to
e2afe70
Compare
Thanks, that did it.
I was suspicious of |
<PackageVersion_Godot_NET_Sdk>4.0.0-dev4</PackageVersion_Godot_NET_Sdk> | ||
<PackageVersion_Godot_SourceGenerators>4.0.0-dev1</PackageVersion_Godot_SourceGenerators> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended to have version 4.0.0-dev4
instead of 4.0.0-dev1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since these are the versions of each package, dev1 to dev3 have already been used. It does seem a bit strange that they're out of sync, so maybe the source generators package should just start at 4.0.0-dev4
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For stable releases they should be the same version, but during development there will be new additions to the source generator while the Sdk may remain the same. Technically we can release an unchanged new version of the Sdk to keep the version in sync with the other package, but that doesn't feel right. The only case where that would be appropriate is when going from rc to stable without changes in the packages.
Thanks! |
since 4.0, `partial` has been requied for the the subclasses of `Godot.Object`. For more information, refer to godotengine/godot#46713
since 4.0, `partial` has been requied for the the subclasses of `Godot.Object`. For more information, refer to godotengine/godot#46713
This source generator adds a newly introduced attribute,
ScriptPath
to all classes that:partial
modifier.Godot.Object
.A build error is thrown if the generator finds a class that meets these conditions but is not declared
partial
, unless the class is annotated with theDisableGodotGenerators
attribute.We also generate an
AssemblyHasScripts
assembly attribute which Godot uses to get all the script classes in the assembly, eliminating the need for Godot to search them. We can also avoid searching in assemblies that don't have this attribute. This will be good for performance in the future once we support multiple assemblies with Godot script classes.This is an example of what the generated code looks like:
The new attributes replace script metadata which we were generating by determining the namespace of script classes with a very simple parser.
This fixes several issues with the old approach related to parser errors and conditional compilation.
It also makes the task part of the MSBuild project build, rather than a separate step executed by the Godot editor.