diff options
Diffstat (limited to 'modules/mono')
6 files changed, 125 insertions, 68 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs index 5fb29b86da..22a21a1754 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs @@ -111,15 +111,16 @@ namespace Godot.SourceGenerators ClassIsEnum = 65536, NilIsVariant = 131072, Array = 262144, - DoNotShareOnDuplicate = 524288, - HighEndGfx = 1048576, - NodePathFromSceneRoot = 2097152, - ResourceNotPersistent = 4194304, - KeyingIncrements = 8388608, - DeferredSetResource = 16777216, - EditorInstantiateObject = 33554432, - EditorBasicSetting = 67108864, - ReadOnly = 134217728, + AlwaysDuplicate = 524288, + NeverDuplicate = 1048576, + HighEndGfx = 2097152, + NodePathFromSceneRoot = 4194304, + ResourceNotPersistent = 8388608, + KeyingIncrements = 16777216, + DeferredSetResource = 33554432, + EditorInstantiateObject = 67108864, + EditorBasicSetting = 134217728, + ReadOnly = 268435456, Default = 6, NoEditor = 2 } diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs index 98ca534c66..2a9758516c 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs @@ -26,6 +26,10 @@ namespace Godot.SourceGenerators private void AnalyzeNode(SyntaxNodeAnalysisContext context) { + // Ignore syntax inside comments + if (IsInsideDocumentation(context.Node)) + return; + var typeArgListSyntax = (TypeArgumentListSyntax)context.Node; // Method invocation or variable declaration that contained the type arguments @@ -74,6 +78,26 @@ namespace Godot.SourceGenerators } /// <summary> + /// Check if the syntax node is inside a documentation syntax. + /// </summary> + /// <param name="syntax">Syntax node to check.</param> + /// <returns><see langword="true"/> if the syntax node is inside a documentation syntax.</returns> + private bool IsInsideDocumentation(SyntaxNode? syntax) + { + while (syntax != null) + { + if (syntax is DocumentationCommentTriviaSyntax) + { + return true; + } + + syntax = syntax.Parent; + } + + return false; + } + + /// <summary> /// Check if the given type argument is being used in a type parameter that contains /// the <c>MustBeVariantAttribute</c>; otherwise, we ignore the attribute. /// </summary> diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 03cbfda1bd..5c4abe30e4 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -229,6 +229,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf List<String> tag_stack; bool code_tag = false; + bool line_del = false; int pos = 0; while (pos < bbcode.length()) { @@ -239,20 +240,22 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf } if (brk_pos > pos) { - String text = bbcode.substr(pos, brk_pos - pos); - if (code_tag || tag_stack.size() > 0) { - xml_output.append(text.xml_escape()); - } else { - Vector<String> lines = text.split("\n"); - for (int i = 0; i < lines.size(); i++) { - if (i != 0) { - xml_output.append("<para>"); - } + if (!line_del) { + String text = bbcode.substr(pos, brk_pos - pos); + if (code_tag || tag_stack.size() > 0) { + xml_output.append(text.xml_escape()); + } else { + Vector<String> lines = text.split("\n"); + for (int i = 0; i < lines.size(); i++) { + if (i != 0) { + xml_output.append("<para>"); + } - xml_output.append(lines[i].xml_escape()); + xml_output.append(lines[i].xml_escape()); - if (i != lines.size() - 1) { - xml_output.append("</para>\n"); + if (i != lines.size() - 1) { + xml_output.append("</para>\n"); + } } } } @@ -265,20 +268,22 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf int brk_end = bbcode.find("]", brk_pos + 1); if (brk_end == -1) { - String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos); - if (code_tag || tag_stack.size() > 0) { - xml_output.append(text.xml_escape()); - } else { - Vector<String> lines = text.split("\n"); - for (int i = 0; i < lines.size(); i++) { - if (i != 0) { - xml_output.append("<para>"); - } + if (!line_del) { + String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos); + if (code_tag || tag_stack.size() > 0) { + xml_output.append(text.xml_escape()); + } else { + Vector<String> lines = text.split("\n"); + for (int i = 0; i < lines.size(); i++) { + if (i != 0) { + xml_output.append("<para>"); + } - xml_output.append(lines[i].xml_escape()); + xml_output.append(lines[i].xml_escape()); - if (i != lines.size() - 1) { - xml_output.append("</para>\n"); + if (i != lines.size() - 1) { + xml_output.append("</para>\n"); + } } } } @@ -292,7 +297,9 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length()); if (!tag_ok) { - xml_output.append("["); + if (!line_del) { + xml_output.append("["); + } pos = brk_pos + 1; continue; } @@ -307,11 +314,20 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append("</c>"); } else if (tag == "/codeblock") { xml_output.append("</code>"); + } else if (tag == "/b") { + xml_output.append("</b>"); + } else if (tag == "/i") { + xml_output.append("</i>"); + } else if (tag == "/csharp") { + xml_output.append("</code>"); + line_del = true; + } else if (tag == "/codeblocks") { + line_del = false; } } else if (code_tag) { xml_output.append("["); pos = brk_pos + 1; - } else if (tag.begins_with("method ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ") || tag.begins_with("constant ") || tag.begins_with("theme_item ")) { + } else if (tag.begins_with("method ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ") || tag.begins_with("constant ") || tag.begins_with("theme_item ") || tag.begins_with("param ")) { const int tag_end = tag.find(" "); const String link_tag = tag.substr(0, tag_end); const String link_target = tag.substr(tag_end + 1, tag.length()).lstrip(" "); @@ -356,6 +372,8 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf } else if (link_tag == "theme_item") { // We do not declare theme_items in any way in C#, so there is nothing to reference _append_xml_undeclared(xml_output, link_target); + } else if (link_tag == "param") { + _append_xml_undeclared(xml_output, snake_to_camel_case(link_target, false)); } pos = brk_end + 1; @@ -377,8 +395,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf #endif "\"/>"); } else if (tag == "Variant") { - // We use System.Object for Variant, so there is no Variant type in C# - xml_output.append("<c>Variant</c>"); + xml_output.append("<see cref=\"Godot.Variant\"/>"); } else if (tag == "String") { xml_output.append("<see cref=\"string\"/>"); } else if (tag == "Nil") { @@ -428,11 +445,13 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf pos = brk_end + 1; } else if (tag == "b") { - // bold is not supported in xml comments + xml_output.append("<b>"); + pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "i") { - // italics is not supported in xml comments + xml_output.append("<i>"); + pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "code") { @@ -447,6 +466,17 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf code_tag = true; pos = brk_end + 1; tag_stack.push_front(tag); + } else if (tag == "codeblocks") { + line_del = true; + pos = brk_end + 1; + tag_stack.push_front(tag); + } else if (tag == "csharp") { + xml_output.append("<code>"); + + line_del = false; + code_tag = true; + pos = brk_end + 1; + tag_stack.push_front(tag); } else if (tag == "kbd") { // keyboard combinations are not supported in xml comments pos = brk_end + 1; @@ -459,7 +489,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append("\n"); // FIXME: Should use <para> instead. Luckily this tag isn't used for now. pos = brk_end + 1; } else if (tag == "u") { - // underline is not supported in xml comments + // underline is not supported in Rider xml comments pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "s") { @@ -510,7 +540,9 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf pos = brk_end + 1; tag_stack.push_front("font"); } else { - xml_output.append("["); // ignore + if (!line_del) { + xml_output.append("["); // ignore + } pos = brk_pos + 1; } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.generics.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.generics.cs index ff385da1c9..3005582bea 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.generics.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.generics.cs @@ -45,7 +45,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0>( + public static unsafe Callable From<[MustBeVariant] T0>( Action<T0> action ) { @@ -64,7 +64,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1>( Action<T0, T1> action ) { @@ -84,7 +84,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1, T2>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2>( Action<T0, T1, T2> action ) { @@ -105,7 +105,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1, T2, T3>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3>( Action<T0, T1, T2, T3> action ) { @@ -127,7 +127,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1, T2, T3, T4>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4>( Action<T0, T1, T2, T3, T4> action ) { @@ -150,7 +150,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5>( Action<T0, T1, T2, T3, T4, T5> action ) { @@ -174,7 +174,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5, T6>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5, [MustBeVariant] T6>( Action<T0, T1, T2, T3, T4, T5, T6> action ) { @@ -199,7 +199,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5, T6, T7>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5, [MustBeVariant] T6, [MustBeVariant] T7>( Action<T0, T1, T2, T3, T4, T5, T6, T7> action ) { @@ -225,7 +225,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From(Action)"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5, T6, T7, T8>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5, [MustBeVariant] T6, [MustBeVariant] T7, [MustBeVariant] T8>( Action<T0, T1, T2, T3, T4, T5, T6, T7, T8> action ) { @@ -255,7 +255,7 @@ public readonly partial struct Callable /// Constructs a new <see cref="Callable"/> for the given <paramref name="func"/>. /// </summary> /// <param name="func">Action method that will be called.</param> - public static unsafe Callable From<TResult>( + public static unsafe Callable From<[MustBeVariant] TResult>( Func<TResult> func ) { @@ -272,7 +272,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] TResult>( Func<T0, TResult> func ) { @@ -291,7 +291,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] TResult>( Func<T0, T1, TResult> func ) { @@ -311,7 +311,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, T2, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] TResult>( Func<T0, T1, T2, TResult> func ) { @@ -332,7 +332,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, T2, T3, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] TResult>( Func<T0, T1, T2, T3, TResult> func ) { @@ -354,7 +354,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] TResult>( Func<T0, T1, T2, T3, T4, TResult> func ) { @@ -377,7 +377,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5, [MustBeVariant] TResult>( Func<T0, T1, T2, T3, T4, T5, TResult> func ) { @@ -401,7 +401,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5, T6, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5, [MustBeVariant] T6, [MustBeVariant] TResult>( Func<T0, T1, T2, T3, T4, T5, T6, TResult> func ) { @@ -426,7 +426,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5, T6, T7, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5, [MustBeVariant] T6, [MustBeVariant] T7, [MustBeVariant] TResult>( Func<T0, T1, T2, T3, T4, T5, T6, T7, TResult> func ) { @@ -452,7 +452,7 @@ public readonly partial struct Callable } /// <inheritdoc cref="From{TResult}(Func{TResult})"/> - public static unsafe Callable From<T0, T1, T2, T3, T4, T5, T6, T7, T8, TResult>( + public static unsafe Callable From<[MustBeVariant] T0, [MustBeVariant] T1, [MustBeVariant] T2, [MustBeVariant] T3, [MustBeVariant] T4, [MustBeVariant] T5, [MustBeVariant] T6, [MustBeVariant] T7, [MustBeVariant] T8, [MustBeVariant] TResult>( Func<T0, T1, T2, T3, T4, T5, T6, T7, T8, TResult> func ) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs index 9c9258dd9e..bb306ddaea 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs @@ -260,7 +260,7 @@ namespace Godot.NativeInterop => from != null ? CreateFromArray((godot_array)from.NativeValue) : default; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static godot_variant CreateFromArray<T>(Array<T>? from) + public static godot_variant CreateFromArray<[MustBeVariant] T>(Array<T>? from) => from != null ? CreateFromArray((godot_array)((Collections.Array)from).NativeValue) : default; public static godot_variant CreateFromDictionary(godot_dictionary from) @@ -274,7 +274,7 @@ namespace Godot.NativeInterop => from != null ? CreateFromDictionary((godot_dictionary)from.NativeValue) : default; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static godot_variant CreateFromDictionary<TKey, TValue>(Dictionary<TKey, TValue>? from) + public static godot_variant CreateFromDictionary<[MustBeVariant] TKey, [MustBeVariant] TValue>(Dictionary<TKey, TValue>? from) => from != null ? CreateFromDictionary((godot_dictionary)((Dictionary)from).NativeValue) : default; public static godot_variant CreateFromStringName(godot_string_name from) @@ -526,7 +526,7 @@ namespace Godot.NativeInterop => Collections.Array.CreateTakingOwnershipOfDisposableValue(ConvertToNativeArray(p_var)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Array<T> ConvertToArray<T>(in godot_variant p_var) + public static Array<T> ConvertToArray<[MustBeVariant] T>(in godot_variant p_var) => Array<T>.CreateTakingOwnershipOfDisposableValue(ConvertToNativeArray(p_var)); public static godot_dictionary ConvertToNativeDictionary(in godot_variant p_var) @@ -539,7 +539,7 @@ namespace Godot.NativeInterop => Dictionary.CreateTakingOwnershipOfDisposableValue(ConvertToNativeDictionary(p_var)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary<TKey, TValue> ConvertToDictionary<TKey, TValue>(in godot_variant p_var) + public static Dictionary<TKey, TValue> ConvertToDictionary<[MustBeVariant] TKey, [MustBeVariant] TValue>(in godot_variant p_var) => Dictionary<TKey, TValue>.CreateTakingOwnershipOfDisposableValue(ConvertToNativeDictionary(p_var)); public static byte[] ConvertAsPackedByteArrayToSystemArray(in godot_variant p_var) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs index da12309217..0ac2e2969c 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs @@ -328,11 +328,11 @@ public partial struct Variant : IDisposable VariantUtils.ConvertToSystemArrayOfGodotObject<T>((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Collections.Dictionary<TKey, TValue> AsGodotDictionary<TKey, TValue>() => + public Collections.Dictionary<TKey, TValue> AsGodotDictionary<[MustBeVariant] TKey, [MustBeVariant] TValue>() => VariantUtils.ConvertToDictionary<TKey, TValue>((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Collections.Array<T> AsGodotArray<T>() => + public Collections.Array<T> AsGodotArray<[MustBeVariant] T>() => VariantUtils.ConvertToArray<T>((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -647,11 +647,11 @@ public partial struct Variant : IDisposable public static Variant CreateFrom(Godot.Object[] from) => from; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Variant CreateFrom<TKey, TValue>(Collections.Dictionary<TKey, TValue> from) => + public static Variant CreateFrom<[MustBeVariant] TKey, [MustBeVariant] TValue>(Collections.Dictionary<TKey, TValue> from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromDictionary(from)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Variant CreateFrom<T>(Collections.Array<T> from) => + public static Variant CreateFrom<[MustBeVariant] T>(Collections.Array<T> from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromArray(from)); [MethodImpl(MethodImplOptions.AggressiveInlining)] |