Skip to content

Minor fixes #2289

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 7 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ Since 2018.1, the version numbers and release cycle match Rider's versions and r

- Show preview for target typed new instances of `Color` ([RIDER-64151](https://youtrack.jetbrains.com/issue/RIDER-64151), [#2250](https://github.com/JetBrains/resharper-unity/pull/2250))
- Update API information to 2022.1.0b7 ([#2276](https://github.com/JetBrains/resharper-unity/pull/2276))
- Rider: Treat animation files as YAML ([#2283](https://github.com/JetBrains/resharper-unity/pull/2283))
- Rider: Hide rename solution and manage NuGet packages by default ([RIDER-62297](https://youtrack.jetbrains.com/issue/RIDER-62297), [#2277](https://github.com/JetBrains/resharper-unity/pull/2277))
- Rider: Updates to handling of hidden assets in Unity Explorer ([#2280](https://github.com/JetBrains/resharper-unity/pull/2280))
- Rider: Improve notification when opening a Unity project as a folder ([#2286](https://github.com/JetBrains/resharper-unity/pull/2286))
- Unity editor: Expand Find Usages editor window by default ([#2239](https://github.com/JetBrains/resharper-unity/pull/2239))

### Fixed

- Fix massive performance issue when opening very large projects on certain file systems ([RIDER-53358](https://youtrack.jetbrains.com/issue/RIDER-53358), [#2271](https://github.com/JetBrains/resharper-unity/pull/2271))
- Fix excessive memory traffic when opening very large projects ([#2271](https://github.com/JetBrains/resharper-unity/pull/2271))
- Fix incorrect redundant attribute warning for `FormerlySerializedAs` attribute on property backing field ([#2285](https://github.com/JetBrains/resharper-unity/issues/2285), [#2289](https://github.com/JetBrains/resharper-unity/pull/2289))
- Rider: Fix incorrectly showing both Unity and Unity DLL project action groups ([#2219](https://github.com/JetBrains/resharper-unity/pull/2219))
- Rider: Fix incorrectly showing "switch to full UI" action when already in full UI ([RIDER-71185](https://youtrack.jetbrains.com/issue/RIDER-71185), [#2220](https://github.com/JetBrains/resharper-unity/pull/2220))
- Rider: Fix debugging unit test when debugger is already attached to the editor ([RIDER-70660](https://youtrack.jetbrains.com/issue/RIDER-70660), [#2232](https://github.com/JetBrains/resharper-unity/pull/2232))
Expand Down
6 changes: 3 additions & 3 deletions resharper/resharper-json/src/Json/Psi/Tree/IJsonNewArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace JetBrains.ReSharper.Plugins.Json.Psi.Tree
{
public partial interface IJsonNewArray
{
void AddArrayElementBefore(IJsonNewValue value, IJsonNewValue? anchor);
void AddArrayElementAfter(IJsonNewValue value, IJsonNewValue? anchor);
IJsonNewValue AddArrayElementBefore(IJsonNewValue value, IJsonNewValue? anchor);
IJsonNewValue AddArrayElementAfter(IJsonNewValue value, IJsonNewValue? anchor);
void RemoveArrayElement(IJsonNewValue argument);
}
}
}
79 changes: 52 additions & 27 deletions resharper/resharper-json/src/Json/Psi/Tree/Impl/JsonNewArray.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,100 @@
#nullable enable

using JetBrains.Diagnostics;
using JetBrains.ReSharper.Plugins.Json.Psi.Parsing.TokenNodeTypes;
using JetBrains.ReSharper.Psi.ExtensionsAPI;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Tree;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Util;
using JetBrains.ReSharper.Resources.Shell;

#nullable enable

namespace JetBrains.ReSharper.Plugins.Json.Psi.Tree.Impl
{
internal partial class JsonNewArray
{
public void AddArrayElementBefore(IJsonNewValue value, IJsonNewValue? anchor)
public IJsonNewValue AddArrayElementBefore(IJsonNewValue value, IJsonNewValue? anchor)
{
if (anchor == null)
{
var lastItem = Values.LastOrDefault();
if (lastItem != null)
{
AddArrayElementAfter(value, lastItem);
return;
}
return AddArrayElementAfter(value, lastItem);

// This is the only array element. Don't worry about whitespace
using (WriteLockCookie.Create(parent.IsPhysical()))
{
if (RBracket != null)
ModificationUtil.AddChildBefore(RBracket, value);
value = ModificationUtil.AddChildBefore(RBracket, value);
else if (LBracket != null)
ModificationUtil.AddChildAfter(LBracket, value);
value = ModificationUtil.AddChildAfter(LBracket, value);
value.AssertIsValid();
return value;
}
}
else

Assertion.Assert(Values.Contains(anchor));

// Copy the leading whitespace from the anchor, since we don't currently support formatting
var whitespaceStart = anchor.GetPreviousNonWhitespaceToken()?.GetNextToken();
var whitespaceEnd = anchor.GetPreviousToken();

using (WriteLockCookie.Create(parent.IsPhysical()))
{
Assertion.Assert(Values.Contains(anchor));
using (WriteLockCookie.Create(parent.IsPhysical()))
var comma = JsonNewTokenNodeTypes.COMMA.CreateLeafElement();
LowLevelModificationUtil.AddChildBefore(anchor, comma);
value = ModificationUtil.AddChildBefore(comma, value);

if (whitespaceStart != null && whitespaceStart.IsWhitespaceToken() &&
whitespaceEnd != null && whitespaceEnd.IsWhitespaceToken())
{
var comma = JsonNewTokenNodeTypes.COMMA.CreateLeafElement();
LowLevelModificationUtil.AddChildBefore(anchor, comma);
ModificationUtil.AddChildBefore(comma, value);
ModificationUtil.AddChildRangeBefore(anchor, new TreeRange(whitespaceStart, whitespaceEnd));
}

value.AssertIsValid();
return value;
}
}

public void AddArrayElementAfter(IJsonNewValue value, IJsonNewValue? anchor)
public IJsonNewValue AddArrayElementAfter(IJsonNewValue value, IJsonNewValue? anchor)
{
if (anchor == null)
{
var firstItem = ValuesEnumerable.FirstOrDefault();
if (firstItem != null)
{
AddArrayElementBefore(value, firstItem);
return;
}
return AddArrayElementBefore(value, firstItem);

// This is the only array element. Don't worry about whitespace
using (WriteLockCookie.Create(parent.IsPhysical()))
{
if (RBracket != null)
ModificationUtil.AddChildBefore(RBracket, value);
else if (LBracket != null)
ModificationUtil.AddChildAfter(LBracket, value);
value.AssertIsValid();
return value;
}
}
else

Assertion.Assert(Values.Contains(anchor));

// Copy the leading whitespace from the anchor, since we don't currently support formatting
var whitespaceStart = anchor.GetPreviousNonWhitespaceToken()?.GetNextToken();
var whitespaceEnd = anchor.GetPreviousToken();

using (WriteLockCookie.Create(parent.IsPhysical()))
{
Assertion.Assert(Values.Contains(anchor));
using (WriteLockCookie.Create(parent.IsPhysical()))
var comma = JsonNewTokenNodeTypes.COMMA.CreateLeafElement();
LowLevelModificationUtil.AddChildAfter(anchor, comma);
value = ModificationUtil.AddChildAfter(comma, value);

if (whitespaceStart != null && whitespaceStart.IsWhitespaceToken() &&
whitespaceEnd != null && whitespaceEnd.IsWhitespaceToken())
{
var comma = JsonNewTokenNodeTypes.COMMA.CreateLeafElement();
LowLevelModificationUtil.AddChildAfter(anchor, comma);
ModificationUtil.AddChildAfter(comma, value);
ModificationUtil.AddChildRangeAfter(comma, new TreeRange(whitespaceStart, whitespaceEnd));
}

value.AssertIsValid();
return value;
}
}

Expand Down Expand Up @@ -117,4 +142,4 @@ public void RemoveArrayElement(IJsonNewValue argument)
}
}
}
}
}
51 changes: 41 additions & 10 deletions resharper/resharper-json/src/Json/Psi/Tree/Impl/JsonNewObject.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#nullable enable

using JetBrains.Diagnostics;
using JetBrains.ReSharper.Plugins.Json.Psi.Parsing.TokenNodeTypes;
using JetBrains.ReSharper.Psi.ExtensionsAPI;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Tree;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Util;
using JetBrains.ReSharper.Resources.Shell;

#nullable enable

namespace JetBrains.ReSharper.Plugins.Json.Psi.Tree.Impl
{
internal partial class JsonNewObject
Expand All @@ -18,24 +20,38 @@ public IJsonNewMember AddMemberBefore(string key, IJsonNewValue value, IJsonNewM
if (lastItem != null)
return AddMemberAfter(key, value, lastItem);

// This is the only member. Don't worry about whitespace
using (WriteLockCookie.Create(parent.IsPhysical()))
{
var member = CreateMember(key, value);
if (RBrace != null)
ModificationUtil.AddChildBefore(RBrace, member);
else if (LBrace != null)
ModificationUtil.AddChildAfter(LBrace, member);
member = ModificationUtil.AddChildBefore(RBrace, member);
if (LBrace != null)
member = ModificationUtil.AddChildAfter(LBrace, member);
member.AssertIsValid();
return member;
}
}

// Copy the leading whitespace from the anchor, since we don't currently support formatting
var whitespaceStart = anchor.GetPreviousNonWhitespaceToken()?.GetNextToken();
var whitespaceEnd = anchor.GetPreviousToken();

Assertion.Assert(Members.Contains(anchor));
using (WriteLockCookie.Create(parent.IsPhysical()))
{
var member = CreateMember(key, value);
var comma = JsonNewTokenNodeTypes.COMMA.CreateLeafElement();
LowLevelModificationUtil.AddChildBefore(anchor, comma);
ModificationUtil.AddChildBefore(comma, member);
member = ModificationUtil.AddChildBefore(comma, member);

if (whitespaceStart != null && whitespaceStart.IsWhitespaceToken() &&
whitespaceEnd != null && whitespaceEnd.IsWhitespaceToken())
{
ModificationUtil.AddChildRangeBefore(anchor, new TreeRange(whitespaceStart, whitespaceEnd));
}

member.AssertIsValid();
return member;
}
}
Expand All @@ -48,24 +64,39 @@ public IJsonNewMember AddMemberAfter(string key, IJsonNewValue value, IJsonNewMe
if (firstItem != null)
return AddMemberBefore(key, value, firstItem);

// This is the only member. Don't worry about whitespace
using (WriteLockCookie.Create(parent.IsPhysical()))
{
var member = CreateMember(key, value);
if (RBrace != null)
ModificationUtil.AddChildBefore(RBrace, member);
member = ModificationUtil.AddChildBefore(RBrace, member);
else if (LBrace != null)
ModificationUtil.AddChildAfter(LBrace, member);
member = ModificationUtil.AddChildAfter(LBrace, member);
member.AssertIsValid();
return member;
}
}

Assertion.Assert(Members.Contains(anchor));

// Copy the leading whitespace from the anchor, since we don't currently support formatting
var whitespaceStart = anchor.GetPreviousNonWhitespaceToken()?.GetNextToken();
var whitespaceEnd = anchor.GetPreviousToken();

using (WriteLockCookie.Create(parent.IsPhysical()))
{
var member = CreateMember(key, value);
var comma = JsonNewTokenNodeTypes.COMMA.CreateLeafElement();
LowLevelModificationUtil.AddChildAfter(anchor, comma);
ModificationUtil.AddChildAfter(comma, member);
member = ModificationUtil.AddChildAfter(comma, member);

if (whitespaceStart != null && whitespaceStart.IsWhitespaceToken() &&
whitespaceEnd != null && whitespaceEnd.IsWhitespaceToken())
{
ModificationUtil.AddChildRangeAfter(comma, new TreeRange(whitespaceStart, whitespaceEnd));
}

member.AssertIsValid();
return member;
}
}
Expand All @@ -79,4 +110,4 @@ private static IJsonNewMember CreateMember(string key, IJsonNewValue value)
return member;
}
}
}
}
13 changes: 12 additions & 1 deletion resharper/resharper-unity/src/Unity/AsmDef/AsmDefUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ namespace JetBrains.ReSharper.Plugins.Unity.AsmDef
{
public static class AsmDefUtils
{
public static string FormatGuidReference(Guid guid) => $"guid:{guid:N}";
// Unity serialises with uppercase "GUID:", but will read either case. The GUID itself is formatted in lowercase
public static string FormatGuidReference(Guid guid) => $"GUID:{guid:N}";

public static bool IsGuidReference(string reference) =>
reference.StartsWith("GUID:", StringComparison.OrdinalIgnoreCase);

public static bool TryParseGuidReference(string reference, out Guid guid)
{
guid = Guid.Empty;
// Skip the 5 chars of "GUID:"
return IsGuidReference(reference) && Guid.TryParse(reference[5..], out guid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ConvertToNamedReferenceContextAction(IJsonNewContextActionDataProvider da

protected override bool IsAvailable(IJsonNewLiteralExpression literalExpression)
{
if (!literalExpression.GetUnquotedText().StartsWith("guid:", StringComparison.InvariantCultureIgnoreCase))
if (!AsmDefUtils.IsGuidReference(literalExpression.GetUnquotedText()))
return false;

var reference = literalExpression.FindReference<AsmDefNameReference>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void Run(IJsonNewLiteralExpression element,
IHighlightingConsumer consumer)
{
if ((element.IsReferencesArrayEntry() || element.IsReferencePropertyValue())
&& element.GetUnquotedText().StartsWith("guid:", StringComparison.InvariantCultureIgnoreCase))
&& AsmDefUtils.IsGuidReference(element.GetUnquotedText()))
{
var reference = element.FindReference<AsmDefNameReference>();
var declaredElement = reference?.Resolve().DeclaredElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void Run(IJsonNewLiteralExpression element,
{
// Unity prefers GUID references when creating a new file, to guard against accidentally changing the name
if ((element.IsReferencesArrayEntry() || element.IsReferencePropertyValue())
&& !element.GetUnquotedText().StartsWith("guid:", StringComparison.InvariantCultureIgnoreCase))
&& !AsmDefUtils.IsGuidReference(element.GetUnquotedText()))
{
var reference = element.FindReference<AsmDefNameReference>();
if (reference != null && reference.Resolve().Info.ResolveErrorType == ResolveErrorType.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,11 @@ private static FrugalLocalList<IJsonNewValue> FindReferenceElement(IJsonNewArray
var text = literal.GetUnquotedText();
if (text.Equals(asmDefName, StringComparison.OrdinalIgnoreCase))
results.Add(literal);
else if (asmDefGuid != null && text.Equals(asmDefGuid))
else if (asmDefGuid != null && text.Equals(asmDefGuid, StringComparison.OrdinalIgnoreCase))
results.Add(literal);

count++;
if (text.StartsWith("guid:", StringComparison.OrdinalIgnoreCase))
if (AsmDefUtils.IsGuidReference(text))
guidCount++;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using JetBrains.Annotations;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Plugins.Json.Psi;
using JetBrains.ReSharper.Plugins.Json.Psi.Tree;
Expand Down Expand Up @@ -33,8 +32,7 @@ public override ResolveResultWithInfo ResolveWithoutCache()
return resolveResultWithInfo;

var name = GetName();
if (name.StartsWith("guid:", StringComparison.InvariantCultureIgnoreCase) &&
Guid.TryParse(name[5..], out var guid))
if (AsmDefUtils.TryParseGuidReference(name, out var guid))
{
var metaFileCache = myOwner.GetSolution().GetComponent<MetaFileGuidCache>();
var asmDefCache = myOwner.GetSolution().GetComponent<AsmDefCache>();
Expand Down Expand Up @@ -86,8 +84,8 @@ public override TreeTextRange GetTreeTextRange()

public override IReference BindTo(IDeclaredElement element)
{
// Don't rename a guid: reference
if (myOwner.GetUnquotedText().StartsWith("guid:", StringComparison.InvariantCultureIgnoreCase))
// Don't rename a GUID: reference
if (AsmDefUtils.IsGuidReference(myOwner.GetUnquotedText()))
return this;

var factory = JsonNewElementFactory.GetInstance(myOwner.GetPsiModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public GuidReferenceSearchSourceFileProcessor(ITreeNode treeNode, ReferenceSearc
}

protected override bool PreFilterReference(IReference reference) => reference is AsmDefNameReference &&
reference.GetName().StartsWith("guid:", StringComparison.InvariantCultureIgnoreCase);
AsmDefUtils.IsGuidReference(reference.GetName());

protected override bool SubTreeContainsText(ITreeNode node)
{
Expand Down
Loading