Skip to content

Commit 46e2c5d

Browse files
Merge pull request #2267 from JetBrains/net221-vk-RIDER-71269
Asset Finder issues
2 parents cee2e2d + e00dd6e commit 46e2c5d

File tree

63 files changed

+3124
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3124
-3
lines changed

resharper/resharper-unity/src/Unity.Rider/Common/CSharp/Daemon/CodeInsights/UnityUsagesCodeVisionProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public void OnClick(CodeInsightsHighlighting highlighting, ISolution solution)
6060
if (!declaredElement.IsValid())
6161
return;
6262

63+
// Document constant is required for non-empty IFinderSearchRoot
64+
rules.AddRule("Document", DocumentModelDataConstants.DOCUMENT, highlighting.Range.Document);
65+
6366
rules.AddRule("DocumentEditorContext", DocumentModelDataConstants.EDITOR_CONTEXT, new DocumentEditorContext(highlighting.Range));
6467
rules.AddRule("PopupWindowSourceOverride", UIDataConstants.PopupWindowContextSource,
6568
new PopupWindowContextSource(lt => new RiderEditorOffsetPopupWindowContext(highlighting.Range.StartOffset.Offset)));

resharper/resharper-unity/src/Unity.Rider/Integration/Yaml/Feature/Usages/UnityYamlExtraGroupingRulesProvider.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ public override RdUsageGroup CreateModel(IOccurrence occurrence, IOccurrenceBrow
189189
{
190190
using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet())
191191
{
192-
if (occurrence is UnityAssetOccurrence assetOccurrence)
192+
if (occurrence is UnityAssetOccurrence assetOccurrence &&
193+
!assetOccurrence.SourceFile.IsAsset() &&
194+
!assetOccurrence.SourceFile.IsAnim() &&
195+
!assetOccurrence.SourceFile.IsController())
193196
{
194197
var hierarchyContainer = assetOccurrence.GetSolution()?.GetComponent<AssetDocumentHierarchyElementContainer>();
195198
var element = hierarchyContainer?.GetHierarchyElement(assetOccurrence.OwningElementLocation, true);

resharper/resharper-unity/src/Unity/CSharp/Daemon/Stages/Highlightings/IconsProviders/EventHandlerDetector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpD
111111
string tooltip, IReadOnlyCallGraphContext context)
112112
{
113113
consumer.AddImplicitConfigurableHighlighting(element);
114+
if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
115+
return;
114116

115117
var isIconHot = element.HasHotIcon(ContextProvider, SettingsStore.BoundSettingsStore, context);
116118

resharper/resharper-unity/src/Unity/CSharp/Daemon/Stages/Highlightings/IconsProviders/FieldDetector.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpD
7272
IReadOnlyCallGraphContext context)
7373
{
7474
consumer.AddImplicitConfigurableHighlighting(element);
75+
76+
if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
77+
return;
78+
7579
consumer.AddHighlighting(new UnityGutterMarkInfo(element, tooltip));
7680
}
7781

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using JetBrains.Application.Settings;
2+
using JetBrains.ReSharper.Plugins.Unity.Core.Application.Settings;
3+
4+
namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Daemon.Stages.Highlightings.IconsProviders
5+
{
6+
public class IconProviderUtil
7+
{
8+
public static bool ShouldShowGutterMarkIcon(IContextBoundSettingsStoreLive settings)
9+
{
10+
return settings.GetValue((UnitySettings key) => key.GutterIconMode) != GutterIconMode.None;
11+
}
12+
}
13+
}

resharper/resharper-unity/src/Unity/CSharp/Daemon/Stages/Highlightings/IconsProviders/TypeDetector.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ protected virtual void AddUnityECSHighlighting(IHighlightingConsumer consumer, I
9292
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration declaration, string text, string tooltip, IReadOnlyCallGraphContext context)
9393
{
9494
consumer.AddImplicitConfigurableHighlighting(declaration);
95+
96+
if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
97+
return;
98+
9599
consumer.AddHighlighting(new UnityGutterMarkInfo(GetActions(declaration), declaration, tooltip));
96100
}
97101

resharper/resharper-unity/src/Unity/CSharp/Daemon/Stages/Highlightings/IconsProviders/UnityCommonIconProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public virtual void AddEventFunctionHighlighting(IHighlightingConsumer consumer,
6060
if (declaration is ICSharpDeclaration cSharpDeclaration)
6161
{
6262
consumer.AddImplicitConfigurableHighlighting(cSharpDeclaration);
63+
64+
if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
65+
continue;
66+
6367
consumer.AddHotHighlighting(PerformanceContextProvider, cSharpDeclaration,
6468
SettingsStore.BoundSettingsStore, text, tooltip, context, GetEventFunctionActions(cSharpDeclaration, context));
6569
}
@@ -73,6 +77,9 @@ public virtual void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer
7377
// gutter mark
7478
var actions = GetActions(cSharpDeclaration, context);
7579

80+
if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
81+
return;
82+
7683
consumer.AddHotHighlighting(PerformanceContextProvider, cSharpDeclaration,
7784
SettingsStore.BoundSettingsStore, text, tooltip, context, actions, true);
7885
}

resharper/resharper-unity/src/Unity/CSharp/Daemon/Stages/Highlightings/IconsProviders/UnityDeclarationHighlightingProviderBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ protected virtual void AddHighlighting(IHighlightingConsumer consumer, ICSharpDe
3232
string tooltip, IReadOnlyCallGraphContext context)
3333
{
3434
consumer.AddImplicitConfigurableHighlighting(element);
35+
36+
if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
37+
return;
38+
3539
consumer.AddHotHighlighting(ContextProvider, element, SettingsStore.BoundSettingsStore, text, tooltip, context, GetActions(element));
3640
}
3741

resharper/resharper-unity/src/Unity/Yaml/Feature/Services/Navigation/UnityAssetOccurrence.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using JetBrains.ProjectModel;
88
using JetBrains.ReSharper.Feature.Services.Occurrences;
99
using JetBrains.ReSharper.Plugins.Unity.Resources.Icons;
10+
using JetBrains.ReSharper.Plugins.Unity.UnityEditorIntegration;
1011
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.DeferredCaches.AssetHierarchy;
1112
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.DeferredCaches.AssetHierarchy.References;
1213
using JetBrains.ReSharper.Psi;
@@ -87,6 +88,9 @@ public virtual RichText GetDisplayText()
8788

8889
private string GetAttachedGameObjectName(AssetHierarchyProcessor processor)
8990
{
91+
if (SourceFile.IsController())
92+
return "AnimatorStateMachine";
93+
9094
var consumer = new UnityScenePathGameObjectConsumer();
9195
processor.ProcessSceneHierarchyFromComponentToRoot(OwningElementLocation, consumer, true, true);
9296

resharper/resharper-unity/src/Unity/Yaml/Psi/Search/UnityAssetReferenceSearcher.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using JetBrains.Annotations;
33
using System;
4+
using System.Linq;
45
using JetBrains.ReSharper.Plugins.Unity.Core.Feature.Caches;
56
using JetBrains.ReSharper.Plugins.Unity.Utils;
67
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.Caches;
@@ -29,6 +30,7 @@ public class UnityAssetReferenceSearcher : IDomainSpecificSearcher
2930
private readonly UnityEventsElementContainer myUnityEventsElementContainer;
3031
private readonly AssetInspectorValuesContainer myAssetInspectorValuesContainer;
3132
private readonly IDeclaredElementsSet myElements;
33+
private readonly ReferenceSearcherParameters myReferenceSearcherParameters;
3234
private readonly AnimationEventUsagesContainer myAnimationEventUsagesContainer;
3335

3436
public UnityAssetReferenceSearcher(DeferredCacheController deferredCacheController,
@@ -48,6 +50,7 @@ public UnityAssetReferenceSearcher(DeferredCacheController deferredCacheControll
4850
myAnimationEventUsagesContainer = animationEventUsagesContainer;
4951
myAssetInspectorValuesContainer = assetInspectorValuesContainer;
5052
myElements = elements;
53+
myReferenceSearcherParameters = referenceSearcherParameters;
5154
}
5255

5356
public bool ProcessProjectItem<TResult>(IPsiSourceFile sourceFile, IFindResultConsumer<TResult> consumer)
@@ -57,10 +60,14 @@ public bool ProcessProjectItem<TResult>(IPsiSourceFile sourceFile, IFindResultCo
5760
if (!myDeferredCacheController.CompletedOnce.Value)
5861
return false;
5962

63+
var set = (myReferenceSearcherParameters.OriginalElements ?? myElements.ToList()).ToHashSet();
6064
foreach (var element in myElements)
6165
{
6266
if (element is IMethod || element is IProperty)
6367
{
68+
if (!set.Contains(element))
69+
continue;
70+
6471
var animationEventUsages = myAnimationEventUsagesContainer.GetEventUsagesFor(sourceFile, element);
6572
foreach (var usage in animationEventUsages)
6673
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.jetbrains.rider.plugins.unity.actions
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent
4+
import com.intellij.openapi.application.ex.ApplicationInfoEx
5+
import com.intellij.openapi.project.Project
6+
import com.jetbrains.rider.actions.RiderTechnicalSupportEntry
7+
import com.jetbrains.rider.actions.RiderTechnicalSupportInfoProvider
8+
import com.jetbrains.rider.plugins.unity.FrontendBackendHost
9+
10+
class UnityVersionRiderTechnicalSupportInfoProvider : RiderTechnicalSupportInfoProvider {
11+
12+
override fun getEntry(e: AnActionEvent, appInfo: ApplicationInfoEx): RiderTechnicalSupportEntry {
13+
return RiderTechnicalSupportEntry("\$UNITY_VERSION", getUnityVersion(e.project))
14+
}
15+
16+
17+
fun getUnityVersion(project: Project?): String {
18+
if (project == null)
19+
return ""
20+
21+
if (project.isDisposed)
22+
return ""
23+
24+
val unityHost = FrontendBackendHost.getInstance(project)
25+
26+
return unityHost.model.unityApplicationData.valueOrNull?.applicationVersion ?: ""
27+
}
28+
}

rider/src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@
161161
<projectService serviceImplementation="com.jetbrains.rider.plugins.unity.ui.vcs.UnityCheckinState"/>
162162

163163
<rider.runWidgetSuspenderExtension implementation="com.jetbrains.rider.plugins.unity.ui.UnityRunWidgetSuspenderExtension"/>
164+
165+
<rider.action.technical.support.info.provider implementation="com.jetbrains.rider.plugins.unity.actions.UnityVersionRiderTechnicalSupportInfoProvider" />
164166
</extensions>
165167

166168
<project-components>

rider/src/test/kotlin/AnimatorFindUsagesTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,18 @@ open class AnimatorFindUsagesTest : FindUsagesAssetTestBase() {
1818
groups?.forEach { group -> setGroupingEnabled(group, true) }
1919
doTest(5, 17, "Behaviour.cs")
2020
}
21+
22+
@Test(dataProvider = "findUsagesGrouping")
23+
fun animationFindUsagesForCommonBehaviorMethod(caseName: String, groups: List<String>?) {
24+
disableAllGroups()
25+
groups?.forEach { group -> setGroupingEnabled(group, true) }
26+
doTest(8, 29, "TestScript1.cs")
27+
}
28+
29+
@Test(dataProvider = "findUsagesGrouping")
30+
fun animationFindUsagesForCommonBehaviorFieldValue(caseName: String, groups: List<String>?) {
31+
disableAllGroups()
32+
groups?.forEach { group -> setGroupingEnabled(group, true) }
33+
doTest(8, 16, "AnimationController.cs")
34+
}
2135
}

rider/src/test/kotlin/FindUsagesAssetTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,17 @@ open class FindUsagesAssetTest : FindUsagesAssetTestBase() {
165165
fun findPropertyHandler2(caseName: String, groups: List<String>?) {
166166
doTest(33, 16, groups)
167167
}
168+
169+
// TODO: uncomment when local tests would fine
170+
// @Test(dataProvider = "findUsagesGrouping")
171+
// @TestEnvironment(solution = "FindUsagesOverriddenEventHandlers")
172+
// fun findAssetUsagesForOverriddenEventHandler(caseName: String, groups: List<String>?) {
173+
// doTest(7, 27, groups, "BaseScript.cs")
174+
// }
175+
//
176+
// @Test(dataProvider = "findUsagesGrouping")
177+
// @TestEnvironment(solution = "FindUsagesOverriddenEventHandlers")
178+
// fun findAssetUsagesForOverriddenEventHandler2(caseName: String, groups: List<String>?) {
179+
// doTest(7, 27, groups, "DerivedScript.cs")
180+
// }
168181
}

rider/src/test/kotlin/base/FindUsagesAssetTestBase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ abstract class FindUsagesAssetTestBase : BaseTestWithSolution() {
2424
prepareAssemblies(activeSolutionDirectory)
2525
}
2626

27-
protected fun doTest(line : Int, column : Int, groups: List<String>?) {
27+
protected fun doTest(line : Int, column : Int, groups: List<String>?, fileName : String = "NewBehaviourScript.cs") {
2828
disableAllGroups()
2929
groups?.forEach { group -> setGroupingEnabled(group, true) }
30-
doTest(line, column)
30+
doTest(line, column, fileName)
3131
}
3232

3333
protected fun doTest(line : Int, column : Int, fileName : String = "NewBehaviourScript.cs") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Search target
2+
AnimationController.X:int
3+
Found usages (2 usages found)
4+
<Assembly-CSharp> (1 usage found)
5+
Assets (1 usage found)
6+
AnimationController.cs (1 usage found)
7+
AnimationController (1 usage found)
8+
Foo() (1 usage found)
9+
[289, Assets/AnimationController.cs] (14: 9) X = 0;
10+
Assets (1 usage found)
11+
Anime.controller (1 usage found)
12+
X = "777"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Search target
2+
TestScript1.Setup(int b):void
3+
Found usages (2 usages found)
4+
<Assembly-CSharp> (1 usage found)
5+
Assets (1 usage found)
6+
TestScript1.cs (1 usage found)
7+
TestScript1 (1 usage found)
8+
Setup(int) (1 usage found)
9+
[239, Assets/TestScript1.cs] (11: 9) Setup(b);
10+
Assets (1 usage found)
11+
Anime.controller (1 usage found)
12+
m_MethodName: Setup

rider/testData/solutions/AnimatorFindUsages/Assembly-CSharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
</ItemGroup>
4949
<ItemGroup>
5050
<Compile Include="Assets/Behaviour.cs"/>
51+
<Compile Include="Assets/AnimationController.cs"/>
52+
<Compile Include="Assets/TestScript1.cs"/>
5153
</ItemGroup>
5254
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
5355
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.Events;
5+
6+
public class AnimationController : StateMachineBehaviour
7+
{
8+
public int X;
9+
public UnityEvent eventZ;
10+
11+
public void Foo()
12+
{
13+
// should be more than 1 usage
14+
X = 0;
15+
}
16+
}

rider/testData/solutions/AnimatorFindUsages/Assets/AnimationController.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)