Skip to content

Commit

Permalink
Merge pull request #2267 from JetBrains/net221-vk-RIDER-71269
Browse files Browse the repository at this point in the history
Asset Finder issues
  • Loading branch information
krasnotsvetov authored Mar 5, 2022
2 parents cee2e2d + e00dd6e commit 46e2c5d
Show file tree
Hide file tree
Showing 63 changed files with 3,124 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public void OnClick(CodeInsightsHighlighting highlighting, ISolution solution)
if (!declaredElement.IsValid())
return;

// Document constant is required for non-empty IFinderSearchRoot
rules.AddRule("Document", DocumentModelDataConstants.DOCUMENT, highlighting.Range.Document);

rules.AddRule("DocumentEditorContext", DocumentModelDataConstants.EDITOR_CONTEXT, new DocumentEditorContext(highlighting.Range));
rules.AddRule("PopupWindowSourceOverride", UIDataConstants.PopupWindowContextSource,
new PopupWindowContextSource(lt => new RiderEditorOffsetPopupWindowContext(highlighting.Range.StartOffset.Offset)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ public override RdUsageGroup CreateModel(IOccurrence occurrence, IOccurrenceBrow
{
using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet())
{
if (occurrence is UnityAssetOccurrence assetOccurrence)
if (occurrence is UnityAssetOccurrence assetOccurrence &&
!assetOccurrence.SourceFile.IsAsset() &&
!assetOccurrence.SourceFile.IsAnim() &&
!assetOccurrence.SourceFile.IsController())
{
var hierarchyContainer = assetOccurrence.GetSolution()?.GetComponent<AssetDocumentHierarchyElementContainer>();
var element = hierarchyContainer?.GetHierarchyElement(assetOccurrence.OwningElementLocation, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpD
string tooltip, IReadOnlyCallGraphContext context)
{
consumer.AddImplicitConfigurableHighlighting(element);
if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
return;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpD
IReadOnlyCallGraphContext context)
{
consumer.AddImplicitConfigurableHighlighting(element);

if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
return;

consumer.AddHighlighting(new UnityGutterMarkInfo(element, tooltip));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using JetBrains.Application.Settings;
using JetBrains.ReSharper.Plugins.Unity.Core.Application.Settings;

namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Daemon.Stages.Highlightings.IconsProviders
{
public class IconProviderUtil
{
public static bool ShouldShowGutterMarkIcon(IContextBoundSettingsStoreLive settings)
{
return settings.GetValue((UnitySettings key) => key.GutterIconMode) != GutterIconMode.None;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ protected virtual void AddUnityECSHighlighting(IHighlightingConsumer consumer, I
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration declaration, string text, string tooltip, IReadOnlyCallGraphContext context)
{
consumer.AddImplicitConfigurableHighlighting(declaration);

if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
return;

consumer.AddHighlighting(new UnityGutterMarkInfo(GetActions(declaration), declaration, tooltip));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public virtual void AddEventFunctionHighlighting(IHighlightingConsumer consumer,
if (declaration is ICSharpDeclaration cSharpDeclaration)
{
consumer.AddImplicitConfigurableHighlighting(cSharpDeclaration);

if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
continue;

consumer.AddHotHighlighting(PerformanceContextProvider, cSharpDeclaration,
SettingsStore.BoundSettingsStore, text, tooltip, context, GetEventFunctionActions(cSharpDeclaration, context));
}
Expand All @@ -73,6 +77,9 @@ public virtual void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer
// gutter mark
var actions = GetActions(cSharpDeclaration, context);

if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
return;

consumer.AddHotHighlighting(PerformanceContextProvider, cSharpDeclaration,
SettingsStore.BoundSettingsStore, text, tooltip, context, actions, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ protected virtual void AddHighlighting(IHighlightingConsumer consumer, ICSharpDe
string tooltip, IReadOnlyCallGraphContext context)
{
consumer.AddImplicitConfigurableHighlighting(element);

if (!IconProviderUtil.ShouldShowGutterMarkIcon(SettingsStore.BoundSettingsStore))
return;

consumer.AddHotHighlighting(ContextProvider, element, SettingsStore.BoundSettingsStore, text, tooltip, context, GetActions(element));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Feature.Services.Occurrences;
using JetBrains.ReSharper.Plugins.Unity.Resources.Icons;
using JetBrains.ReSharper.Plugins.Unity.UnityEditorIntegration;
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.DeferredCaches.AssetHierarchy;
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.DeferredCaches.AssetHierarchy.References;
using JetBrains.ReSharper.Psi;
Expand Down Expand Up @@ -87,6 +88,9 @@ public virtual RichText GetDisplayText()

private string GetAttachedGameObjectName(AssetHierarchyProcessor processor)
{
if (SourceFile.IsController())
return "AnimatorStateMachine";

var consumer = new UnityScenePathGameObjectConsumer();
processor.ProcessSceneHierarchyFromComponentToRoot(OwningElementLocation, consumer, true, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using System;
using System.Linq;
using JetBrains.ReSharper.Plugins.Unity.Core.Feature.Caches;
using JetBrains.ReSharper.Plugins.Unity.Utils;
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.Caches;
Expand Down Expand Up @@ -29,6 +30,7 @@ public class UnityAssetReferenceSearcher : IDomainSpecificSearcher
private readonly UnityEventsElementContainer myUnityEventsElementContainer;
private readonly AssetInspectorValuesContainer myAssetInspectorValuesContainer;
private readonly IDeclaredElementsSet myElements;
private readonly ReferenceSearcherParameters myReferenceSearcherParameters;
private readonly AnimationEventUsagesContainer myAnimationEventUsagesContainer;

public UnityAssetReferenceSearcher(DeferredCacheController deferredCacheController,
Expand All @@ -48,6 +50,7 @@ public UnityAssetReferenceSearcher(DeferredCacheController deferredCacheControll
myAnimationEventUsagesContainer = animationEventUsagesContainer;
myAssetInspectorValuesContainer = assetInspectorValuesContainer;
myElements = elements;
myReferenceSearcherParameters = referenceSearcherParameters;
}

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

var set = (myReferenceSearcherParameters.OriginalElements ?? myElements.ToList()).ToHashSet();
foreach (var element in myElements)
{
if (element is IMethod || element is IProperty)
{
if (!set.Contains(element))
continue;

var animationEventUsages = myAnimationEventUsagesContainer.GetEventUsagesFor(sourceFile, element);
foreach (var usage in animationEventUsages)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.jetbrains.rider.plugins.unity.actions

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ex.ApplicationInfoEx
import com.intellij.openapi.project.Project
import com.jetbrains.rider.actions.RiderTechnicalSupportEntry
import com.jetbrains.rider.actions.RiderTechnicalSupportInfoProvider
import com.jetbrains.rider.plugins.unity.FrontendBackendHost

class UnityVersionRiderTechnicalSupportInfoProvider : RiderTechnicalSupportInfoProvider {

override fun getEntry(e: AnActionEvent, appInfo: ApplicationInfoEx): RiderTechnicalSupportEntry {
return RiderTechnicalSupportEntry("\$UNITY_VERSION", getUnityVersion(e.project))
}


fun getUnityVersion(project: Project?): String {
if (project == null)
return ""

if (project.isDisposed)
return ""

val unityHost = FrontendBackendHost.getInstance(project)

return unityHost.model.unityApplicationData.valueOrNull?.applicationVersion ?: ""
}
}
2 changes: 2 additions & 0 deletions rider/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
<projectService serviceImplementation="com.jetbrains.rider.plugins.unity.ui.vcs.UnityCheckinState"/>

<rider.runWidgetSuspenderExtension implementation="com.jetbrains.rider.plugins.unity.ui.UnityRunWidgetSuspenderExtension"/>

<rider.action.technical.support.info.provider implementation="com.jetbrains.rider.plugins.unity.actions.UnityVersionRiderTechnicalSupportInfoProvider" />
</extensions>

<project-components>
Expand Down
14 changes: 14 additions & 0 deletions rider/src/test/kotlin/AnimatorFindUsagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@ open class AnimatorFindUsagesTest : FindUsagesAssetTestBase() {
groups?.forEach { group -> setGroupingEnabled(group, true) }
doTest(5, 17, "Behaviour.cs")
}

@Test(dataProvider = "findUsagesGrouping")
fun animationFindUsagesForCommonBehaviorMethod(caseName: String, groups: List<String>?) {
disableAllGroups()
groups?.forEach { group -> setGroupingEnabled(group, true) }
doTest(8, 29, "TestScript1.cs")
}

@Test(dataProvider = "findUsagesGrouping")
fun animationFindUsagesForCommonBehaviorFieldValue(caseName: String, groups: List<String>?) {
disableAllGroups()
groups?.forEach { group -> setGroupingEnabled(group, true) }
doTest(8, 16, "AnimationController.cs")
}
}
13 changes: 13 additions & 0 deletions rider/src/test/kotlin/FindUsagesAssetTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,17 @@ open class FindUsagesAssetTest : FindUsagesAssetTestBase() {
fun findPropertyHandler2(caseName: String, groups: List<String>?) {
doTest(33, 16, groups)
}

// TODO: uncomment when local tests would fine
// @Test(dataProvider = "findUsagesGrouping")
// @TestEnvironment(solution = "FindUsagesOverriddenEventHandlers")
// fun findAssetUsagesForOverriddenEventHandler(caseName: String, groups: List<String>?) {
// doTest(7, 27, groups, "BaseScript.cs")
// }
//
// @Test(dataProvider = "findUsagesGrouping")
// @TestEnvironment(solution = "FindUsagesOverriddenEventHandlers")
// fun findAssetUsagesForOverriddenEventHandler2(caseName: String, groups: List<String>?) {
// doTest(7, 27, groups, "DerivedScript.cs")
// }
}
4 changes: 2 additions & 2 deletions rider/src/test/kotlin/base/FindUsagesAssetTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ abstract class FindUsagesAssetTestBase : BaseTestWithSolution() {
prepareAssemblies(activeSolutionDirectory)
}

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

protected fun doTest(line : Int, column : Int, fileName : String = "NewBehaviourScript.cs") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Search target
AnimationController.X:int
Found usages (2 usages found)
<Assembly-CSharp> (1 usage found)
Assets (1 usage found)
AnimationController.cs (1 usage found)
AnimationController (1 usage found)
Foo() (1 usage found)
[289, Assets/AnimationController.cs] (14: 9) X = 0;
Assets (1 usage found)
Anime.controller (1 usage found)
X = "777"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Search target
TestScript1.Setup(int b):void
Found usages (2 usages found)
<Assembly-CSharp> (1 usage found)
Assets (1 usage found)
TestScript1.cs (1 usage found)
TestScript1 (1 usage found)
Setup(int) (1 usage found)
[239, Assets/TestScript1.cs] (11: 9) Setup(b);
Assets (1 usage found)
Anime.controller (1 usage found)
m_MethodName: Setup
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets/Behaviour.cs"/>
<Compile Include="Assets/AnimationController.cs"/>
<Compile Include="Assets/TestScript1.cs"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class AnimationController : StateMachineBehaviour
{
public int X;
public UnityEvent eventZ;

public void Foo()
{
// should be more than 1 usage
X = 0;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 46e2c5d

Please # to comment.