Skip to content

Serialised fields require correct type #1720

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

Merged
merged 14 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 13 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Since 2018.1, the version numbers and release cycle match Rider's versions and r

- All applicable quick fixes are now bulk actions, and can be applied over project scope ([#1648](https://github.com/JetBrains/resharper-unity/issues/1648), [#1649](https://github.com/JetBrains/resharper-unity/pull/1649))
- Improved method signature validation and usage suppression using Unity's `RequiredSignature` attribute ([#1679](https://github.com/JetBrains/resharper-unity/pull/1679), [#1689](https://github.com/JetBrains/resharper-unity/pull/1689))
- Fields must have correct type to be considered a serialised field ([#1605](https://github.com/JetBrains/resharper-unity/issues/1605), [#1638](https://github.com/JetBrains/resharper-unity/pull/1638), [#1720](https://github.com/JetBrains/resharper-unity/pull/1720))
- Update `.meta` file icons to something less distracting ([RIDER-45675](https://youtrack.jetbrains.com/issue/RIDER-45675), [#1698](https://github.com/JetBrains/resharper-unity/pull/1698))
- Rider: Significant reduction in memory usage while indexing assets ([#1645](https://github.com/JetBrains/resharper-unity/pull/1645))
- Rider: Better support for prefab modifications in Find Usages and showing Inspector values ([#1645](https://github.com/JetBrains/resharper-unity/pull/1645))
Expand All @@ -38,7 +39,7 @@ Since 2018.1, the version numbers and release cycle match Rider's versions and r
### Fixed

- Fix meta file handling when references to Unity assemblies are invalid ([#1623](https://github.com/JetBrains/resharper-unity/pull/1623))
- Public fields of type `Action` are no longer treated as serialised fields ([#1605](https://github.com/JetBrains/resharper-unity/issues/1605), [#1638](https://github.com/JetBrains/resharper-unity/pull/1638))
- Public fields of type `Action` are no longer treated as serialised fields ([#1605](https://github.com/JetBrains/resharper-unity/issues/1605), )
- Fix incorrect method signature validation for methods marked with `OnOpenedAsset` ([#1053](https://github.com/JetBrains/resharper-unity/issues/1053), [#1679](https://github.com/JetBrains/resharper-unity/pull/1679))
- Rider: Fix debugger sometimes treating user code as external code ([#1671](https://github.com/JetBrains/resharper-unity/issues/1671), [RIDER-43846](https://youtrack.jetbrains.com/issue/RIDER-43846), [#1697](https://github.com/JetBrains/resharper-unity/pull/1697))
- Rider: Fix grouping assets by directory in Find Usages results ([#1668](https://github.com/JetBrains/resharper-unity/pull/1668))
Expand Down

This file was deleted.

86 changes: 0 additions & 86 deletions resharper/.idea/.idea.resharper-unity/.idea/markdown-navigator.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using JetBrains.Metadata.Reader.API;
using JetBrains.ReSharper.Feature.Services.Daemon;
Expand Down Expand Up @@ -41,13 +43,13 @@ public class AttributedMethodSignatureProblemAnalyzer : MethodSignatureProblemAn
};

private readonly IPredefinedTypeCache myPredefinedTypeCache;
private readonly Dictionary<IClrTypeName, MethodSignature[]> myMethodSignatures;
private readonly ConcurrentDictionary<IClrTypeName, MethodSignature[]> myMethodSignatures;

public AttributedMethodSignatureProblemAnalyzer(UnityApi unityApi, IPredefinedTypeCache predefinedTypeCache)
: base(unityApi)
{
myPredefinedTypeCache = predefinedTypeCache;
myMethodSignatures = new Dictionary<IClrTypeName, MethodSignature[]>();
myMethodSignatures = new ConcurrentDictionary<IClrTypeName, MethodSignature[]>();
}

protected override void Analyze(IAttribute element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
Expand Down Expand Up @@ -88,14 +90,22 @@ private MethodSignature[] GetExpectedMethodSignatures(ITypeElement attributeType
{
var attributeClrName = attributeTypeElement.GetClrName();
if (myMethodSignatures.TryGetValue(attributeClrName, out var signatures))
return signatures;
{
if (signatures.All(s => s.IsValid()))
return signatures;

// If any of the signatures are no longer valid, clear the cache and try again
myMethodSignatures.Clear();
}

// Try to get the expected signature from a method marked with RequiredSignatureAttribute (introduced in
// Unity 2017.3). If the attribute does not exist, either because it's not applied, or we're on an earlier
// version, check our known attributes for a signature
// Remember that we're run on pooled threads, so try to add to the concurrent dictionary. It doesn't matter
// if another thread beats us.
signatures = GetSignaturesFromRequiredSignatureAttribute(attributeTypeElement)
?? GetSignaturesFromKnownAttributes(attributeClrName, predefinedType);
if (signatures != null) myMethodSignatures.Add(attributeClrName, signatures);
if (signatures != null) myMethodSignatures.TryAdd(attributeClrName.GetPersistent(), signatures);
return signatures;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.Plugins.Unity.Feature.HighlightingEye;
using JetBrains.ReSharper.Plugins.Unity.Feature.Services.Pencils;

namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Daemon.Stages.Highlightings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out Impl
flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature;
return true;

case ITypeElement typeElement when unityApi.IsSerializableType(typeElement):
case ITypeElement typeElement when unityApi.IsSerializableTypeDeclaration(typeElement):
// TODO: We should only really mark it as in use if it's actually used somewhere
// That is, it should be used as a field in a Unity type, or another serializable type
flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public bool Matches(ITreeNode node, INodeMatchingContext ctx)
if (!(node is IDeclaration declaration)) return false;
var unityApi = node.GetSolution().GetComponent<UnityApi>();
return unityApi.IsUnityType(declaration.DeclaredElement as ITypeElement)
|| unityApi.IsSerializableType(declaration.DeclaredElement as ITypeElement);
|| unityApi.IsSerializableTypeDeclaration(declaration.DeclaredElement as ITypeElement);
}

public int? Compare(INodeConstraint other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using JetBrains.ReSharper.Features.Navigation.Features.FindUsages;
using JetBrains.ReSharper.Psi;

namespace JetBrains.ReSharper.Plugins.Unity
namespace JetBrains.ReSharper.Plugins.Unity.Feature.Navigation.FindUsages
{
[ShellComponent]
public class UnityFindUsagesProvider : FindUsagesProvider
Expand Down Expand Up @@ -40,8 +40,6 @@ public override string GetNotFoundMessage(SearchRequest request)
return request.Title + " are only implicit.";
}
}


}

return base.GetNotFoundMessage(request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace JetBrains.ReSharper.Plugins.Unity.Feature.HighlightingEye
namespace JetBrains.ReSharper.Plugins.Unity.Feature.Services.Pencils
{
public static class PencilsGroupKind
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
using JetBrains.Lifetimes;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Feature.Services.Pencils.Filters;
using JetBrains.ReSharper.Plugins.Unity.Feature.HighlightingEye;
using JetBrains.ReSharper.Plugins.Unity.ProjectModel;
using JetBrains.ReSharper.Plugins.Unity.Settings;

namespace JetBrains.ReSharper.Plugins.Unity.Feature.Pencils
namespace JetBrains.ReSharper.Plugins.Unity.Feature.Services.Pencils
{
public class UnityPencilsFilter : PencilsFilterSettingsBase<UnitySettings>
{
Expand All @@ -20,7 +19,7 @@ public UnityPencilsFilter(Lifetime lifetime, UnitySolutionTracker solutionTracke

public override string Kind => PencilsGroupKind.UnityPerformanceKind;
}

[SolutionComponent]
public class UnityPencilsFilterProvider : IPencilsFiltersProvider
{
Expand Down
15 changes: 15 additions & 0 deletions resharper/resharper-unity/src/KnownTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ namespace JetBrains.ReSharper.Plugins.Unity
{
public static class KnownTypes
{
// System
public static readonly IClrTypeName SystemVersion = new ClrTypeName("System.Version");

// UnityEngine
public static readonly IClrTypeName AddComponentMenu = new ClrTypeName("UnityEngine.AddComponentMenu");
public static readonly IClrTypeName AnimationCurve = new ClrTypeName("UnityEngine.AnimationCurve");
public static readonly IClrTypeName Animator = new ClrTypeName("UnityEngine.Animator");
public static readonly IClrTypeName Camera = new ClrTypeName("UnityEngine.Camera");
public static readonly IClrTypeName Color = new ClrTypeName("UnityEngine.Color");
public static readonly IClrTypeName Color32 = new ClrTypeName("UnityEngine.Color32");
public static readonly IClrTypeName Component = new ClrTypeName("UnityEngine.Component");
public static readonly IClrTypeName CreateAssetMenuAttribute = new ClrTypeName("UnityEngine.CreateAssetMenuAttribute");
public static readonly IClrTypeName Debug = new ClrTypeName("UnityEngine.Debug");
public static readonly IClrTypeName ExecuteInEditMode = new ClrTypeName("UnityEngine.ExecuteInEditMode");
public static readonly IClrTypeName GameObject = new ClrTypeName("UnityEngine.GameObject");
public static readonly IClrTypeName Gradient = new ClrTypeName("UnityEngine.Gradient");
public static readonly IClrTypeName GUIStyle = new ClrTypeName("UnityEngine.GUIStyle");
public static readonly IClrTypeName HeaderAttribute = new ClrTypeName("UnityEngine.HeaderAttribute");
public static readonly IClrTypeName HideInInspectorAttribute = new ClrTypeName("UnityEngine.HideInInspector");
public static readonly IClrTypeName ImageEffectAfterScale = new ClrTypeName("UnityEngine.ImageEffectAfterScale");
Expand All @@ -24,13 +32,17 @@ public static class KnownTypes
public static readonly IClrTypeName LayerMask = new ClrTypeName("UnityEngine.LayerMask");
public static readonly IClrTypeName Material = new ClrTypeName("UnityEngine.Material");
public static readonly IClrTypeName MaterialPropertyBlock = new ClrTypeName("UnityEngine.MaterialPropertyBlock");
public static readonly IClrTypeName Matrix4x4 = new ClrTypeName("UnityEngine.Matrix4x4");
public static readonly IClrTypeName MinAttribute = new ClrTypeName("UnityEngine.MinAttribute");
public static readonly IClrTypeName MonoBehaviour = new ClrTypeName("UnityEngine.MonoBehaviour");
public static readonly IClrTypeName Object = new ClrTypeName("UnityEngine.Object");
public static readonly IClrTypeName Physics = new ClrTypeName("UnityEngine.Physics");
public static readonly IClrTypeName Physics2D = new ClrTypeName("UnityEngine.Physics2D");
public static readonly IClrTypeName Quaternion = new ClrTypeName("UnityEngine.Quaternion");
public static readonly IClrTypeName RangeAttribute = new ClrTypeName("UnityEngine.RangeAttribute");
public static readonly IClrTypeName RequireComponent = new ClrTypeName("UnityEngine.RequireComponent");
public static readonly IClrTypeName Rect = new ClrTypeName("UnityEngine.Rect");
public static readonly IClrTypeName RectOffset = new ClrTypeName("UnityEngine.RectOffset");
public static readonly IClrTypeName Resources = new ClrTypeName("UnityEngine.Resources");
public static readonly IClrTypeName RuntimeInitializeOnLoadMethodAttribute = new ClrTypeName("UnityEngine.RuntimeInitializeOnLoadMethodAttribute");
public static readonly IClrTypeName ScriptableObject = new ClrTypeName("UnityEngine.ScriptableObject");
Expand All @@ -39,6 +51,9 @@ public static class KnownTypes
public static readonly IClrTypeName SpaceAttribute = new ClrTypeName("UnityEngine.SpaceAttribute");
public static readonly IClrTypeName TooltipAttribute = new ClrTypeName("UnityEngine.TooltipAttribute");
public static readonly IClrTypeName Transform = new ClrTypeName("UnityEngine.Transform");
public static readonly IClrTypeName Vector2 = new ClrTypeName("UnityEngine.Vector2");
public static readonly IClrTypeName Vector3 = new ClrTypeName("UnityEngine.Vector3");
public static readonly IClrTypeName Vector4 = new ClrTypeName("UnityEngine.Vector4");

public static readonly IClrTypeName UnityEvent = new ClrTypeName("UnityEngine.Events.UnityEventBase");

Expand Down
Loading