Commit Graph

43 Commits

Author SHA1 Message Date
f192430921 Fix source generator exceptions appearing when use "@+internal keyword" as type or namespace name in C# script 2025-08-09 13:25:54 +08:00
f4094b554d [.NET] Disallow [ExportToolButton] on members thay may store the Callable
Ensures the user doesn't store the Callable so the .NET assembly can be reloaded.
2025-02-14 01:09:59 +01:00
4e5080d805 [.NET] Preserve no-hint behavior for unmarshallable generics in dictionaries 2024-11-21 20:38:55 +01:00
ec7fd4f6f1 Merge pull request #97894 from paulloz/dotnet/export-tool-button
Implement `[ExportToolButton]`
2024-11-19 15:20:07 -06:00
4f52c2bb1f Implement [ExportToolButton] 2024-11-18 20:19:47 +01:00
186f35fc9b remove duplicate read/write only property warning from ScriptPropertiesGenerator 2024-11-13 14:23:53 -08:00
e3790de461 Fix exported typed dictionaries in .NET having an incorrect hint, which led to incorrect scene serialization 2024-10-18 00:55:24 -03:00
9853a69144 Implement typed dictionaries 2024-09-04 10:27:26 -05:00
65cd0c86f9 C#: Escape generated members 2024-06-15 19:07:42 +02:00
e3270113ca Remove useless isFirstEntry and useless source.Append("else ") 2024-05-14 07:44:56 +01:00
06b716d8b3 Fix C# Hint NodeType and ResourceType HintString 2024-05-08 16:22:52 +01:00
aba787393f C#: Fix generator crash w/ generic arrays 2024-04-30 22:22:09 +02:00
139a5df821 Cleanup C# projects, code quality & style
New rules:
- Do not silence CA1805 any more
- Limit where we silence CA1707, CA1711, CA1720
- Enforce severity=warning for IDE0040
- Enforce Allman style braces
- Enforce naming conventions (IDE1006 is still severity=suggestion)

Fixes:
- Fix REFL045, CS1572, CS1573
- Suppress CS0618 when generating `InvokeGodotClassMethod`
- Fix indent when generating GD_constants.cs
- Temporarily silence CS1734 in generated code
- Fix a lot of naming rule violations

Misc.:
- Remove ReSharper comments for RedundantNameQualifier
- Remove suppression attributes for RedundantNameQualifier
- Remove severity=warnings for CA1716, CA1304 (already included in the level of analysis we run)
2024-02-27 20:11:24 +01:00
00dc19585b provide analyser corresponding to the GD0001 and GD0002, add ClassPartialModifierAnalyzerFix, and tests
Co-authored-by: Raul Santos <raulsntos@gmail.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
2024-02-21 12:35:28 +03:00
5981886fb7 Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402.

To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed.

Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
2024-02-18 16:47:20 +01:00
46b3096570 Clean a bunch of C# warnings
- `[Obsolete]` tag generated in the middle of documentation comments
- Potential `null` values in generators
- Obsolete call to `GetEditorInterface()`
- We don't want `Godot.Collections.Array` to end with `Collection`
- A few culture specifications and use of `AsSpan` instead of `SubString` in `StringExtensions`
- Disable CA1716 in GodotSharp
2024-01-26 09:38:33 +01:00
fe078219fc C#: Fix generated nested class order 2023-10-18 03:37:57 +02:00
41cf94e8b6 Allow readonly and writeonly C# properties to be accessed from GDScript 2023-08-13 18:35:10 -04:00
b78fe83ed4 Merge pull request #79239 from raulsntos/dotnet/document-generated-members
C#: Document generated members
2023-07-25 21:51:20 +02:00
f8f06d3d38 Merge pull request #78264 from magian1127/4.0StringName
C#: Add `PropertyHint.Enum` support to `Array<StringName>`
2023-07-18 12:19:37 +02:00
12e4aa93b3 C#: Document generated members
Documents generated members and tries to discourage users from calling/overriding internal methods that only exist to be used by the engine.
2023-07-09 14:26:15 +02:00
671a5b4ea5 C#: Compare symbol names without null flow state 2023-07-06 16:10:14 +02:00
e8aeb6baa0 C# Array<StringName> support PropertyHint.Enum 2023-06-15 16:01:42 +08:00
a1f454fee3 C#: Add global class support
Co-authored-by: willnationsdev <willnationsdev@gmail.com>
2023-05-29 19:04:02 +02:00
8ab3295e57 Add fine-grained disabling of SourceGenerators
This allows manual testing and/or alternate source generators to
provide functionality without conflict.
2023-03-25 13:46:12 +11:00
0372bd56b6 C#: Ignore explicit interface implementations 2023-03-04 19:16:48 +01:00
4788cb35c1 C#: Add global namespace to grouping property info 2023-01-27 01:15:19 +01:00
03c26d6618 C#: Disallow init-only properties
ReadOnly properties are currently not allowed because the generated code
needs to set them, this also apply to `init` properties because they
need to be set after initialization.
2022-12-23 19:04:14 +01:00
17b2838f39 C#: Cleanup Variant marshaling code in source/bindings generators
This change aims to reduce the number of places that need to be changed
when adding or editing a Godot type to the bindings.

Since the addition of `Variant.From<T>/As<T>` and
`VariantUtils.CreateFrom<T>/ConvertTo<T>`, we can now replace a lot of
the previous code in the bindings generator and the source generators
that specify these conversions for each type manually.

The only exceptions are the generic Godot collections (`Array<T>` and
`Dictionary<TKey, TValue>`) which still use the old version, as that
one cannot be matched by our new conversion methods (limitation in the
language with generics, forcing us to use delegate pointers).

The cleanup applies to:

- Bindings generator:
  - `TypeInterface.cs_variant_to_managed`
  - `TypeInterface.cs_managed_to_variant`
- Source generators:
  - `MarshalUtils.AppendNativeVariantToManagedExpr`
  - `MarshalUtils.AppendManagedToNativeVariantExpr`
  - `MarshalUtils.AppendVariantToManagedExpr`
  - `MarshalUtils.AppendManagedToVariantExpr`
2022-12-02 14:47:12 +01:00
4a82d71d73 Merge pull request #65907 from magian1127/4.0FixPropertiesGenerator
C#: Fix Generated ScriptProperty Error.
2022-11-28 01:48:52 +01:00
c41196f0f3 C#: Fix Generated ScriptProperty Error.
1. Add "this." to prevent errors caused by duplicate variable names.
2. Try to find the default value of property getters.
2022-11-27 17:40:40 +08:00
b9e1ca1e86 C#: Add global:: namespace to generated source
Adds `global::` to the fully qualified types in source generators to
prevent ambiguity.
2022-11-26 01:13:16 +01:00
687633e5bd Use .generated suffix for generated C# code
Use the `.generated` suffix instead of `_Generated` so .NET marks C#
file generated by Godot source generators as generated code.
2022-10-22 23:13:52 +02:00
4448859ead C# Modify the MemberName generated for the user script 2022-09-06 20:43:40 +08:00
761e2b1a65 C#: Ignore property indexers and report if exported
Ignore property indexers since they are unsupported and report a
diagnostic if an user tries to export it.
2022-08-28 18:16:57 +02:00
cf99d92a39 C#: Preserve order of exported fields/categories 2022-08-25 20:39:57 +02:00
6468f9b37c Add MustBeVariant attribute and analyzer
- MustBeVariant attribute can be used to enforce that generic types must
be a marshable from/to Variant.
- Also renames all diagnostic ids to be valid unicode identifiers.
2022-08-25 01:47:40 +02:00
Zae
431a28fe19 C#: Add grouping attributes for properties. 2022-08-23 01:23:45 +08:00
3123be2384 C#: Array, Dictionary and marshaling refactoring
- Array and Dictionary now store `Variant` instead of `System.Object`.
- Removed generic Array and Dictionary.
  They cause too much issues, heavily relying on reflection and
  very limited by the lack of a generic specialization.
- Removed support for non-Godot collections.
  Support for them also relied heavily on reflection for marshaling.
  Support for them will likely be re-introduced in the future, but
  it will have to rely on source generators instead of reflection.
- Reduced our use of reflection.
  The remaining usages will be moved to source generators soon.
  The only usage that I'm not sure yet how to replace is dynamic
  invocation of delegates.
2022-08-22 03:36:52 +02:00
a9892f2571 C#: Add source generator for method list 2022-08-22 03:36:52 +02:00
97713ff77a C#: Add source generator for signals as events
Changed the signal declaration signal to:

```
// The following generates a MySignal event
[Signal] public delegate void MySignalEventHandler(int param);
```
2022-08-22 03:36:52 +02:00
e22dd3bc6a C#: Static marshaling for bindings and source generators
Previously, we added source generators for invoking/accessing methods,
properties and fields in scripts. This freed us from the overhead of
reflection. However, the generated code still used our dynamic
marshaling functions, which do runtime type checking and box value
types.

This commit changes the bindings and source generators to include
'static' marshaling. Based on the types known at compile time, now
we generate the appropriate marshaling call for each type.
2022-08-22 03:36:51 +02:00
92503ae8db C#: Add source generator for properties and exports default values
The editor no longer needs to create temporary instances to get the
default values. The initializer values of the exported properties are
still evaluated at runtime. For example, in the following example,
`GetInitialValue()` will be called when first looks for default values:

```
[Export] int MyValue = GetInitialValue();
```

Exporting fields with a non-supported type now results in a compiler
error rather than a runtime error when the script is used.
2022-08-22 03:36:51 +02:00