Skip to content

Commit

Permalink
fix RIDER-107227
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 03899e6b3ddb00180c024d70b73786cec0f22c39
  • Loading branch information
krasnotsvetov authored and intellij-monorepo-bot committed Jul 18, 2024
1 parent abd773d commit 1d7240b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out Impl
{
case IClass cls when unityApi.IsUnityType(cls) ||
cls.IsDotsImplicitlyUsedType() ||
IsUxmlFactory(cls):
IsUxmlFactory(cls) ||
unityApi.IsOdinType(cls):
flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature;
return true;
case IStruct @struct when unityApi.IsUnityType(@struct) ||
Expand Down Expand Up @@ -105,14 +106,21 @@ public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out Impl
case IField field when unityApi.IsSerialisedField(field).HasFlag(SerializedFieldStatus.SerializedField):
flags = ImplicitUseKindFlags.Assign;
return true;

case IField field when unityApi.IsOdinInspectorField(field):
flags = ImplicitUseKindFlags.Assign;
return true;

case IProperty property when IsEventHandler(unityApi, property.Setter) ||
IsImplicitlyUsedInterfaceProperty(property) ||
IsAnimationEvent(solution, property) ||
unityApi.IsSerialisedAutoProperty(property, useSwea:true).HasFlag(SerializedFieldStatus.SerializedField):
flags = ImplicitUseKindFlags.Assign;
return true;

case IProperty property when unityApi.IsOdinInspectorProperty(property):
flags = ImplicitUseKindFlags.Assign;
return true;

case IParameter parameter
when parameter.IsRefMember() && parameter.GetContainingType().IsDotsImplicitlyUsedType():
flags = ImplicitUseKindFlags.Assign;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public static class OdinKnownAttributes
public static readonly IClrTypeName OdinSerializedComponent = new ClrTypeName("Sirenix.OdinInspector.SerializedComponent");
public static readonly IClrTypeName OdinSerializedStateMachineBehaviour = new ClrTypeName("Sirenix.OdinInspector.SerializedStateMachineBehaviour");
public static readonly IClrTypeName OdinSerializedUnityObject= new ClrTypeName("Sirenix.OdinInspector.SerializedUnityObject");

public static readonly IClrTypeName PropertyGroupAttribute = new ClrTypeName("Sirenix.OdinInspector.PropertyGroupAttribute");
public static readonly IClrTypeName OdinDrawer = new ClrTypeName("Sirenix.OdinInspector.Editor.OdinDrawer");


public static readonly Dictionary<IClrTypeName, string[]> AttributesWithMemberCompletion = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public UnityApi(UnityVersion unityVersion, UnityTypeCache unityTypeCache, UnityT

public bool IsUnityType([NotNullWhen(true)] ITypeElement? type) =>
type != null && myUnityTypeCache.IsUnityType(type);

public bool IsOdinType([NotNullWhen(true)] ITypeElement? type)
{
if (type == null)
return false;

if (!OdinAttributeUtil.HasOdinSupport(myTechnologyDescriptionCollector))
return false;

return type.DerivesFromOdinDrawer();
}

// A serialised field cannot be abstract or generic, but a type declaration that will be serialised can be. This
// method differentiates between a type declaration and a type usage. Consider renaming if we ever need to
Expand Down Expand Up @@ -173,6 +184,44 @@ public SerializedFieldStatus IsSerialisedField(IField? field, bool useSwea = tru

return status;
}

public bool IsOdinInspectorField(IField? field)
{
if (field == null)
return false;

if (!OdinAttributeUtil.HasOdinSupport(myTechnologyDescriptionCollector))
return false;

foreach (var attribute in field.GetAttributeInstances(AttributesSource.Self))
{
if (attribute.GetAttributeType().GetTypeElement().DerivesFrom(OdinKnownAttributes.PropertyGroupAttribute))
{
return true;
}
}

return false;
}

public bool IsOdinInspectorProperty(IProperty? property)
{
if (property == null)
return false;

if (!OdinAttributeUtil.HasOdinSupport(myTechnologyDescriptionCollector))
return false;

foreach (var attribute in property.GetBackingFieldAttributeInstances())
{
if (attribute.GetAttributeType().GetTypeElement().DerivesFrom(OdinKnownAttributes.PropertyGroupAttribute))
{
return true;
}
}

return false;
}

private SerializedFieldStatus IsSerialisedFieldByOdinRules(IField? field)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using JetBrains.Metadata.Reader.API;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Plugins.Unity.Core.ProjectModel;
using JetBrains.ReSharper.Plugins.Unity.Odin.Attributes;
using JetBrains.ReSharper.Plugins.Unity.UnityEditorIntegration.Api;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp;
Expand Down Expand Up @@ -56,6 +57,11 @@ public static bool DerivesFromMonoBehaviour([CanBeNull] this ITypeElement candid
{
return candidate.DerivesFrom(KnownTypes.MonoBehaviour);
}

public static bool DerivesFromOdinDrawer([CanBeNull] this ITypeElement candidate)
{
return candidate.DerivesFrom(OdinKnownAttributes.OdinDrawer);
}

public static bool DerivesFromScriptableObject([CanBeNull] this ITypeElement candidate)
{
Expand Down

0 comments on commit 1d7240b

Please sign in to comment.